From 3ffe1ed7742a8927caee818c49018f59c93b0615 Mon Sep 17 00:00:00 2001 From: YgorSouza <43298013+YgorSouza@users.noreply.github.com> Date: Tue, 31 Dec 2024 13:37:05 +0100 Subject: [PATCH] Re-enable IME support on Linux (#5198) Reverts #5188 and adds a different fix to restore IME on Linux without breaking the backspace and arrow keys. * Closes https://github.com/emilk/egui/issues/5544 * Closes https://github.com/emilk/egui/pull/5198 * [x] I have followed the instructions in the PR template --- crates/egui-winit/src/lib.rs | 72 ++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index ac396a01..f3612f50 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -333,43 +333,45 @@ impl State { } WindowEvent::Ime(ime) => { - if cfg!(target_os = "linux") { - // We ignore IME events on linux, because of https://github.com/emilk/egui/issues/5008 - } else { - // on Mac even Cmd-C is pressed during ime, a `c` is pushed to Preedit. - // So no need to check is_mac_cmd. - // - // How winit produce `Ime::Enabled` and `Ime::Disabled` differs in MacOS - // and Windows. - // - // - On Windows, before and after each Commit will produce an Enable/Disabled - // event. - // - On MacOS, only when user explicit enable/disable ime. No Disabled - // after Commit. - // - // We use input_method_editor_started to manually insert CompositionStart - // between Commits. - match ime { - winit::event::Ime::Enabled => { + // on Mac even Cmd-C is pressed during ime, a `c` is pushed to Preedit. + // So no need to check is_mac_cmd. + // + // How winit produce `Ime::Enabled` and `Ime::Disabled` differs in MacOS + // and Windows. + // + // - On Windows, before and after each Commit will produce an Enable/Disabled + // event. + // - On MacOS, only when user explicit enable/disable ime. No Disabled + // after Commit. + // + // We use input_method_editor_started to manually insert CompositionStart + // between Commits. + match ime { + winit::event::Ime::Enabled => { + if cfg!(target_os = "linux") { + // This event means different things in X11 and Wayland, but we can just + // ignore it and enable IME on the preedit event. + // See + } else { self.ime_event_enable(); } - winit::event::Ime::Preedit(text, Some(_cursor)) => { - self.ime_event_enable(); - self.egui_input - .events - .push(egui::Event::Ime(egui::ImeEvent::Preedit(text.clone()))); - } - winit::event::Ime::Commit(text) => { - self.egui_input - .events - .push(egui::Event::Ime(egui::ImeEvent::Commit(text.clone()))); - self.ime_event_disable(); - } - winit::event::Ime::Disabled | winit::event::Ime::Preedit(_, None) => { - self.ime_event_disable(); - } - }; - } + } + winit::event::Ime::Preedit(text, Some(_cursor)) => { + self.ime_event_enable(); + self.egui_input + .events + .push(egui::Event::Ime(egui::ImeEvent::Preedit(text.clone()))); + } + winit::event::Ime::Commit(text) => { + self.egui_input + .events + .push(egui::Event::Ime(egui::ImeEvent::Commit(text.clone()))); + self.ime_event_disable(); + } + winit::event::Ime::Disabled | winit::event::Ime::Preedit(_, None) => { + self.ime_event_disable(); + } + }; EventResponse { repaint: true,