A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.
Rust archive-managerdesktop-appdual-paneexplorer-alternativefile-browserfile-explorerfile-managerfluent-designgpu-acceleratedgpuimacosmicaproductivityquick-lookrustrust-guitabswindowswindows-11windows-explorer
fix(dock): recover lost reservation without fighting fullscreen Explorer
Atharv Tamboli4e0c970deceb
diff --git a/crates/rf-shellguard/src/tbctl.rs b/crates/rf-shellguard/src/tbctl.rsindex e8b89ba7..92eeea89 100644--- a/crates/rf-shellguard/src/tbctl.rs+++ b/crates/rf-shellguard/src/tbctl.rs@@ -75,6 +75,8 @@ pub trait HideWorld {fn wait_hidden(&mut self, targets: &[Target]) -> Vec<Target>;/// The monitors, with the work area each has NOW. `primary` marks the one the dock sits on.fn monitors(&mut self) -> Vec<MonitorGeom>;+ /// Explorer may park taskbars on other monitors while any display is in full screen.+ fn any_fullscreen(&mut self) -> bool { false }/// Sets the session's work area for the monitor that holds `rect` (never stored: no profile update).fn set_work_area(&mut self, rect: [i32; 4]) -> Result<(), String>;/// Holds the work area of a monitor whose edge is ours while Explorer's taskbar is hidden: from `from` (what it has now) to `to`.@@ -192,8 +194,8 @@ impl Controller {next_guard_try_ms: 0,guard_fault: None,guard_confirmed_ms: 0,- // Explorer may recompute the work area whenever it likes: give it back at most 4 times a minute.- throttle: Throttle::new(4, 60_000),+ // Explorer may recompute the work area whenever it likes: give it back at most once a minute.+ throttle: Throttle::new(1, 60_000),held: Vec::new(),throttle_said: false,band_owed: false,@@ -253,6 +255,7 @@ impl Controller {self.position = position;self.band_px = band_px;self.band_known = true;+ self.band_owed = true;self}@@ -370,7 +373,7 @@ impl Controller {}/// The work area was changed by someone (Explorer recomputes it when a toolbar changes): while the edge is ours it is set again,- /// a few times a minute at most.+ /// once a minute at most.pub fn work_area_changed(&mut self, w: &mut dyn HideWorld) {if self.want && !self.hidden.is_empty() {self.drive_edge(w);@@ -442,6 +445,13 @@ impl Controller {self.guard_failures = 0;}}+ // Do not re-hide or take work areas while Explorer is handling full screen on ANY monitor.+ if w.any_fullscreen() {+ if matches!(self.edge, Edge::Releasing { .. }) {+ self.edge = Edge::Releasing { since_ms: w.now_ms() };+ }+ return;+ }// 2. Is there an Explorer taskbar at all? (Nothing is started for a session where there is none.)if !w.explorer_owns_shell() {self.refusal = Some(Refusal::NoExplorerShell);@@ -601,6 +611,13 @@ impl Controller {return;}let now = w.now_ms();+ if w.any_fullscreen() {+ // Do not let the dock-release timeout run while we deliberately wait.+ if matches!(self.edge, Edge::Releasing { .. }) {+ self.edge = Edge::Releasing { since_ms: now };+ }+ return;+ }match self.edge {Edge::Free => {// the dock has not said what its band is: wait for its word (`set_band` drives the edge when it comes)@@ -729,6 +746,9 @@ impl Controller {}fn set_changes(&mut self, w: &mut dyn HideWorld, now: u64, plan: &tbwork::EdgePlan) {+ if w.any_fullscreen() {+ return;+ }let changes = plan.changes();if changes.is_empty() {self.band_owed = false;@@ -742,7 +762,10 @@ impl Controller {// Explorer may recompute the work area whenever it likes; answering every time could fight it for ever. (The dock's own change// of its band is not Explorer's doing: the thin dock changes it as windows are maximised and restored, never faster than// every two seconds, and the work area must be the one the dock stands under at every one of them.)- if !std::mem::take(&mut self.band_owed) && !self.throttle.allow(now) {+ let band_changed = std::mem::take(&mut self.band_owed);+ // A changing dock band is exempt only when Explorer has not also reset a previously held work area.+ let explorer_reset = changes.iter().any(|c| self.held.iter().any(|(id, rect)| *id == c.id && *rect != c.from));+ if !(band_changed && !explorer_reset) && !self.throttle.allow(now) {if !self.throttle_said {self.throttle_said = true;w.warn("taskbar: the work area was set too often lately; left alone");diff --git a/crates/rf-shellguard/src/tbedge_tests.rs b/crates/rf-shellguard/src/tbedge_tests.rsindex 3fad2e2e..800cff21 100644--- a/crates/rf-shellguard/src/tbedge_tests.rs+++ b/crates/rf-shellguard/src/tbedge_tests.rs@@ -355,8 +355,8 @@ fn explorer_taking_the_strip_back_is_answered_a_few_times_and_then_left_alone()w.now += 1_000;c.work_area_changed(&mut w);}- // the first batch used one slot of four; three more were allowed- assert_eq!(w.work_sets.len(), first + 3, "{:?}", w.work_sets);+ // Initial acquisition is free; only one unsolicited recovery is allowed per minute.+ assert_eq!(w.work_sets.len(), first + 1, "{:?}", w.work_sets);assert!(w.lines.iter().any(|l| l.contains("too often")));// and a minute later it is answered againw.now += 60_000;@@ -386,7 +386,7 @@ fn a_display_change_after_explorer_was_throttled_sets_the_work_area_again_at_oncw.now += 1_000;c.work_area_changed(&mut w);}- assert_eq!(w.work_sets.len(), before + 3, "{:?}", w.work_sets);+ assert_eq!(w.work_sets.len(), before, "{:?}", w.work_sets);}#[test]@@ -468,7 +468,7 @@ fn explorer_taking_the_work_area_back_is_still_throttled_after_the_docks_own_chaw.now += 1_000;c.work_area_changed(&mut w);}- assert_eq!(w.work_sets.len(), before + 3, "{:?}", w.work_sets);+ assert_eq!(w.work_sets.len(), before + 1, "{:?}", w.work_sets);assert!(w.lines.iter().any(|l| l.contains("too often")));}@@ -822,3 +822,61 @@ fn bands_for_other_monitors_wait_for_the_edge_and_cost_nothing_when_nothing_is_hassert_eq!(work_b(&w), [-1440, -200, 0, 2279]);assert_eq!(work_a(&w), [0, 0, 2560, 1362]);}++#[test]+fn fullscreen_on_any_monitor_leaves_parked_secondary_and_work_areas_alone_777() {+ let (mut c, mut w) = settled();+ c.set_other_bands(&mut w, vec![("B".into(), BAND)]);+ w.fullscreen_active = true;+ {+ let mut desktop = w.desktop.borrow_mut();+ let secondary = desktop.iter_mut().find(|bar| bar.class == SECONDARY).unwrap();+ secondary.rect = [-1440, 2357, 0, 2405];+ secondary.visible = true;+ }+ w.monitors[0].work = A;+ w.monitors[1].work = B;+ let before = w.work_sets.len();+ let hides = w.count("hide:");+ let dock = w.count("dock.");+ for _ in 0..70 {+ w.now += 1_000;+ c.tick(&mut w);+ c.work_area_changed(&mut w);+ }+ c.set_band(&mut w, Some(68));+ assert_eq!(w.work_sets.len(), before);+ assert_eq!(w.count("hide:"), hides);+ assert_eq!(w.count("dock."), dock);+ assert_eq!((work_a(&w), work_b(&w)), (A, B));+ // Once full screen ends, Explorer returns its taskbar to its normal position.+ w.fullscreen_active = false;+ w.desktop.borrow_mut().iter_mut().find(|bar| bar.class == SECONDARY).unwrap().rect = [-1440, 2311, 0, 2359];+ c.tick(&mut w);+ assert_eq!(work_a(&w), [0, 0, 2560, 1372]);+ assert_eq!(work_b(&w), [-1440, -200, 0, 2281]);+}++#[test]+fn single_monitor_parked_taskbar_recovers_lost_band_at_most_once_per_minute() {+ let (mut c, mut w) = world(true);+ w.monitors.truncate(1);+ w.desktop.borrow_mut().retain(|bar| bar.class == PRIMARY);+ on(&mut c, &mut w);+ w.desktop.borrow_mut()[0].rect = [0, 1438, 2560, 1486];+ w.monitors[0].work = A;+ w.now += 1_000;+ c.tick(&mut w);+ assert_eq!(work_a(&w), [0, 0, 2560, 1362]);+ let before = w.work_sets.len();+ for _ in 0..59 {+ w.now += 1_000;+ w.monitors[0].work = A;+ c.tick(&mut w);+ }+ assert_eq!(w.work_sets.len(), before);+ w.now += 1_000;+ c.tick(&mut w);+ assert_eq!(work_a(&w), [0, 0, 2560, 1362]);+ assert_eq!(w.work_sets.len(), before + 1);+}diff --git a/crates/rf-shellguard/src/tbfakes.rs b/crates/rf-shellguard/src/tbfakes.rsindex b3010201..8a9bda52 100644--- a/crates/rf-shellguard/src/tbfakes.rs+++ b/crates/rf-shellguard/src/tbfakes.rs@@ -47,6 +47,7 @@ pub struct FakeWorld {pub desktop: Desktop,pub now: u64,pub explorer_shell: bool,+ pub fullscreen_active: bool,pub list_fails: bool,pub hide_fails: Vec<isize>,pub show_fails: Vec<isize>,@@ -99,6 +100,7 @@ impl FakeWorld {desktop,now: 1_000_000,explorer_shell: true,+ fullscreen_active: false,list_fails: false,hide_fails: vec![],show_fails: vec![],@@ -154,6 +156,8 @@ impl FakeWorld {}impl HideWorld for FakeWorld {+ fn any_fullscreen(&mut self) -> bool { self.fullscreen_active }+fn now_ms(&mut self) -> u64 {self.now}diff --git a/crates/rf-shellguard/src/tbwork.rs b/crates/rf-shellguard/src/tbwork.rsindex e8d3e07a..b8af0569 100644--- a/crates/rf-shellguard/src/tbwork.rs+++ b/crates/rf-shellguard/src/tbwork.rs@@ -255,6 +255,21 @@ pub fn plan_edge_bands_on(monitors: &[MonitorGeom], bars: &[[i32; 4]], band: Optlet mut plan = MonitorPlan { id: m.id.clone(), primary: m.primary, rect: m.rect, work_now: m.work, target, user_work: m.rect, band_held: false, verdict: Verdict::NotOurs };if let Some(bar) = bar {plan.verdict = Verdict::Foreign;+ // On a single display a parked bottom taskbar can leave the entire work area exposed.+ // Never infer ownership from parked secondary taskbars (#777), or from an unknown reservation.+ let parked = monitors.len() == 1 && m.primary+ && near(bar[0], m.rect[0]) && near(bar[2], m.rect[2])+ && (1..=8).contains(&(m.rect[3] - bar[1]))+ && bar[3] > m.rect[3] + 1 && bar[3] - bar[1] < (m.rect[3] - m.rect[1]) / 2;+ if parked {+ if same(m.work, target) {+ plan.verdict = Verdict::AsWanted;+ } else if same(m.work, m.rect) || held.iter().any(|h| same(m.work, *h)) {+ plan.verdict = Verdict::Set;+ }+ out.push(plan);+ continue;+ }if let Some(side) = side_of(m.rect, *bar) {let strip_only = without_strip(m.rect, *bar);// The user's own work area is what the taskbar's strip leaves. With the whole monitor read (an auto-hiding taskbar thatdiff --git a/crates/rf-win/src/dock/fullscreen.rs b/crates/rf-win/src/dock/fullscreen.rsindex eaa11ed9..cc220725 100644--- a/crates/rf-win/src/dock/fullscreen.rs+++ b/crates/rf-win/src/dock/fullscreen.rs@@ -86,7 +86,7 @@ pub fn is_borderless_popup(style: u32) -> bool {}/// Reads window information for any given HWND. `None` when there is none or it cannot be measured.-fn window_info(h: windows::Win32::Foundation::HWND) -> Option<Foreground> {+pub(crate) fn window_info(h: windows::Win32::Foundation::HWND) -> Option<Foreground> {use windows::Win32::Foundation::RECT;use windows::Win32::System::Threading::GetCurrentProcessId;use windows::Win32::UI::WindowsAndMessaging::{GWL_STYLE, GetClassNameW, GetWindowLongPtrW, GetWindowRect, GetWindowThreadProcessId};diff --git a/crates/rf-win/src/taskbar_hide.rs b/crates/rf-win/src/taskbar_hide.rsindex f9cb6412..6de52fde 100644--- a/crates/rf-win/src/taskbar_hide.rs+++ b/crates/rf-win/src/taskbar_hide.rs@@ -204,6 +204,13 @@ impl HideWorld for RealWorld {crate::dock::system::give_back_edge();}+ fn any_fullscreen(&mut self) -> bool {+ self.monitors().into_iter().any(|m| {+ let [l, t, r, b] = m.rect;+ crate::dock::fullscreen::on_monitor(Rect::new(l, t, r, b))+ })+ }+fn monitors(&mut self) -> Vec<MonitorGeom> {let mut v: Vec<MonitorGeom> = Vec::new();// SAFETY: `v` outlives the call. The thread is per-monitor DPI aware (see `run_thread`), so rectangles are physical pixels.diff --git a/crates/rf-win/src/workfit.rs b/crates/rf-win/src/workfit.rsindex ec56e407..ca6c6e66 100644--- a/crates/rf-win/src/workfit.rs+++ b/crates/rf-win/src/workfit.rs@@ -58,7 +58,16 @@ unsafe extern "system" fn each(hwnd: HWND, lparam: LPARAM) -> BOOL {if pid == fit.own || GetWindowRect(hwnd, &mut r).is_err() {return true.into();}- if let Some([l, t, rr, b]) = rf_shellguard::tbmodel::refit_maximized([r.left, r.top, r.right, r.bottom], fit.monitor_rect, fit.from, fit.to) {+ let win = [r.left, r.top, r.right, r.bottom];+ let target = if win == fit.monitor_rect {+ // Some ordinary maximized apps open exactly at monitor size after the band is lost.+ // The native sizing frame distinguishes them from borderless full-screen apps.+ let ordinary = crate::dock::fullscreen::window_info(hwnd).is_some_and(|w| w.maximized_frame && !w.shell && !w.own);+ (ordinary && win != fit.to).then_some(fit.to)+ } else {+ rf_shellguard::tbmodel::refit_maximized(win, fit.monitor_rect, fit.from, fit.to)+ };+ if let Some([l, t, rr, b]) = target {let _ = SetWindowPos(HWND(hwnd.0 as *mut c_void), None, l, t, rr - l, b - t, SWP_ASYNCWINDOWPOS | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);}true.into()