]> git.mdlowis.com Git - proto/labwc.git/commitdiff
IME: don't forward key-release without correspinding key-press
authortokyo4j <hrak1529@gmail.com>
Tue, 17 Dec 2024 03:06:05 +0000 (12:06 +0900)
committerHiroaki Yamamoto <hrak1529@gmail.com>
Tue, 17 Dec 2024 07:38:09 +0000 (16:38 +0900)
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
src/input/ime.c

index 189f51f152176d51ac4d830bacc51e2c124c1931..7e7349343a418b0d35d02d39820e7184d61e577d 100644 (file)
@@ -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.
index d64ee195de3d8ba073d729101783c5e99de0b9b2..4a18ba20814082e4f11ea3bca0ec0aa1c87f864e 100644 (file)
@@ -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);