Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Wayland, app repaints every frame if IME output is set #4254

Closed
white-axe opened this issue Mar 28, 2024 · 1 comment · Fixed by #4269
Closed

On Wayland, app repaints every frame if IME output is set #4254

white-axe opened this issue Mar 28, 2024 · 1 comment · Fixed by #4269
Labels
bug Something is broken IME native-linux Problem specific to Linux

Comments

@white-axe
Copy link
Contributor

white-axe commented Mar 28, 2024

Describe the bug
On Linux with Wayland, when an egui app using eframe has ui.output(|o| o.ime) not equal to None, the app continuously repaints.

One example of when ui.output(|o| o.ime) is not None is when an egui::widgets::TextEdit is focused because it is set by the widget in order to allow IMEs to determine where the cursor is.

I haven't tested this on non-Linux machines, but WebAssembly apps in browsers on Linux don't seem to have this problem, nor do apps for Windows running in Wine on Linux. Linux with X11 doesn't have this problem either.

To Reproduce
Steps to reproduce the behavior:

  1. Clone egui and checkout to the 0.27.0 tag
  2. cargo run -p egui_demo_app
  3. Make sure "Backend" is selected in the top-left corner of the app so that the left pane is visible
  4. Set the rendering mode to "Reactive" in the left pane so that the app doesn't repaint unless it has to
  5. Focus the text edit in the widget gallery or any other text edit
  6. Observe that the "Mean CPU usage" in the left pane constantly updates, meaning the app is repainting every frame

Expected behavior
The app should not repaint every frame when the text edit is selected.

Desktop (please complete the following information):

  • OS: Arch Linux with GNOME 46
  • Version: Linux unknown 6.8.1-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Sat, 16 Mar 2024 17:15:23 +0000 x86_64 GNU/Linux
@white-axe white-axe added the bug Something is broken label Mar 28, 2024
@emilk emilk added native-linux Problem specific to Linux IME labels Mar 28, 2024
@white-axe
Copy link
Contributor Author

I don't see anything wrong with egui that would be causing this to happen. Rather, it's being caused by this call here to the function winit::window::Window::set_ime_cursor_area:

if let Some(ime) = ime {
let rect = ime.rect;
let pixels_per_point = pixels_per_point(&self.egui_ctx, window);
crate::profile_scope!("set_ime_cursor_area");
window.set_ime_cursor_area(
winit::dpi::PhysicalPosition {
x: pixels_per_point * rect.min.x,
y: pixels_per_point * rect.min.y,
},
winit::dpi::PhysicalSize {
width: pixels_per_point * rect.width(),
height: pixels_per_point * rect.height(),
},
);
}

The Wayland implementation of that function is somehow triggering egui apps to repaint every time it's called. I'll try to get this fixed in winit.

emilk added a commit that referenced this issue Mar 30, 2024
…put 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 <[email protected]>
emilk added a commit that referenced this issue Apr 2, 2024
…put 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 <[email protected]>
emilk added a commit that referenced this issue Apr 2, 2024
…put 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 <[email protected]>
hacknus pushed a commit to hacknus/egui that referenced this issue Oct 30, 2024
…put is not None (emilk#4269)

* Closes emilk#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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken IME native-linux Problem specific to Linux
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants