Skip to content

Commit

Permalink
IME: don't forward key-release without correspinding key-press
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tokyo4j committed Dec 21, 2024
1 parent fdadd85 commit 605a88e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/core/seat/input-method-relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/core/seat/input-method-relay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <vector>
#include <memory>
#include <set>

namespace wf
{
Expand All @@ -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<uint32_t> pressed_keys;

text_input *find_focusable_text_input();
void set_focus(wlr_surface*);

Expand Down

0 comments on commit 605a88e

Please sign in to comment.