Skip to content

Re-enable IME support on Linux#5198

Merged
emilk merged 2 commits intoemilk:masterfrom
YgorSouza:fix-linux-ime
Dec 31, 2024
Merged

Re-enable IME support on Linux#5198
emilk merged 2 commits intoemilk:masterfrom
YgorSouza:fix-linux-ime

Conversation

@YgorSouza
Copy link
Copy Markdown
Contributor

@YgorSouza YgorSouza commented Sep 30, 2024

Reverts #5188 and adds a different fix to restore IME on Linux without breaking the backspace and arrow keys.

It means different things on X11 and Wayland, and causes us to assume
IME is active when it isn't, causing the backspace and arrow keys to be
disabled.
@github-actions
Copy link
Copy Markdown

Preview available at https://egui-pr-preview.github.io/pr/5198-fix-linux-ime
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

@YgorSouza
Copy link
Copy Markdown
Contributor Author

@rustbasic @crumblingstatue can you test this?

I've tested with Fedora 40/Gnome 46 with both the regular (Wayland) session and the XOrg session, with the compose key, the Unicode input (Ctrl+Shift+U) and the Chinese (Intelligent Pinyin) input source. Everything seems to work, and the backspace and arrow keys work on both as well.

@crumblingstatue
Copy link
Copy Markdown
Contributor

I can't test IME, because fcitx (& pals) somehow break my X11 setup (don't ask me how), but I can confirm that backspace and arrow keys work.

@rustbasic
Copy link
Copy Markdown
Contributor

Dear emilk & Dear YgorSouza

My opinion is,

@YgorSouza
Copy link
Copy Markdown
Contributor Author

I'm not sure if it will work well on some Linux + Chinese

Is there anyone who can test this? I mean, it seems fine to me, but I'm not Chinese so I don't know.

image

#5182 looks like it would require a major release? It's adding fields to structs, so I guess that's a breaking change. But if we can get the IME to work correctly on all platforms, maybe it won't be needed? And egui-winit already has an allow_ime field, so we could block IME events at this level, if needed, without involving the TextEdit or any other widgets.

let allow_ime = ime.is_some();
if self.allow_ime != allow_ime {
self.allow_ime = allow_ime;
crate::profile_scope!("set_ime_allowed");
window.set_ime_allowed(allow_ime);
}

@rustbasic
Copy link
Copy Markdown
Contributor

allow_ime turns the entire IME function of the OS ON/OFF, so it is not the way we expect.

As you may have noticed,
some Linux and some Chinese input IMEs have a problem with IME::enable that persists from the program startup,
so it is always recognized as IME input state.
It seems necessary to directly control ON/OFF.

@YgorSouza
Copy link
Copy Markdown
Contributor Author

The change in this PR ignores the Enabled event on Linux, where on X11 it seems to just mean that the window supports IME (and sometimes it can't even be turned off). That should hopefully be enough to prevent egui from going into IME mode in applications where IME isn't used at all. It is only enabled in the Preedit event, which contains a string and a cursor range, so we're definitely using IME if we get that event, since winit can't just invent this data out of nowhere.

If this still causes problems, I think we need an issue explaining what those problems are and on which systems they occur, so we can think about a solution that doesn't break anything for anyone else.

@YgorSouza YgorSouza marked this pull request as ready for review October 1, 2024 08:47
Copy link
Copy Markdown
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM, but we need to test this properly:

  • X11 without IME
  • X11 with IME
  • Wayland without IME
  • Wayland with IME

Repository owner deleted a comment from rustbasic Oct 2, 2024
@iamazy
Copy link
Copy Markdown

iamazy commented Dec 30, 2024

Code LGTM, but we need to test this properly:

  • X11 without IME
  • X11 with IME
  • Wayland without IME
  • Wayland with IME

I tested with X11 without IME and X11 with IME, chinese input works well.

@tmvkrpxl0
Copy link
Copy Markdown

I tried it out on Wayland with fcitx5 running custom_font example. Korean input works well, although I had to add custom font that supports Korean font.

@emilk
Copy link
Copy Markdown
Owner

emilk commented Dec 31, 2024

Thanks for the help testing!

@emilk emilk added eframe Relates to epi and eframe egui-winit porblems related to winit native-linux Problem specific to Linux labels Dec 31, 2024
@emilk emilk merged commit 3ffe1ed into emilk:master Dec 31, 2024
mikedilger pushed a commit to mikedilger/egui that referenced this pull request Feb 17, 2025
Reverts emilk#5188 and adds a different fix to restore IME on Linux without
breaking the backspace and arrow keys.

* Closes emilk#5544
* Closes emilk#5198
* [x] I have followed the instructions in the PR template
zxq82lm added a commit to elodin-sys/elodin that referenced this pull request Feb 23, 2026
Workaround for emilk/egui#5008 — on Linux
(X11/XWayland via nix develop), IME activation via set_ime_allowed(true)
causes the display server to capture Backspace and arrow key events
through XIM, preventing them from reaching egui TextEdit widgets.

bevy_egui's process_ime_system calls set_ime_allowed(true) whenever a
TextEdit gains focus. egui-winit fixed this in emilk/egui#5188 and
emilk/egui#5198, but bevy_egui has its own input pipeline and still
triggers the problematic path. Setting enable_ime = false on the
EguiContextSettings prevents the call entirely.

Co-authored-by: Cursor <cursoragent@cursor.com>
zxq82lm added a commit to elodin-sys/elodin that referenced this pull request Feb 23, 2026
Workaround for emilk/egui#5008 — on Linux
(X11/XWayland via nix develop), IME activation via set_ime_allowed(true)
causes the display server to capture Backspace and arrow key events
through XIM, preventing them from reaching egui TextEdit widgets.

bevy_egui's process_ime_system calls set_ime_allowed(true) whenever a
TextEdit gains focus. egui-winit fixed this in emilk/egui#5188 and
emilk/egui#5198, but bevy_egui has its own input pipeline and still
triggers the problematic path. Setting enable_ime = false on the
EguiContextSettings prevents the call entirely.

Co-authored-by: Cursor <cursoragent@cursor.com>
zxq82lm added a commit to elodin-sys/elodin that referenced this pull request Feb 23, 2026
* Fix command palette backspace handling at top level

* Disable IME on Linux to fix Backspace/arrow keys in TextEdit

Workaround for emilk/egui#5008 — on Linux
(X11/XWayland via nix develop), IME activation via set_ime_allowed(true)
causes the display server to capture Backspace and arrow key events
through XIM, preventing them from reaching egui TextEdit widgets.

bevy_egui's process_ime_system calls set_ime_allowed(true) whenever a
TextEdit gains focus. egui-winit fixed this in emilk/egui#5188 and
emilk/egui#5198, but bevy_egui has its own input pipeline and still
triggers the problematic path. Setting enable_ime = false on the
EguiContextSettings prevents the call entirely.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

eframe Relates to epi and eframe egui-winit porblems related to winit native-linux Problem specific to Linux

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IME input does not working on Linux since v0.29.0

6 participants