From 683f67b7612e0a37adab346bf9bc3224a5eefbde Mon Sep 17 00:00:00 2001 From: tokyo4j Date: Tue, 17 Dec 2024 12:06:05 +0900 Subject: [PATCH] IME: don't forward key-release without correspinding key-press After commit e2189903 in wlroots, when ctrl-f is pressed in firefox with a IME client running, the following key-release event for "f" is not sent, thus "f" is repeated like "ffffffffff..." in the input box of firefox. This is because the key-release event for "f" is firstly forwarded to the IME client and then sent via the virtual keyboard created by the IME client while the key-press event is sent via physical keyboard, and with e2189903, key-release events without a corresponding key-press event on the same keyboard is not emitted to the compositor. So this commit fixes this problem by not forwarding the key-release event to the IME client unless the corresponding key-press event was also forwarded. --- include/input/ime.h | 1 + src/input/ime.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/input/ime.h b/include/input/ime.h index 189f51f1..7e734934 100644 --- a/include/input/ime.h +++ b/include/input/ime.h @@ -21,6 +21,7 @@ struct input_method_relay { struct wl_list text_inputs; /* struct text_input.link */ struct wlr_input_method_v2 *input_method; struct wlr_surface *focused_surface; + struct lab_set pressed_keys; /* * Text-input which is enabled by the client and communicating with * input-method. diff --git a/src/input/ime.c b/src/input/ime.c index d64ee195..4a18ba20 100644 --- a/src/input/ime.c +++ b/src/input/ime.c @@ -73,9 +73,25 @@ bool input_method_keyboard_grab_forward_key(struct keyboard *keyboard, struct wlr_keyboard_key_event *event) { + /* + * We should not forward key-release events without corresponding + * key-press events forwarded + */ + struct lab_set *pressed_keys = + &keyboard->base.seat->input_method_relay->pressed_keys; + if (event->state == WL_KEYBOARD_KEY_STATE_RELEASED + && !lab_set_contains(pressed_keys, event->keycode)) { + return false; + } + struct wlr_input_method_keyboard_grab_v2 *keyboard_grab = get_keyboard_grab(keyboard); if (keyboard_grab) { + if (event->state == WL_KEYBOARD_KEY_STATE_PRESSED) { + lab_set_add(pressed_keys, event->keycode); + } else { + lab_set_remove(pressed_keys, event->keycode); + } wlr_input_method_keyboard_grab_v2_set_keyboard(keyboard_grab, keyboard->wlr_keyboard); wlr_input_method_keyboard_grab_v2_send_key(keyboard_grab, @@ -329,6 +345,8 @@ handle_input_method_grab_keyboard(struct wl_listener *listener, void *data) keyboard_grab, active_keyboard); } + relay->pressed_keys = (struct lab_set){0}; + relay->keyboard_grab_destroy.notify = handle_keyboard_grab_destroy; wl_signal_add(&keyboard_grab->events.destroy, &relay->keyboard_grab_destroy);