From 2a2529bb9c304daca5e4f9f2603a76db5fb13a16 Mon Sep 17 00:00:00 2001 From: icedrocket <114203630+icedrocket@users.noreply.github.com> Date: Mon, 10 Jul 2023 17:56:24 +0900 Subject: [PATCH] eframe: sleep a bit only when minimized (#3139) --- crates/eframe/src/native/run.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index bd7ccd72..367daea7 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -914,12 +914,9 @@ mod glow_integration { integration.maybe_autosave(app.as_mut(), window); - if !self.is_focused { - // On Mac, a minimized Window uses up all CPU: https://github.com/emilk/egui/issues/325 - // We can't know if we are minimized: https://github.com/rust-windowing/winit/issues/208 - // But we know if we are focused (in foreground). When minimized, we are not focused. - // However, a user may want an egui with an animation in the background, - // so we still need to repaint quite fast. + if window.is_minimized() == Some(true) { + // On Mac, a minimized Window uses up all CPU: + // https://github.com/emilk/egui/issues/325 crate::profile_scope!("bg_sleep"); std::thread::sleep(std::time::Duration::from_millis(10)); } @@ -1335,12 +1332,9 @@ mod wgpu_integration { integration.maybe_autosave(app.as_mut(), window); - if !self.is_focused { - // On Mac, a minimized Window uses up all CPU: https://github.com/emilk/egui/issues/325 - // We can't know if we are minimized: https://github.com/rust-windowing/winit/issues/208 - // But we know if we are focused (in foreground). When minimized, we are not focused. - // However, a user may want an egui with an animation in the background, - // so we still need to repaint quite fast. + if window.is_minimized() == Some(true) { + // On Mac, a minimized Window uses up all CPU: + // https://github.com/emilk/egui/issues/325 crate::profile_scope!("bg_sleep"); std::thread::sleep(std::time::Duration::from_millis(10)); }