egui icon indicating copy to clipboard operation
egui copied to clipboard

Re-enable IME support on Linux

Open YgorSouza opened this issue 1 year ago • 7 comments

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

  • [x] I have followed the instructions in the PR template

YgorSouza avatar Sep 30 '24 15:09 YgorSouza

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.

github-actions[bot] avatar Sep 30 '24 15:09 github-actions[bot]

@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.

YgorSouza avatar Sep 30 '24 15:09 YgorSouza

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.

crumblingstatue avatar Sep 30 '24 16:09 crumblingstatue

Dear emilk & Dear YgorSouza

My opinion is,

  • #5188 It seems like it's impossible to input languages ​​other than English that require an IME on Linux.

  • #5182 For non-English users using Linux, I think #5182 is the right way, because we can control turning it on/off as needed. If there are any parts we don't like, we can just edit them.

  • #5198 #5198 It should work fine on Windows, as there are no changes. I'm not sure if it will work well on some Linux + Chinese.

rustbasic avatar Sep 30 '24 17:09 rustbasic

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

https://github.com/emilk/egui/pull/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.

https://github.com/emilk/egui/blob/ce744e6f7a22412cecf1cf2ea8678344bfb56489/crates/egui-winit/src/lib.rs#L844-L849

YgorSouza avatar Sep 30 '24 18:09 YgorSouza

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.

rustbasic avatar Oct 01 '24 06:10 rustbasic

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 avatar Oct 01 '24 07:10 YgorSouza

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.

iamazy avatar Dec 30 '24 15:12 iamazy

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.

tmvkrpxl0 avatar Dec 30 '24 17:12 tmvkrpxl0

Thanks for the help testing!

emilk avatar Dec 31 '24 12:12 emilk