Skip to content

Commit

Permalink
input method: check current_serial when switching focus
Browse files Browse the repository at this point in the history
  • Loading branch information
ammen99 authored and lilydjwg committed Jan 24, 2024
1 parent 5b7afe3 commit 6bd1179
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/core/seat/input-method-relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ wf::input_method_relay::input_method_relay()
auto evt_input_method = static_cast<wlr_input_method_v2*>(data);
assert(evt_input_method == input_method);

// When we switch focus, we send a done event to the IM.
// The IM may need time to process further events and may send additional commits after switching
// focus, which belong to the old text input.
//
// To prevent this, we simply ignore commits which do not acknowledge the newest done event from the
// compositor.
if (input_method->current_serial < last_done_serial.value_or(0))
{
LOGD("focus just changed, ignore input method commit");
return;
}

auto *text_input = find_focused_text_input();
if (text_input == nullptr)
{
Expand Down Expand Up @@ -164,6 +176,13 @@ void wf::input_method_relay::send_im_state(wlr_text_input_v3 *input)
wlr_input_method_v2_send_content_type(input_method,
input->current.content_type.hint,
input->current.content_type.purpose);
send_im_done();
}

void wf::input_method_relay::send_im_done()
{
last_done_serial = next_done_serial;
next_done_serial++;
wlr_input_method_v2_send_done(input_method);
}

Expand Down
5 changes: 5 additions & 0 deletions src/core/seat/input-method-relay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class input_method_relay
on_input_method_new, on_input_method_commit, on_input_method_destroy,
on_grab_keyboard, on_grab_keyboard_destroy, on_new_popup_surface;
wlr_input_method_keyboard_grab_v2 *keyboard_grab = nullptr;

std::optional<uint32_t> last_done_serial;
uint32_t next_done_serial = 0;
void send_im_done();

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

Expand Down

0 comments on commit 6bd1179

Please sign in to comment.