From c07394b5766053fcdb5cb506e369f60a535a4800 Mon Sep 17 00:00:00 2001 From: Barugon <16503728+Barugon@users.noreply.github.com> Date: Tue, 19 Sep 2023 05:14:42 -0700 Subject: [PATCH] Only show on-screen-keyboard and IME when editing text (#3362) * Remove calls to `set_ime_allowed` * Allow IME if `text_cursor_pos` is `Some` * Only call `Window::set_ime_allowed` when necessary * allow_ime doesn't need to be atomic * Remove unused imports * Fix assignment --- crates/eframe/src/native/run.rs | 3 --- crates/egui-winit/src/lib.rs | 10 ++++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index 6b276e96..db11e0f8 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -777,7 +777,6 @@ mod glow_integration { let theme = system_theme.unwrap_or(self.native_options.default_theme); integration.egui_ctx.set_visuals(theme.egui_visuals()); - gl_window.window().set_ime_allowed(true); if self.native_options.mouse_passthrough { gl_window.window().set_cursor_hittest(false).unwrap(); } @@ -1269,8 +1268,6 @@ mod wgpu_integration { let theme = system_theme.unwrap_or(self.native_options.default_theme); integration.egui_ctx.set_visuals(theme.egui_visuals()); - window.set_ime_allowed(true); - { let event_loop_proxy = self.repaint_proxy.clone(); integration diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index b304657b..079a2404 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -80,6 +80,8 @@ pub struct State { #[cfg(feature = "accesskit")] accesskit: Option, + + allow_ime: bool, } impl State { @@ -107,6 +109,8 @@ impl State { #[cfg(feature = "accesskit")] accesskit: None, + + allow_ime: false, } } @@ -663,6 +667,12 @@ impl State { self.clipboard.set(copied_text); } + let allow_ime = text_cursor_pos.is_some(); + if self.allow_ime != allow_ime { + self.allow_ime = allow_ime; + window.set_ime_allowed(allow_ime); + } + if let Some(egui::Pos2 { x, y }) = text_cursor_pos { window.set_ime_position(winit::dpi::LogicalPosition { x, y }); }