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 <Joscha.Wloch@bruker.com>
This commit is contained in:
Joscha.Wloch 2026-03-24 11:47:03 +01:00 committed by Joscha Wloch
parent e0bfeb4f8f
commit cfcfc15554

View file

@ -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);
}