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

Fix: The viewport stops working when the program is minimized. #4832

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,8 @@ fn run_and_return(event_loop: &mut EventLoop<UserEvent>, mut winit_app: impl Win

if let Some(window) = winit_app.window(*window_id) {
log::trace!("request_redraw for {window_id:?}");
let is_minimized = window.is_minimized().unwrap_or(false);
if is_minimized {
false
} else {
window.request_redraw();
true
}
window.request_redraw();
true
Comment on lines +192 to +193
Copy link
Owner

@emilk emilk Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reverts the changes you added in:

Won't this cause high CPU usage on Windows when minimized again?

Copy link
Contributor Author

@rustbasic rustbasic Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's ok as long as you don't keep calling request_repaint().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone want to keep calling request_repaint() but not call it when minimized, someone can do the following.
It works fine.

            let is_maximized = ui.input(|i| i.viewport().maximized.unwrap_or(false));
            if !is_minimized {
                ui.ctx().request_repaint();
            }

} else {
log::trace!("No window found for {window_id:?}");
false
Expand Down Expand Up @@ -347,13 +342,8 @@ fn run_and_exit(

if let Some(window) = winit_app.window(*window_id) {
log::trace!("request_redraw for {window_id:?}");
let is_minimized = window.is_minimized().unwrap_or(false);
if is_minimized {
false
} else {
window.request_redraw();
true
}
window.request_redraw();
true
} else {
log::trace!("No window found for {window_id:?}");
false
Expand Down
Loading