From cfcfc15554a544b16a6a15addd8d6890348158db Mon Sep 17 00:00:00 2001 From: "Joscha.Wloch" Date: Tue, 24 Mar 2026 11:47:03 +0100 Subject: [PATCH] clients: keyboard: fix key remains visually in pressed state If you pressed a key and then moved your finger to another position without lifting it, the key remained visually pressed even after you lifted your finger. Now the ID is stored for each touch event and as soon as a release event returns, the corresponding key is put back into the correct state. Signed-off-by: Joscha.Wloch --- clients/keyboard.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/clients/keyboard.c b/clients/keyboard.c index f1035c223..91a3e176a 100644 --- a/clients/keyboard.c +++ b/clients/keyboard.c @@ -276,6 +276,7 @@ struct keyboard { enum keyboard_state state; uint32_t key_state[max_count]; + int32_t key_touch_event_id[max_count]; uint32_t key_margin; uint32_t key_radius; @@ -805,7 +806,7 @@ button_handler(struct widget *widget, } static void -touch_handler(struct input *input, uint32_t time, +touch_handler(struct input *input, uint32_t time, int32_t id, float x, float y, uint32_t state, void *data) { struct keyboard *keyboard = data; @@ -826,6 +827,7 @@ touch_handler(struct input *input, uint32_t time, for (i = 0; i < layout->count; ++i) { col -= layout->keys[i].width; if (col < 0) { + keyboard->key_touch_event_id[i] = id; keyboard_handle_key(keyboard, time, &layout->keys[i], i, input, state); break; @@ -840,7 +842,7 @@ touch_down_handler(struct widget *widget, struct input *input, uint32_t serial, uint32_t time, int32_t id, float x, float y, void *data) { - touch_handler(input, time, x, y, + touch_handler(input, time, id, x, y, WL_POINTER_BUTTON_STATE_PRESSED, data); } @@ -849,11 +851,21 @@ touch_up_handler(struct widget *widget, struct input *input, uint32_t serial, uint32_t time, int32_t id, void *data) { - float x, y; + struct keyboard *keyboard = data; - input_get_touch(input, id, &x, &y); + for (size_t i = 0; i < max_count; ++i) + { + if (id == keyboard->key_touch_event_id[i]) + { + keyboard->key_touch_event_id[i] = -1; + keyboard->key_state[i] = WL_KEYBOARD_KEY_STATE_RELEASED; + } + } - touch_handler(input, time, x, y, + float x, y; + input_get_touch(input, id, &x, &y); + + touch_handler(input, time, id, x, y, WL_POINTER_BUTTON_STATE_RELEASED, data); }