Skip to content

Commit 3ffe1ed

Browse files
authored
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 #5544 * Closes #5198 * [x] I have followed the instructions in the PR template
1 parent e32ca21 commit 3ffe1ed

File tree

1 file changed

+37
-35
lines changed

1 file changed

+37
-35
lines changed

crates/egui-winit/src/lib.rs

+37-35
Original file line numberDiff line numberDiff line change
@@ -333,43 +333,45 @@ impl State {
333333
}
334334

335335
WindowEvent::Ime(ime) => {
336-
if cfg!(target_os = "linux") {
337-
// We ignore IME events on linux, because of https://github.com/emilk/egui/issues/5008
338-
} else {
339-
// on Mac even Cmd-C is pressed during ime, a `c` is pushed to Preedit.
340-
// So no need to check is_mac_cmd.
341-
//
342-
// How winit produce `Ime::Enabled` and `Ime::Disabled` differs in MacOS
343-
// and Windows.
344-
//
345-
// - On Windows, before and after each Commit will produce an Enable/Disabled
346-
// event.
347-
// - On MacOS, only when user explicit enable/disable ime. No Disabled
348-
// after Commit.
349-
//
350-
// We use input_method_editor_started to manually insert CompositionStart
351-
// between Commits.
352-
match ime {
353-
winit::event::Ime::Enabled => {
354-
self.ime_event_enable();
355-
}
356-
winit::event::Ime::Preedit(text, Some(_cursor)) => {
336+
// on Mac even Cmd-C is pressed during ime, a `c` is pushed to Preedit.
337+
// So no need to check is_mac_cmd.
338+
//
339+
// How winit produce `Ime::Enabled` and `Ime::Disabled` differs in MacOS
340+
// and Windows.
341+
//
342+
// - On Windows, before and after each Commit will produce an Enable/Disabled
343+
// event.
344+
// - On MacOS, only when user explicit enable/disable ime. No Disabled
345+
// after Commit.
346+
//
347+
// We use input_method_editor_started to manually insert CompositionStart
348+
// between Commits.
349+
match ime {
350+
winit::event::Ime::Enabled => {
351+
if cfg!(target_os = "linux") {
352+
// This event means different things in X11 and Wayland, but we can just
353+
// ignore it and enable IME on the preedit event.
354+
// See <https://github.com/rust-windowing/winit/issues/2498>
355+
} else {
357356
self.ime_event_enable();
358-
self.egui_input
359-
.events
360-
.push(egui::Event::Ime(egui::ImeEvent::Preedit(text.clone())));
361357
}
362-
winit::event::Ime::Commit(text) => {
363-
self.egui_input
364-
.events
365-
.push(egui::Event::Ime(egui::ImeEvent::Commit(text.clone())));
366-
self.ime_event_disable();
367-
}
368-
winit::event::Ime::Disabled | winit::event::Ime::Preedit(_, None) => {
369-
self.ime_event_disable();
370-
}
371-
};
372-
}
358+
}
359+
winit::event::Ime::Preedit(text, Some(_cursor)) => {
360+
self.ime_event_enable();
361+
self.egui_input
362+
.events
363+
.push(egui::Event::Ime(egui::ImeEvent::Preedit(text.clone())));
364+
}
365+
winit::event::Ime::Commit(text) => {
366+
self.egui_input
367+
.events
368+
.push(egui::Event::Ime(egui::ImeEvent::Commit(text.clone())));
369+
self.ime_event_disable();
370+
}
371+
winit::event::Ime::Disabled | winit::event::Ime::Preedit(_, None) => {
372+
self.ime_event_disable();
373+
}
374+
};
373375

374376
EventResponse {
375377
repaint: true,

0 commit comments

Comments
 (0)