Skip to content

Commit

Permalink
On X11, fix IME input lagging behind
Browse files Browse the repository at this point in the history
IME events and requests where drained on one-by-one basis, however
we should drain all of them at once and send to user.

Links: alacritty/alacritty#7514
  • Loading branch information
kchibisov committed Dec 31, 2023
1 parent 2998bbf commit 2bf12c7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 39 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Unreleased` header.

# Unreleased

# 0.29.8

- On X11, fix IME input lagging behind.
- On X11, fix `ModifiersChanged` not sent from xdotool-like input
- On X11, keymap not updated from xmodmap.
- On X11, reduce the amount of time spent fetching screen resources.
Expand Down
77 changes: 38 additions & 39 deletions src/platform_impl/linux/x11/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ impl<T: 'static> EventProcessor<T> {
}

// Handle IME requests.
if let Ok(request) = self.ime_receiver.try_recv() {
while let Ok(request) = self.ime_receiver.try_recv() {
let mut ime = wt.ime.borrow_mut();
match request {
ImeRequest::Position(window_id, x, y) => {
Expand All @@ -1323,47 +1323,46 @@ impl<T: 'static> EventProcessor<T> {
}
}

let (window, event) = match self.ime_event_receiver.try_recv() {
Ok((window, event)) => (window as xproto::Window, event),
Err(_) => return,
};

match event {
ImeEvent::Enabled => {
callback(Event::WindowEvent {
window_id: mkwid(window),
event: WindowEvent::Ime(Ime::Enabled),
});
}
ImeEvent::Start => {
self.is_composing = true;
callback(Event::WindowEvent {
window_id: mkwid(window),
event: WindowEvent::Ime(Ime::Preedit("".to_owned(), None)),
});
}
ImeEvent::Update(text, position) => {
if self.is_composing {
// Drain IME events.
while let Ok((window, event)) = self.ime_event_receiver.try_recv() {
let window_id = mkwid(window as xproto::Window);
match event {
ImeEvent::Enabled => {
callback(Event::WindowEvent {
window_id: mkwid(window),
event: WindowEvent::Ime(Ime::Preedit(text, Some((position, position)))),
window_id,
event: WindowEvent::Ime(Ime::Enabled),
});
}
ImeEvent::Start => {
self.is_composing = true;
callback(Event::WindowEvent {
window_id,
event: WindowEvent::Ime(Ime::Preedit("".to_owned(), None)),
});
}
ImeEvent::Update(text, position) => {
if self.is_composing {
callback(Event::WindowEvent {
window_id,
event: WindowEvent::Ime(Ime::Preedit(text, Some((position, position)))),
});
}
}
ImeEvent::End => {
self.is_composing = false;
// Issue empty preedit on `Done`.
callback(Event::WindowEvent {
window_id,
event: WindowEvent::Ime(Ime::Preedit(String::new(), None)),
});
}
ImeEvent::Disabled => {
self.is_composing = false;
callback(Event::WindowEvent {
window_id,
event: WindowEvent::Ime(Ime::Disabled),
});
}
}
ImeEvent::End => {
self.is_composing = false;
// Issue empty preedit on `Done`.
callback(Event::WindowEvent {
window_id: mkwid(window),
event: WindowEvent::Ime(Ime::Preedit(String::new(), None)),
});
}
ImeEvent::Disabled => {
self.is_composing = false;
callback(Event::WindowEvent {
window_id: mkwid(window),
event: WindowEvent::Ime(Ime::Disabled),
});
}
}
}
Expand Down

0 comments on commit 2bf12c7

Please sign in to comment.