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.
This commit is contained in:
Guido Cella 2024-02-10 20:34:48 +01:00 committed by Dudemanguy
parent a039cfce00
commit 86e0882733
1 changed files with 6 additions and 0 deletions

View File

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