From b2a4c0ce9172c30449b31f86fa9a1b94b97f8012 Mon Sep 17 00:00:00 2001 From: nanahi <130121847+na-na-hi@users.noreply.github.com> Date: Wed, 5 Jun 2024 10:13:22 -0400 Subject: [PATCH] wayland_common: properly handle modifiers for keyboard enter keys Wayland protocol only guarantees the delivery of modifier information after the enter event. To handle it properly for keys pressed in the enter event, save those keys for later processing in the modifier event. --- video/out/wayland_common.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index aa91a687be..56269b0859 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -211,6 +211,9 @@ struct vo_wayland_seat { bool axis_value120_scroll; bool has_keyboard_input; struct wl_list link; + bool keyboard_entering; + uint32_t *keyboard_entering_keys; + int num_keyboard_entering_keys; }; static bool single_output_spanned(struct vo_wayland_state *wl); @@ -558,11 +561,12 @@ static void keyboard_handle_enter(void *data, struct wl_keyboard *wl_keyboard, struct vo_wayland_seat *s = data; struct vo_wayland_state *wl = s->wl; s->has_keyboard_input = true; + s->keyboard_entering = true; guess_focus(wl); uint32_t *key; wl_array_for_each(key, keys) - handle_key_input(s, *key, WL_KEYBOARD_KEY_STATE_PRESSED); + MP_TARRAY_APPEND(s, s->keyboard_entering_keys, s->num_keyboard_entering_keys, *key); } static void keyboard_handle_leave(void *data, struct wl_keyboard *wl_keyboard, @@ -598,8 +602,15 @@ static void keyboard_handle_modifiers(void *data, struct wl_keyboard *wl_keyboar xkb_state_update_mask(s->xkb_state, mods_depressed, mods_latched, mods_locked, 0, 0, group); s->mpmod = get_mods(s); - if (s->mpkey) - mp_input_put_key(wl->vo->input_ctx, s->mpkey | MP_KEY_STATE_DOWN | s->mpmod); + } + // Handle keys pressed during the enter event. + if (s->keyboard_entering) { + s->keyboard_entering = false; + for (int n = 0; n < s->num_keyboard_entering_keys; n++) + handle_key_input(s, s->keyboard_entering_keys[n], WL_KEYBOARD_KEY_STATE_PRESSED); + s->num_keyboard_entering_keys = 0; + } else if (s->xkb_state && s->mpkey) { + mp_input_put_key(wl->vo->input_ctx, s->mpkey | MP_KEY_STATE_DOWN | s->mpmod); } }