Skip to content

Commit 33221bd

Browse files
white-axeemilk
andauthored
Fix continuous repaint on Wayland when TextEdit is focused or IME output is not None (#4269)
* Closes #4254 Changes egui-winit so that it calls `window.set_ime_cursor_area` when the IME rect changes or the user interacts with the application instead of calling it every time the app is rendered. This works around a winit bug that causes the app to continuously repaint under certain circumstances on Wayland. Tested on Wayland and on X11 using the text edit in the egui_demo_app - no changes in IME functionality as far as I can tell. Untested on non-Linux platforms. --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
1 parent 3b147c0 commit 33221bd

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

crates/egui-winit/src/lib.rs

+21-12
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub struct State {
9999
accesskit: Option<accesskit_winit::Adapter>,
100100

101101
allow_ime: bool,
102+
ime_rect_px: Option<egui::Rect>,
102103
}
103104

104105
impl State {
@@ -139,6 +140,7 @@ impl State {
139140
accesskit: None,
140141

141142
allow_ime: false,
143+
ime_rect_px: None,
142144
};
143145

144146
slf.egui_input
@@ -817,19 +819,26 @@ impl State {
817819
}
818820

819821
if let Some(ime) = ime {
820-
let rect = ime.rect;
821822
let pixels_per_point = pixels_per_point(&self.egui_ctx, window);
822-
crate::profile_scope!("set_ime_cursor_area");
823-
window.set_ime_cursor_area(
824-
winit::dpi::PhysicalPosition {
825-
x: pixels_per_point * rect.min.x,
826-
y: pixels_per_point * rect.min.y,
827-
},
828-
winit::dpi::PhysicalSize {
829-
width: pixels_per_point * rect.width(),
830-
height: pixels_per_point * rect.height(),
831-
},
832-
);
823+
let ime_rect_px = pixels_per_point * ime.rect;
824+
if self.ime_rect_px != Some(ime_rect_px)
825+
|| self.egui_ctx.input(|i| !i.events.is_empty())
826+
{
827+
self.ime_rect_px = Some(ime_rect_px);
828+
crate::profile_scope!("set_ime_cursor_area");
829+
window.set_ime_cursor_area(
830+
winit::dpi::PhysicalPosition {
831+
x: ime_rect_px.min.x,
832+
y: ime_rect_px.min.y,
833+
},
834+
winit::dpi::PhysicalSize {
835+
width: ime_rect_px.width(),
836+
height: ime_rect_px.height(),
837+
},
838+
);
839+
}
840+
} else {
841+
self.ime_rect_px = None;
833842
}
834843

835844
#[cfg(feature = "accesskit")]

0 commit comments

Comments
 (0)