Conversation
|
Preview available at https://egui-pr-preview.github.io/pr/7967-fix-undesired-keyboard-input-events-during-ime-composition View snapshot changes at kitdiff |
|
Related |
winit::event::KeyboardInput fiddling with IME composition on Windowswinit::event::KeyboardInput fiddling with IME composition on Windows properly
|
Hello. @choyunjin (Issue #7809) |
|
Tested on Windows 11 with Google Japanese IME, it's working very well, like other applications that supports IME. Nice work! Speaking of implementation, as the behavior which winit sends keyboard events that is consumed by IME is confirmed as a bug, it would be nice to have a comment that says the implementation is workaround and will be fixed by winit. |
winit::event::KeyboardInput fiddling with IME composition on Windows properlywinit::event::KeyboardInput fiddling with IME composition on Windows properly
winit::event::KeyboardInput fiddling with IME composition on Windows properlywinit::event::KeyboardInput fiddling with IME composition on Windows properly
lucasmerlin
left a comment
There was a problem hiding this comment.
Looks good to me! Thanks for the thorough testing as well!
|
I noticed that @rustbasic reacted with an 👀 to the comment where I pinged people, so they may still be reviewing this PR. I think we should wait for their feedback before considering merging it. |
|
Great job, @umajho. On a side note, I believe #7914 should still be pursued for separate reasons. While not directly related to this (#7914 and #7967), there are still some unresolved issues regarding IME handling. |
|
@rustbasic thanks for the feedback! Could you elaborate more on the Cheonjiin issue Specifically:
Regarding #4137The I have tested #7983 on Windows and confirmed that the partial fix for the focus-related bug still works there. (And on macOS, the behavior remains incorrect as before.) I guess the ultimate solution may involve explicitly disabling and re-enabling the IME when a |
|
Regarding the I'm also planning to introduce this in a follow-up PR that implements visuals for “real IME cursors & cursor ranges.” My intention is to work on it after this PR and #7983 are resolved. By “real IME cursors & cursor ranges,” I mean something like the following: Since this discussion is already outside the scope of this PR, I suggest we continue it in #7983 and merge this PR first. (Since I've gathered feedback from both a Japanese IME user and a Korean IME user that this PR works, and I'm confident it also works for Chinese IMEs (at least for those Pinyin-like), I believe this PR is ready to be merged.) |
Regarding the Cheonjiin Korean Keyboard issue: Example sequence: Regarding #7983: Regarding disabling and re-enabling IME on focus: |
|
@umajho Update from further testing: |
|
Note I moved the original content of this comment to #7983 (comment) I think we should continue our discussion in #7983, since we are now talking about what comes after this PR, which is what I originally planned for #7983. |
|
Finally, a smooth typing experience in egui on Windows! Thank you for the extensive testing across different environments. You've solved a long-standing pain point for us : ) |
winit::event::KeyboardInput fiddling with IME composition on Windows properly|
Thank you! |


TextEditinput is removed when typing is completed with Japanese IME #7809TextEditto fix some bugs #4794This approach is better than #7898 (#7914) because it correctly handles all three major IME types (Chinese, Japanese, and Korean) without requiring a predefined “IME mode”.
Environments I haved tested this PR in
macOS 15.7.3 (AArch64, Host of other virtual machines)
Run command:
cargo run -p egui_demo_app --releaseTested IMEs:
Windows 11 25H2 (AArch64, Virtual Machine)
Build command:
cargo build --release -p egui_demo_app --target=x86_64-pc-windows-gnu --features=glow --no-default-features(I cannot use
wgpudue to this bug, which prevents debugging inside the VM. Anyways, the rendering backend should be irrelevant here.)Tested IMEs:
Linux [Wayland + IBus] (AArch64, Virtual Machine)
Fedora KDE Plasma Desktop 43 [Wayland + IBus 1.5.33-rc2]
(Not working at the moment because of another issue that will be fixed by #7983. It is a complicated story. )
Build command:
cross build --release -p egui_demo_app --target=aarch64-unknown-linux-gnu --features=wayland,wgpu --no-default-features(The Linux toolchain on my mac is somehow broken, so I used
crossinstead.)Tested IMEs:
Linux [X11 + Fcitx5] (AArch64, Virtual Machine)
Debian 13 [Cinnamon 6.4.10 + X11 + Fcitx5 5.1.2]
Build command:
cross build --release -p egui_demo_app --target=aarch64-unknown-linux-gnu --features=x11,wgpu --no-default-featuresTested IMEs:
luna-pinyinUnlike macOS and Linux + Wayland, key-release events for keys processed by the IME are still forwarded to
egui. These appear to be harmless in practice.Unlike on Windows, however, they cannot be filtered reliably because there are no corresponding key-press events marked as “processed by IME”.
There are too many possible combinations to test (Operating Systems × Desktop Environments × Windowing Systems × IMFs × IMEs × …), and I only have access to a limited subset. For example, Google Japanese Input refused to install on my Windows VM, and some paid Japanese IMEs are not accessible to me. Therefore, I would appreciate feedback from people other than me using all kinds of environments.
Details
There are two possible approaches to removing keyboard events that have already been processed by an IME:
eguithat appear to have been received during IME composition.egui-winitcrate or the code underweb/in theeframecrate.).Both approaches already exist in
egui:TextEditto fix some bugs #4794 uses the first approach, filtering these events in theTextEdit-related code.eframeuses the second approach in its web integration. See:egui/crates/eframe/src/web/events.rs
Lines 173 to 176 in 14afefa
Compared to the first approach, the second has a clear advantage: when events are passed from the platform backends into
egui, they are simplified and lose information. In contrast, events in the platform backends are the original events, which allows them to be handled more flexibly. This is also why #7898 (#7914), which attempts to address the issue from within theeguicrate, struggles to make all IMEs work correctly at the same time and requires manually selecting an “IME mode”: the events received byeguihave already been reduced and therefore lack necessary information.A more appropriate solution is to consistently follow the second approach, explicitly requiring platform backends not to forward events that have already been processed by the IME to
egui. This is the method used in this PR. Specifically, this PR works within theegui-winitcrate, where the originalKeyboardInputevents can be accessed. At least for key press events, these can be used directly to determine whether the event has already been processed by the IME on Windows (by checking whetherlogical_keyequalswinit::keyboard::NamedKey::Process). This makes it straightforward to ensure that all IMEs work correctly at the same time.This PR also reverts #4794, which took the first approach. It filters out some events that merely look like they were received during IME composition but actually are not. It also messes up the order of those events along the way.
As a result, it caused several IME-related issues. One of the sections in the Demonstrations below will illustrate these problems.
Demonstrations
Changes not included in this PR for displaying Unicode characters in demonstrations
Download
unifont-17.0.03.otffrom https://unifoundry.com/pub/unifont/unifont-17.0.03/font-builds/, and place it atcrates/egui_demo_app/src/unifont-17.0.03.otf.In
crates/egui_demo_app/src/wrap_app.rs, add these lines at the beginning ofimpl WrapApp'spub fn new:(I took this from somewhere, but I forgot where it is. Sorry…)
GNU Unifont is licensed under OFL-1.1.
This PR Fixes: Focus on a single-line
TextEditis lost after completing candidate selection with Japanese IME on Windows (#7809)Screencast: ✅ Japanese IME now behaves correctly while Korean IME behaves as before
This PR Fixes: Committing Japanese IME text with Enter inserts an unintended newline in multiline
TextEditon Windows (#7876)Screencast: ✅ Japanese IME now behaves correctly while Korean IME behaves as before
This PR Fixes: Backspacing deletes characters during composition in certain Chinese IMEs (e.g., Sogou) on Windows (#7908)
Screencast: ✅ Sogou IME now behaves correctly
This PR Obsoletes #4794, because
eguireceives only IME events during composition from now onOn Windows, “incompatible” events are filtered in
egui-winit, aligning the behavior with other systems.Screencasts
Some Chinese IMEs on Windows:

The default Japanese IMEs on Windows:

The 2-set Korean IMEs handle arrow keys differently. It will be discussed in the next section.
This PR Reverts #4794, because it introduced several bugs
Some of its bugs have already been worked around in the past, but those workarounds might also be problematic. For example, #4912 is a workaround for a bug (#4908) introduced by #4794, and that workaround is in fact the root cause of the macOS backspacing bug I have worked around with #7810. (The reversion of #4912 is out of the scope of this PR, I will do that in #7983.)
It Caused: Arrow keys are incorrectly blocked during typical Korean IME composition
When composing Korean text using 2-Set IMEs, users should still be able to move the cursor with arrow keys regardless if the composition is committed.
Correct behavior
Screencasts
macOS TextEdit:

Windows Notepad:

With #4794 reverted,

eguialso behaves correctly (tested on Linux + Wayland, macOS, and Windows):Incorrect behavior caused by #4794
remove_ime_incompatible_eventsremoved arrow-key events in such cases. As a result, the first arrow key press only commits the composition, and users need to press the arrow key again to move the cursor:Screencast
This is essentially the same issue described here: #7877 (comment)
It Caused: Backspacing leaves the last character in Korean IME pre-edit text not removed on macOS
Screencasts
Before this PR:

After this PR:

Korean IMEs also use Enter to confirm Hanja selections, and will not work properly in the Korean “IME mode” proposed by #7898 (#7914)
Screencast: Korean IME using Enter and Space for confirmation (IBus Korean Hangul IME)
The screencast below demonstrates that some Korean IMEs handle Hanja selection in a way similar to Japanese IMEs: the Up/Down arrow keys are used to navigate candidates, and Enter confirms the selected candidate.
Screencasts: Another example
Using the built-in Korean IME on Windows, I type two lines: the first line in Hangul, and the second line as the same word converted to Hanja.
Correct behavior in Notepad (reference):

Behavior after applying this PR, which matches the Notepad behavior:

Behavior after applying #7914 with the “IME mode” set to Korean (which is also the behavior before this PR being applied):

On the second line, each time a Hanja character is confirmed, an unintended newline is inserted. This mirrors the Japanese IME issues that are supposed to be fixed by setting the “IME mode” to Japanese.
(These Japanese IME issues are fixed in this PR as mentioned before.)