From 605a88e79067f39d9bd3aeadb64f86561e01d49e Mon Sep 17 00:00:00 2001 From: tokyo4j Date: Sun, 22 Dec 2024 02:00:44 +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 preceding 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. --- src/core/seat/input-method-relay.cpp | 13 +++++++++++++ src/core/seat/input-method-relay.hpp | 3 +++ 2 files changed, 16 insertions(+) diff --git a/src/core/seat/input-method-relay.cpp b/src/core/seat/input-method-relay.cpp index b523c1e8d..c5ad160dc 100644 --- a/src/core/seat/input-method-relay.cpp +++ b/src/core/seat/input-method-relay.cpp @@ -284,6 +284,19 @@ bool wf::input_method_relay::handle_key(struct wlr_keyboard *kbd, uint32_t time, return false; } + if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { + pressed_keys.insert(key); + } else + { + // Don't forward the release event if the press event for the same key + // has also been forwarded. + if (!pressed_keys.count(key)) + { + return false; + } + pressed_keys.erase(key); + } + wlr_input_method_keyboard_grab_v2_set_keyboard(keyboard_grab, kbd); wlr_input_method_keyboard_grab_v2_send_key(keyboard_grab, time, key, state); return true; diff --git a/src/core/seat/input-method-relay.hpp b/src/core/seat/input-method-relay.hpp index 7a5b81a19..f5212db1f 100644 --- a/src/core/seat/input-method-relay.hpp +++ b/src/core/seat/input-method-relay.hpp @@ -7,6 +7,7 @@ #include #include +#include namespace wf { @@ -25,6 +26,8 @@ class input_method_relay : public text_input_v3_im_relay_interface_t uint32_t next_done_serial = 0; void send_im_done(); + std::multiset pressed_keys; + text_input *find_focusable_text_input(); void set_focus(wlr_surface*);