From 553596fc3e8ba68425edf9a80cd9bf7d73e90d0a Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Tue, 8 Oct 2024 16:38:46 +0300 Subject: [PATCH] x11: don't forward key events to IME when it's disabled Fixes #3815. --- src/changelog/unreleased.md | 1 + src/platform_impl/linux/x11/event_processor.rs | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 440c93691f..e3a77be78a 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -187,3 +187,4 @@ changelog entry. - On macOS, fix `WindowEvent::Moved` sometimes being triggered unnecessarily on resize. - On MacOS, package manifest definitions of `LSUIElement` will no longer be overridden with the default activation policy, unless explicitly provided during initialization. +- On X11, key events forward to IME anyway, even when it's disabled. diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index 0f9e8d78ca..3bbefc1615 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -141,9 +141,15 @@ impl EventProcessor { F: FnMut(&ActiveEventLoop, Event), { let event_type = xev.get_type(); - - if self.filter_event(xev) { - if event_type == xlib::KeyPress || event_type == xlib::KeyRelease { + let key_event = event_type == xlib::KeyPress || event_type == xlib::KeyRelease; + let has_ime = self.target.ime.is_some(); + + // If we have IME disabled, don't try to `filter_event`, since only IME can consume them + // and forward back. This is not desired for e.g. games since some IMEs may delay the input + // and game can toggle IME back when e.g. typing into some text-box where latency won't + // really matter. + if (key_event && has_ime || !key_event) && self.filter_event(xev) { + if key_event { let xev: &XKeyEvent = xev.as_ref(); if self.xmodmap.is_modifier(xev.keycode as u8) { // Don't grow the buffer past the `MAX_MOD_REPLAY_LEN`. This could happen