summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido Cella <guido@guidocella.xyz>2024-02-10 20:34:48 +0100
committerDudemanguy <random342@airmail.cc>2024-02-11 04:01:14 +0000
commit86e088273323499a9a3fc6b49149ee585f13e217 (patch)
treef90efdc761ff9cbc04ae891df9e54a05c0e65075
parenta039cfce00fb070ce006ee18f0587c4795958378 (diff)
downloadmpv-86e088273323499a9a3fc6b49149ee585f13e217.tar.bz2
mpv-86e088273323499a9a3fc6b49149ee585f13e217.tar.xz
wayland: don't press keys again when releasing modifiers
Since 1f8013ff3f, if you release a modifier before a regular key on Wayland, that key gets immediately pressed again because keyboard_handle_modifiers() calls mp_input_put_key() regardless of whether a modifier is pressed or released, e.g. if you press Ctrl+s it easy to take an another screenshot with s by accident. Fix this by releasing keys when releasing modifiers. Ideally, releasing the modifier should input the key alone after --input-ar-delay, while this patch disables it forever, e.g. on X11 if you type something in the console, hold Ctrl+h, and release Ctrl, it starts typing h instead of deleting characters. This doesn't work because keyboard_handle_key() is only called when you first press a key, while on X11 KeyPress keeps getting sent as you hold down the key. But this difference in behavior between X11 and Wayland can also be reproduced with GTK and Qt applications, so I guess this is acceptable.
-rw-r--r--video/out/wayland_common.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c
index a337136d00..1c8fd66fca 100644
--- a/video/out/wayland_common.c
+++ b/video/out/wayland_common.c
@@ -536,6 +536,12 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard,
mp_input_put_key_utf8(wl->vo->input_ctx, state | wl->mpmod, bstr0(s));
} else {
// Assume a modifier was pressed and handle it in the mod event instead.
+ // If a modifier is released before a regular key, also release that
+ // key to not activate it again by accident.
+ if (state == MP_KEY_STATE_UP) {
+ wl->mpkey = 0;
+ mp_input_put_key(wl->vo->input_ctx, MP_INPUT_RELEASE_ALL);
+ }
return;
}
}