diff --git a/apps/lightcraft/src/prefs.rs b/apps/lightcraft/src/prefs.rs index 7187128133..8c3a1859b8 100644 --- a/apps/lightcraft/src/prefs.rs +++ b/apps/lightcraft/src/prefs.rs @@ -243,6 +243,9 @@ impl PrefsWriter { for command in start.step(&seen, at, zoom) { ctx.send_viewport_cmd(command); } + } else { + // (hidden: nothing to place by, but the time limit still runs) + start.idle(at); } match start.waits() { Some(wait) => ctx.request_repaint_after(wait), diff --git a/crates/ui-egui/src/window_place.rs b/crates/ui-egui/src/window_place.rs index b8846d7a16..20e6d1f80e 100644 --- a/crates/ui-egui/src/window_place.rs +++ b/crates/ui-egui/src/window_place.rs @@ -402,9 +402,7 @@ impl StartPlace { return Vec::new(); } // (not shown yet, its screen unknown, full screen or minimized: wait, but not for ever) - let first = *self.first_step.get_or_insert(now); - if now - first > PLACE_WITHIN_SECONDS { - self.done = true; + if self.out_of_time(now) { return Vec::new(); } if seen.full_screen || seen.minimized { @@ -458,6 +456,23 @@ impl StartPlace { } } + /// A pass with nothing to place by (the window is hidden: its size is stale) at time `now`: the time limit + /// still runs, so a window kept hidden ends the placement and stops asking to be looked at. + pub fn idle(&mut self, now: f64) { + if !self.done { + self.out_of_time(now); + } + } + + /// Whether placing has gone on for longer than it may (it is then done); its clock starts at the first pass. + fn out_of_time(&mut self, now: f64) -> bool { + let first = *self.first_step.get_or_insert(now); + if now - first > PLACE_WITHIN_SECONDS { + self.done = true; + } + self.done + } + /// When to look again while it waits (the app may have nothing else to draw). pub fn waits(&self) -> Option { (!self.done).then(|| std::time::Duration::from_millis(100)) diff --git a/crates/ui-egui/src/window_place/tests.rs b/crates/ui-egui/src/window_place/tests.rs index 8012652684..2ada192d28 100644 --- a/crates/ui-egui/src/window_place/tests.rs +++ b/crates/ui-egui/src/window_place/tests.rs @@ -689,3 +689,16 @@ fn a_window_clamped_to_its_screen_before_it_shows_is_still_fitted() { let mut s = StartPlace::new(false); assert!(s.step(&clamped, 0.0, 1.0).is_empty()); } + +/// A window kept hidden while it is being placed still ends the placement in time, and then stops asking to be +/// looked at (CodeRabbit on #2974). +#[test] +fn placement_ends_in_time_while_the_window_is_hidden() { + let mut s = StartPlace::new(true); + s.idle(0.0); + assert!(!s.done() && s.waits().is_some(), "still within its time"); + s.idle(PLACE_WITHIN_SECONDS + 0.1); + assert!(s.done()); + assert_eq!(s.waits(), None); + assert!(s.step(&window([1300.0, 800.0]), PLACE_WITHIN_SECONDS + 0.2, 1.0).is_empty()); +}