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
Add the foundation for right-edge dock positioning
Atharv Tambolif2189951b91a
diff --git a/crates/rf-shellguard/src/tbctl.rs b/crates/rf-shellguard/src/tbctl.rsindex ecb8dc14..e8b89ba7 100644--- a/crates/rf-shellguard/src/tbctl.rs+++ b/crates/rf-shellguard/src/tbctl.rs@@ -158,6 +158,7 @@ pub struct Controller {band_owed: bool,/// The dock's band thickness in device px (`None`: the dock reserves none, `dock_reserve` is off). Session only.band_px: Option<i32>,+ position: tbwork::DockEdge,/// The bands of the docks on the other monitors (monitor id, thickness in device px), as the host last said. Empty: none (the/// switch for a dock on every monitor is off, or one monitor, or `dock_reserve` is off): those monitors are given whole.other_bands: Vec<(String, i32)>,@@ -197,6 +198,7 @@ impl Controller {throttle_said: false,band_owed: false,band_px: None,+ position: tbwork::DockEdge::Bottom,other_bands: Vec::new(),band_known: false,edge: Edge::Free,@@ -243,7 +245,12 @@ impl Controller {/// The band the dock wants kept free at the bottom of the primary monitor, when it is known at the start (before any window is/// hidden); later changes come through [`Controller::set_band`].- pub fn with_band(mut self, band_px: Option<i32>) -> Controller {+ pub fn with_band(self, band_px: Option<i32>) -> Controller {+ self.with_band_on(band_px, tbwork::DockEdge::Bottom)+ }++ pub fn with_band_on(mut self, band_px: Option<i32>, position: tbwork::DockEdge) -> Controller {+ self.position = position;self.band_px = band_px;self.band_known = true;self@@ -321,9 +328,14 @@ impl Controller {/// The dock's band changed (its size, or `dock_reserve`): while the edge is ours the work area follows.pub fn set_band(&mut self, w: &mut dyn HideWorld, band_px: Option<i32>) {- if band_px == self.band_px && self.band_known {+ self.set_band_on(w, band_px, tbwork::DockEdge::Bottom);+ }++ pub fn set_band_on(&mut self, w: &mut dyn HideWorld, band_px: Option<i32>, position: tbwork::DockEdge) {+ if band_px == self.band_px && position == self.position && self.band_known {return;}+ self.position = position;self.band_px = band_px;self.band_known = true;self.band_owed = true;@@ -599,7 +611,7 @@ impl Controller {let plan = self.plan(&mons);if !self.foreign_said && plan.monitors.iter().any(|m| m.verdict == Verdict::Foreign) {self.foreign_said = true;- w.warn("taskbar: another toolbar reserves room on a monitor (or the taskbar is not at the bottom); its work area is left alone and the taskbar's strip stays there");+ w.warn("taskbar: another toolbar reserves room on a monitor (or the taskbar edge is ambiguous); its work area is left alone and the taskbar's strip stays there");}if !plan.any_ours() {return;@@ -612,7 +624,7 @@ impl Controller {}// 2. The dock lets go of its own band and places itself from the monitor's bottom edge.if plan.primary_ours()- && let Some(edge) = plan.dock_edge(self.band_px)+ && let Some(edge) = plan.dock_edge_on(self.band_px, self.position){w.dock_take_edge(edge);self.dock_edge = Some(edge);@@ -654,7 +666,7 @@ impl Controller {/// Does the primary monitor's work area show that Explorer holds no band of the dock's any more?fn explorer_dropped_band(&mut self, w: &mut dyn HideWorld) -> bool {- let plan = tbwork::plan_edge(&w.monitors(), &self.bars, self.band_px);+ let plan = tbwork::plan_edge_bands_on(&w.monitors(), &self.bars, self.band_px, &[], &[], self.position);!plan.primary().is_some_and(|m| m.band_held)}@@ -669,7 +681,7 @@ impl Controller {let mons = w.monitors();let plan = self.plan(&mons);if plan.primary_ours()- && let Some(edge) = plan.dock_edge(self.band_px)+ && let Some(edge) = plan.dock_edge_on(self.band_px, self.position)&& self.dock_edge != Some(edge){w.dock_take_edge(edge);@@ -688,7 +700,7 @@ impl Controller {/// What the rules want on these monitors, from the bars we hid, the band of the dock on the primary one, the bands of the docks on/// the others and the rectangles this controller set itself.fn plan(&self, mons: &[MonitorGeom]) -> tbwork::EdgePlan {- tbwork::plan_edge_bands(mons, &self.bars, self.band_px, &self.held_rects(), &self.other_bands)+ tbwork::plan_edge_bands_on(mons, &self.bars, self.band_px, &self.held_rects(), &self.other_bands, self.position)}/// Writes the user's own work area of every monitor that is or is about to be ours into the state file (with `pending_restore`),diff --git a/crates/rf-shellguard/src/tbedge_tests.rs b/crates/rf-shellguard/src/tbedge_tests.rsindex 080f4804..3fad2e2e 100644--- a/crates/rf-shellguard/src/tbedge_tests.rs+++ b/crates/rf-shellguard/src/tbedge_tests.rs@@ -720,17 +720,26 @@ fn nothing_is_taken_until_the_dock_has_said_what_its_band_is() {}#[test]-fn a_taskbar_on_the_left_is_hidden_but_the_edge_and_the_work_areas_are_left_alone() {- let mut c = Controller::new(HOST_PID, HOST_START).with_band(Some(BAND));- let mut w = FakeWorld::new(Rc::new(RefCell::new(vec![window(0x1001, PRIMARY, [0, 0, 48, 1440])])));- w.monitors = vec![MonitorGeom { id: "A".into(), rect: A, work: [48, 0, 2560, 1440 - BAND], primary: true }];- w.dock_band = Some(BAND);- w.dock_wants_band = Some(BAND);- on(&mut c, &mut w);- assert_eq!(c.status(), Status::Hidden(1));- assert_eq!((w.count("dock."), w.count("work:"), c.edge(), w.dock_edge), (0, 0, Edge::Free, None), "{:?}", w.calls);- assert_eq!(w.dock_band, Some(BAND), "the dock keeps its own registration");- assert!(w.state.original_work_areas().is_empty());+fn a_side_taskbar_releases_its_strip_and_restores_it_after_quit() {+ for (bar, strip) in [+ ([0, 0, 48, 1440], [48, 0, 2560, 1440]),+ ([2512, 0, 2560, 1440], [0, 0, 2512, 1440]),+ ] {+ let mut c = Controller::new(HOST_PID, HOST_START).with_band(Some(BAND));+ let mut w = FakeWorld::new(Rc::new(RefCell::new(vec![window(0x1001, PRIMARY, bar)])));+ let registered = crate::tbwork::monitor_less_band(strip, BAND);+ w.monitors = vec![MonitorGeom { id: "A".into(), rect: A, work: registered, primary: true }];+ w.dock_band = Some(BAND);+ w.dock_wants_band = Some(BAND);+ on(&mut c, &mut w);+ assert_eq!(c.status(), Status::Hidden(1));+ assert_eq!(c.edge(), Edge::Ours);+ assert_eq!(work_a(&w), [0, 0, 2560, 1440 - BAND]);+ assert_eq!(w.state.original_work_areas()[0].rect, strip);+ c.set_wanted(&mut w, false);+ assert_eq!(work_a(&w), registered);+ assert!(w.state.original_work_areas().is_empty());+ }}#[test]diff --git a/crates/rf-shellguard/src/tbfakes.rs b/crates/rf-shellguard/src/tbfakes.rsindex dbbb5837..b3010201 100644--- a/crates/rf-shellguard/src/tbfakes.rs+++ b/crates/rf-shellguard/src/tbfakes.rs@@ -141,9 +141,10 @@ impl FakeWorld {/// Explorer computes the primary monitor's work area from its toolbars: the taskbar's strip if it is shown OR hidden (a hidden/// taskbar keeps its strip), less the dock's band when one is registered.pub fn explorer_recomputes(&mut self, band: Option<i32>) {- let bar_top = self.desktop.borrow().iter().find(|w| w.class == PRIMARY).map(|w| w.rect[1]);- if let (Some(top), Some(m)) = (bar_top, self.monitors.iter_mut().find(|m| m.primary)) {- m.work = [m.rect[0], m.rect[1], m.rect[2], top - band.unwrap_or(0)];+ let bar = self.desktop.borrow().iter().find(|w| w.class == PRIMARY).map(|w| w.rect);+ if let (Some(bar), Some(m)) = (bar, self.monitors.iter_mut().find(|m| m.primary)) {+ let strip = crate::tbwork::without_strip(m.rect, bar);+ m.work = band.map_or(strip, |t| crate::tbwork::monitor_less_band(strip, t));}}diff --git a/crates/rf-shellguard/src/tbwork.rs b/crates/rf-shellguard/src/tbwork.rsindex e5783171..e8d3e07a 100644--- a/crates/rf-shellguard/src/tbwork.rs+++ b/crates/rf-shellguard/src/tbwork.rs@@ -13,12 +13,10 @@//! This is the same rule the work-area keeper for a session with NO Explorer uses (`rf_win::shellhost::workarea::target` calls//! [`monitor_less_band`]); the two owners stay separate, only the arithmetic is shared.//!-//! WHAT IS TOUCHED, and what is not. Only the monitor of a taskbar that we hid, only a taskbar on the BOTTOM edge (Windows 11 has no-//! other; a bar at the top or a side, older Windows or a tweak, is left alone), and only where the geometry is unambiguous: the work-//! area is the monitor less that taskbar's strip (what a hidden taskbar still reserves), or the whole monitor (Explorer did not-//! reserve it), or - on the primary monitor, while the dock's own band is still registered with Explorer - the monitor less the strip-//! less a band at the bottom. Anything else means another toolbar reserves room there (a third-party bar, a sidebar): that monitor is-//! left alone ([`Verdict::Foreign`]) and the strip stays, as before this increment.+//! Only monitors with a taskbar we hid are touched, and only when its strip can be identified on one of the four edges.+//! The work area must be the monitor less that strip, the whole monitor, or the strip plus the primary dock's own bottom band.+//! For a non-bottom taskbar the band's thickness must agree with the dock's request; otherwise the extra reservation is ambiguous.+//! Other toolbar reservations are left alone ([`Verdict::Foreign`]).//!//! The pure parts here are the target ([`target_for`]), the judgement of what is there ([`plan_edge`]), the rectangles to write down//! before the first change ([`EdgePlan::originals`]) and what to put back on the way out ([`work_restore`]: the written-down@@ -28,11 +26,27 @@use crate::statefile::WorkAreaRec;use crate::tbmodel::{MonitorGeom, WorkChange};-/// The monitor less a band of `thickness` px at its bottom edge. At least one pixel of band and at least one pixel left, so the-/// result is never empty or inverted.-pub fn monitor_less_band(monitor: [i32; 4], thickness: i32) -> [i32; 4] {+/// The edge occupied by the dock, independently of the hidden Explorer taskbar.+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]+pub enum DockEdge {+ #[default]+ Bottom,+ Right,+}++/// A monitor minus the dock's reservation. Leave at least one pixel of usable space.+pub fn monitor_less_band_on(monitor: [i32; 4], thickness: i32, edge: DockEdge) -> [i32; 4] {let [left, top, right, bottom] = monitor;- [left, top, right, (bottom - thickness.max(1)).max(top + 1)]+ let thickness = thickness.max(1);+ match edge {+ DockEdge::Bottom => [left, top, right, (bottom - thickness).max(top + 1)],+ DockEdge::Right => [left, top, (right - thickness).max(left + 1), bottom],+ }+}++/// The monitor less a band at its bottom edge.+pub fn monitor_less_band(monitor: [i32; 4], thickness: i32) -> [i32; 4] {+ monitor_less_band_on(monitor, thickness, DockEdge::Bottom)}/// Which edge of its monitor a taskbar sits on.@@ -90,9 +104,16 @@ pub fn side_of(monitor: [i32; 4], bar: [i32; 4]) -> Option<Side> {}}-/// The monitor less the strip of a bar on its bottom edge: what the work area is with only that taskbar reserving room.+/// The work area with only an identified edge taskbar reserving room.pub fn without_strip(monitor: [i32; 4], bar: [i32; 4]) -> [i32; 4] {- [monitor[0], monitor[1], monitor[2], bar[1]]+ let [l, t, r, b] = monitor;+ match side_of(monitor, bar) {+ Some(Side::Left) => [bar[2], t, r, b],+ Some(Side::Top) => [l, bar[3], r, b],+ Some(Side::Right) => [l, t, bar[0], b],+ Some(Side::Bottom) => [l, t, r, bar[1]],+ None => monitor,+ }}/// The work area WE want on a monitor: the primary one keeps a band at the bottom when the dock reserves one (`band`: its thickness@@ -107,7 +128,12 @@ pub fn target_for(monitor: [i32; 4], primary: bool, band: Option<i32>) -> [i32;/// [`target_for`] for a host with a dock on the other monitors too: a monitor that is not the primary one keeps the band of the dock on/// it (`other`, in device px) when it has one, and is given whole when it has none.pub fn target_for_monitor(monitor: [i32; 4], primary: bool, band: Option<i32>, other: Option<i32>) -> [i32; 4] {- if primary { target_for(monitor, true, band) } else { other.map_or(monitor, |t| monitor_less_band(monitor, t)) }+ target_for_monitor_on(monitor, primary, band, other, DockEdge::Bottom)+}++pub fn target_for_monitor_on(monitor: [i32; 4], primary: bool, band: Option<i32>, other: Option<i32>, edge: DockEdge) -> [i32; 4] {+ let thickness = if primary { band } else { other };+ thickness.map_or(monitor, |t| monitor_less_band_on(monitor, t, edge))}/// A work area that is `strip_only` with a band cut from its bottom edge: the other three edges agree and the bottom is above the@@ -183,13 +209,18 @@ impl EdgePlan {/// The bottom strip of the primary monitor that is the dock's own band (an empty strip at the very bottom when `dock_reserve` is/// off): what the dock's placement is told, `[left, bottom - thickness, right, bottom]`.pub fn dock_edge(&self, band: Option<i32>) -> Option<[i32; 4]> {+ self.dock_edge_on(band, DockEdge::Bottom)+ }++ /// The physical strip at the selected dock edge (empty if reservation is off).+ pub fn dock_edge_on(&self, band: Option<i32>, edge: DockEdge) -> Option<[i32; 4]> {let m = self.primary()?;- let [l, _, r, b] = m.rect;- let top = match band {- Some(t) => monitor_less_band(m.rect, t)[3],- None => b,- };- Some([l, top, r, b])+ let [l, t, r, b] = m.rect;+ let target = band.map_or(m.rect, |thickness| monitor_less_band_on(m.rect, thickness, edge));+ Some(match edge {+ DockEdge::Bottom => [l, target[3], r, b],+ DockEdge::Right => [target[2], t, r, b],+ })}}@@ -211,24 +242,33 @@ pub fn plan_edge_held(monitors: &[MonitorGeom], bars: &[[i32; 4]], band: Option</// one (monitor id, thickness in device px). A monitor with a band there is given the monitor less that band, a monitor without one the/// whole monitor, as before. The primary monitor is judged exactly as it was.pub fn plan_edge_bands(monitors: &[MonitorGeom], bars: &[[i32; 4]], band: Option<i32>, held: &[[i32; 4]], other_bands: &[(String, i32)]) -> EdgePlan {+ plan_edge_bands_on(monitors, bars, band, held, other_bands, DockEdge::Bottom)+}++/// Resolve the taskbar's old strip and the dock's new reservation independently.+pub fn plan_edge_bands_on(monitors: &[MonitorGeom], bars: &[[i32; 4]], band: Option<i32>, held: &[[i32; 4]], other_bands: &[(String, i32)], dock_edge: DockEdge) -> EdgePlan {let mut out = Vec::with_capacity(monitors.len());for (i, m) in monitors.iter().enumerate() {let bar = bars.iter().find(|b| owner_of(monitors, b) == Some(i));let other = other_bands.iter().find(|(id, _)| *id == m.id).map(|(_, t)| *t);- let target = target_for_monitor(m.rect, m.primary, band, other);+ let target = target_for_monitor_on(m.rect, m.primary, band, other, dock_edge);let 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;- // Only a taskbar on the bottom edge is ours to take the strip of: the dock sits at the bottom, and a bar elsewhere is left- // as it is (the dock keeps its own registration and the strip stays).- if side_of(m.rect, *bar) == Some(Side::Bottom) {+ 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 that// happens to be up reserves nothing) the monitor is what the user has and is what is written down: the strip is not// guessed into it.plan.user_work = if same(m.work, m.rect) { m.rect } else { strip_only };// (a work area that already is the target is ours, whatever it looks like)- plan.band_held = m.primary && !same(m.work, target) && band_cut(m.work, strip_only);+ let own_band = if side == Side::Bottom && dock_edge == DockEdge::Bottom {+ band_cut(m.work, strip_only)+ } else {+ // A reservation on a different edge must match the known dock band exactly.+ band.is_some_and(|t| same(m.work, monitor_less_band_on(strip_only, t, dock_edge)))+ };+ plan.band_held = m.primary && !same(m.work, target) && own_band;if same(m.work, target) {plan.verdict = Verdict::AsWanted;} else if same(m.work, strip_only) || same(m.work, m.rect) || plan.band_held || held.iter().any(|h| same(m.work, *h)) {@@ -280,7 +320,7 @@ pub fn work_restore(originals: &[WorkAreaRec], monitors: &[MonitorGeom], bars: &out.dropped += 1;continue;};- let fresh = bars.iter().find(|b| owner_of(monitors, b) == Some(i) && side_of(m.rect, **b) == Some(Side::Bottom)).map(|b| without_strip(m.rect, *b));+ let fresh = bars.iter().find(|b| owner_of(monitors, b) == Some(i) && side_of(m.rect, **b).is_some()).map(|b| without_strip(m.rect, *b));match fresh {Some(f) if same(o.rect, f) || same(o.rect, m.rect) => out.put.push(o.rect),Some(f) => {@@ -319,6 +359,36 @@ mod tests {assert_eq!(monitor_less_band([-1440, -200, 0, 2359], 78), [-1440, -200, 0, 2281], "a negative origin works the same");}+ #[test]+ fn right_dock_band_is_independent_of_the_native_taskbar_edge() {+ let rect = [-1920, 100, 0, 1180];+ let right = [-72, 100, 0, 1180];+ let expected = [-1920, 100, -72, 1180];+ assert_eq!(monitor_less_band_on(rect, 72, DockEdge::Right), expected);+ assert_eq!(monitor_less_band_on(rect, 5000, DockEdge::Right), [-1920, 100, -1919, 1180]);+ for bar in [+ [-1920, 1132, 0, 1180],+ [-1920, 100, -1872, 1180],+ [-48, 100, 0, 1180],+ [-1920, 100, 0, 148],+ ] {+ let strip = without_strip(rect, bar);+ let registered = monitor_less_band_on(strip, 72, DockEdge::Right);+ let p = plan_edge_bands_on(+ &[mon("A", rect, registered, true)],+ &[bar],+ Some(72),+ &[],+ &[],+ DockEdge::Right,+ );+ assert_eq!(p.changes()[0].to, expected);+ assert_eq!(p.originals()[0].from, strip);+ assert_eq!(p.dock_edge_on(Some(72), DockEdge::Right), Some(right));+ assert_eq!(p.dock_edge_on(None, DockEdge::Right), Some([0, 100, 0, 1180]));+ }+ }+#[test]fn the_target_keeps_a_band_on_the_primary_monitor_only_and_only_when_the_dock_reserves() {// dock_reserve on: the monitor less the dock's band@@ -477,25 +547,50 @@ mod tests {}#[test]- fn a_taskbar_at_the_top_or_a_side_is_left_alone() {- // portrait monitor to the left of the primary, taskbar on top: the dock sits at the bottom, there is nothing to take- let m = mon("B", [-1440, -200, 0, 2359], [-1440, -152, 0, 2359], false);- let p = plan_edge(&[m], &[[-1440, -200, 0, -152]], None);- assert_eq!(verdicts(&p), vec![Verdict::Foreign]);- assert!(p.changes().is_empty() && p.originals().is_empty() && !p.any_ours());- // taskbar on the left of the primary monitor- let m = mon("C", [0, 0, 1920, 1080], [48, 0, 1920, 1080], true);- let p = plan_edge(&[m], &[[0, 0, 48, 1080]], Some(78));- assert_eq!(verdicts(&p), vec![Verdict::Foreign]);- assert!(!p.primary_ours() && p.changes().is_empty(), "the dock keeps its own registration");- // taskbar on the right- let m = mon("D", [0, 0, 1920, 1080], [0, 0, 1872, 1080], true);- assert_eq!(verdicts(&plan_edge(&[m], &[[1872, 0, 1920, 1080]], None)), vec![Verdict::Foreign]);- // taskbar on top of the primary monitor with the dock's band registered at the bottom- let m = mon("E", [0, 0, 1920, 1080], [0, 48, 1920, 1002], true);- let p = plan_edge(&[m], &[[0, 0, 1920, 48]], Some(78));- assert_eq!(verdicts(&p), vec![Verdict::Foreign]);- assert!(!p.primary_ours());+ fn a_taskbar_on_any_edge_releases_its_strip_and_restores_it_on_exit() {+ let rect = [0, 0, 1920, 1080];+ for (bar, strip) in [+ ([0, 0, 48, 1080], [48, 0, 1920, 1080]),+ ([1872, 0, 1920, 1080], [0, 0, 1872, 1080]),+ ([0, 0, 1920, 48], [0, 48, 1920, 1080]),+ ([0, 1032, 1920, 1080], [0, 0, 1920, 1032]),+ ] {+ let registered = monitor_less_band(strip, 78);+ let m = mon("A", rect, registered, true);+ let p = plan_edge(&[m], &[bar], Some(78));+ assert_eq!(verdicts(&p), vec![Verdict::Set], "{bar:?}");+ assert!(p.monitors[0].band_held && p.primary_ours());+ assert_eq!(p.originals()[0].from, strip);+ assert_eq!(p.changes()[0].to, [0, 0, 1920, 1002]);+ let p = plan_edge(&[mon("A", rect, strip, true)], &[bar], None);+ assert!(!p.monitors[0].band_held);+ assert_eq!(p.changes()[0].to, rect);+ let restored = work_restore(&[rec("A", strip)], &[mon("A", rect, rect, true)], &[bar]);+ assert_eq!(restored.put, vec![strip]);+ }+ }++ #[test]+ fn a_side_taskbar_does_not_erase_an_unrelated_reservation() {+ let rect = [0, 0, 1920, 1080];+ let bar = [1872, 0, 1920, 1080];+ for work in [[0, 30, 1872, 1080], [0, 0, 1872, 900], [20, 0, 1872, 1002]] {+ let p = plan_edge(&[mon("A", rect, work, true)], &[bar], Some(78));+ assert_eq!(verdicts(&p), vec![Verdict::Foreign]);+ assert!(p.changes().is_empty());+ }+ }++ #[test]+ fn a_moved_side_taskbar_is_restored_using_its_current_edge() {+ let rect = [0, 0, 1920, 1080];+ let restored = work_restore(+ &[rec("A", [0, 0, 1872, 1080])],+ &[mon("A", rect, rect, true)],+ &[[0, 0, 48, 1080]],+ );+ assert_eq!(restored.put, vec![[48, 0, 1920, 1080]]);+ assert_eq!(restored.refreshed, 1);}#[test]diff --git a/crates/rf-win/src/dock/band.rs b/crates/rf-win/src/dock/band.rsindex c86bdb33..dd6fbb19 100644--- a/crates/rf-win/src/dock/band.rs+++ b/crates/rf-win/src/dock/band.rs@@ -18,7 +18,7 @@//!//! Everything here is pure; the real calls are in `system.rs` behind [`AppBarCalls`], and the tests use a fake that models Explorer.-use super::layout::Rect;+use super::layout::{DockEdge, Rect, edge_axes};/// How many times in a row `ABM_SETPOS` is sent again for a band that was granted unchanged but is not in the work area.pub const MAX_REASSERT: u8 = 3;@@ -82,6 +82,7 @@ pub fn in_effect(band: Rect, work: Rect) -> bool {#[derive(Debug, Default)]pub struct Band {registered: bool,+ edge: DockEdge,granted: Option<Rect>,reasserts: u8,/// An announcement arrived and no registration has gone through since. The announcement does not say WHO sent it: Explorer@@ -117,6 +118,20 @@ impl Band {/// Brings the band in line with `want` (its thickness in device px; `None`: no band). `view`: the primary monitor's rectangle and/// its work area now (`None`: they could not be read; nothing is asked then, except giving the band back).pub fn apply(&mut self, api: &mut dyn AppBarCalls, want: Option<i32>, view: Option<(Rect, Rect)>) -> Applied {+ self.apply_on(api, want, view, DockEdge::Bottom)+ }++ /// Reserve an edge, replacing the registration when the dock changes position.+ pub fn apply_on(&mut self, api: &mut dyn AppBarCalls, want: Option<i32>, view: Option<(Rect, Rect)>, edge: DockEdge) -> Applied {+ if self.edge != edge && want.is_some() {+ if self.registered {+ api.remove();+ self.registered = false;+ }+ self.edge = edge;+ self.reasserts = 0;+ self.granted = None;+ }let Some(thickness) = want else {if self.registered {api.remove();@@ -145,11 +160,12 @@ impl Band {}// the whole bottom edge is asked for; the system takes away what the Windows taskbar (and any toolbar that came first) holds,// then the band is cut to its thickness at the bottom of what is left- let mut rc = api.query(monitor);- rc.top = rc.bottom - thickness;+ let mut logical = edge_axes(api.query(monitor), edge);+ logical.top = logical.bottom - thickness;+ let rc = edge_axes(logical, edge);if self.granted != Some(rc) {self.reasserts = 0;- } else if in_effect(rc, work) {+ } else if in_effect(logical, edge_axes(work, edge)) {self.reasserts = 0;return Applied::Unchanged;} else if self.reasserts >= MAX_REASSERT {@@ -225,6 +241,33 @@ mod tests {}}+ #[test]+ fn the_right_edge_reservation_uses_screen_coordinates_and_releases() {+ struct RightBar(Fake);++ impl AppBarCalls for RightBar {+ fn register(&mut self) -> bool { self.0.register() }+ fn query(&mut self, rc: Rect) -> Rect {+ edge_axes(self.0.query(edge_axes(rc, DockEdge::Right)), DockEdge::Right)+ }+ fn set_pos(&mut self, rc: Rect) {+ self.0.set_pos(edge_axes(rc, DockEdge::Right));+ }+ fn remove(&mut self) { self.0.remove(); }+ }++ let mut band = Band::new();+ let mut bar = RightBar(Fake::new());+ let monitor = edge_axes(MON, DockEdge::Right);+ let work = edge_axes(bar.0.work, DockEdge::Right);+ let expected = Rect::new(monitor.right - TASKBAR - BAND, monitor.top, monitor.right - TASKBAR, monitor.bottom);+ assert_eq!(band.apply_on(&mut bar, Some(BAND), Some((monitor, work)), DockEdge::Right), Applied::Set(expected));+ let work = edge_axes(bar.0.work, DockEdge::Right);+ assert_eq!(band.apply_on(&mut bar, Some(BAND), Some((monitor, work)), DockEdge::Right), Applied::Unchanged);+ assert_eq!(band.apply_on(&mut bar, None, None, DockEdge::Bottom), Applied::Released);+ assert!(!band.registered());+ }+/// One apply with the work area as it is now.fn go(b: &mut Band, f: &mut Fake, want: Option<i32>) -> Applied {let view = Some((MON, f.work));diff --git a/crates/rf-win/src/dock/layout.rs b/crates/rf-win/src/dock/layout.rsindex a9a50803..df86825c 100644--- a/crates/rf-win/src/dock/layout.rs+++ b/crates/rf-win/src/dock/layout.rs@@ -7,6 +7,8 @@//! size factor (`size::unit`). At the default size the factor is 1.0 and the unit is the DPI scale itself, so the numbers below are//! the dock the way it always was; the size setting multiplies every length of the dock by passing a different unit, nothing else.+pub use rf_shellguard::tbwork::DockEdge;+/// A rectangle in device px, `right` and `bottom` exclusive (the same shape as Win32's `RECT`).#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]pub struct Rect {@@ -43,6 +45,15 @@ impl Rect {}}+/// Convert between screen coordinates and the dock's along-edge/inward axes.+/// The right edge's along-edge coordinate is screen Y. This conversion is its own inverse.+pub fn edge_axes(rect: Rect, edge: DockEdge) -> Rect {+ match edge {+ DockEdge::Bottom => rect,+ DockEdge::Right => Rect::new(rect.top, rect.left, rect.bottom, rect.right),+ }+}+/// Distance of every island's bottom edge from the bottom of the work area, logical px. The same room is kept above the middle island/// (`RESERVED_HEIGHT`), so this is both gaps a maximized window's user sees: under the dock and between the dock and the window./// (10, then 6, until a user asked twice for less room above and below the dock.)@@ -61,7 +72,7 @@ pub const DEFAULT_RADIUS: f32 = 24.0;static RADIUS_BITS: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0x41C0_0000); // 24.0-/// The islands' corner radius in logical px: Settings › Dock › Corner roundness (issue 463), 24 unless chosen.+/// The islands' corner radius in logical px: Settings > Dock > Corner roundness (issue 463), 24 unless chosen.pub fn radius() -> f32 {f32::from_bits(RADIUS_BITS.load(std::sync::atomic::Ordering::Relaxed))}@@ -145,7 +156,7 @@ pub fn islands(work: Rect, scale: f32, widths: Widths) -> Islands {islands_with(work, scale, widths, SIDE_HEIGHT)}-/// The side islands' height for the setting "Yan adalar Dock kadar yüksek olsun" (`side_tall`): the middle island's, or their own.+/// The side islands' height for the setting "Yan adalar Dock kadar y�ksek olsun" (`side_tall`): the middle island's, or their own./// It is the height of their glass AT REST with the dock at its full height; while the dock is thin a tall side island is as low as/// the middle one (`thin::glass_height_px`, the app lowers the glass inside the window that this height made).pub fn side_height(tall: bool) -> f32 {@@ -174,6 +185,16 @@ pub fn islands_with(work: Rect, scale: f32, widths: Widths, side_height: f32) ->Islands { left, middle, right }}+/// Place the three islands along an edge. Widths are lengths along that edge.+pub fn islands_on_edge(work: Rect, scale: f32, widths: Widths, side_height: f32, edge: DockEdge) -> Islands {+ let layout = islands_with(edge_axes(work, edge), scale, widths, side_height);+ Islands {+ left: edge_axes(layout.left, edge),+ middle: edge_axes(layout.middle, edge),+ right: edge_axes(layout.right, edge),+ }+}+/// An island's window and the glass inside it, device px, screen coordinates. The window is bigger than the glass: the margin holds the/// shadow and, for the middle island, what grows out of the glass and the room for it to widen. The margin is transparent and lets/// the pointer through (see `hit`).@@ -227,6 +248,21 @@ pub fn placements(islands: &Islands, monitor: Rect, scale: f32, shadow: bool) ->Placements { left: make(islands.left, edge, edge), middle: make(islands.middle, edge + reserve, head), right: make(islands.right, edge, edge) }}+/// On the right edge, transparent headroom extends inward while the widening room runs vertically.+pub fn placements_on_edge(islands: &Islands, monitor: Rect, scale: f32, shadow: bool, edge: DockEdge) -> Placements {+ let logical = Islands {+ left: edge_axes(islands.left, edge),+ middle: edge_axes(islands.middle, edge),+ right: edge_axes(islands.right, edge),+ };+ let p = placements(&logical, edge_axes(monitor, edge), scale, shadow);+ let physical = |p: Placement| Placement {+ window: edge_axes(p.window, edge),+ glass: edge_axes(p.glass, edge),+ };+ Placements { left: physical(p.left), middle: physical(p.middle), right: physical(p.right) }+}+/// How far the middle island's glass may widen on each side, device px: what its window reserves, and what the neighbouring islands/// leave (their least gap is kept), never negative.pub fn growth_room(islands: &Islands, scale: f32) -> i32 {@@ -236,6 +272,14 @@ pub fn growth_room(islands: &Islands, scale: f32) -> i32 {reserve.min(to_left).min(to_right).max(0)}+pub fn growth_room_on_edge(islands: &Islands, scale: f32, edge: DockEdge) -> i32 {+ growth_room(&Islands {+ left: edge_axes(islands.left, edge),+ middle: edge_axes(islands.middle, edge),+ right: edge_axes(islands.right, edge),+ }, scale)+}+/// The width of the middle island for these item sizes (logical px, icons only, in order) and this many thin separators: the/// padding on both sides, the items and a gap between every two neighbouring items (separators are items).pub fn middle_width(icon_sizes: &[f32], separators: usize) -> f32 {@@ -261,12 +305,52 @@ pub fn placement_area(work: Rect, band: Option<Rect>, monitor: Rect) -> Rect {}}+pub fn placement_area_on_edge(work: Rect, band: Option<Rect>, monitor: Rect, edge: DockEdge) -> Rect {+ edge_axes(placement_area(edge_axes(work, edge), band.map(|b| edge_axes(b, edge)), edge_axes(monitor, edge)), edge)+}+#[cfg(test)]mod tests {use super::*;const W: Widths = Widths { left: 330.0, middle: 600.0, right: 280.0 };+ #[test]+ fn right_edge_uses_the_same_geometry_without_overlap_or_coordinate_drift() {+ let work = Rect::new(-1920, 100, 0, 1540);+ let widths = Widths { left: 120.0, middle: 600.0, right: 200.0 };+ for scale in [0.85, 1.0, 1.25, 1.5] {+ let i = islands_on_edge(work, scale, widths, SIDE_HEIGHT, DockEdge::Right);+ assert_eq!(i.left.right, -px(MARGIN_BOTTOM, scale));+ assert_eq!(i.middle.right, i.left.right);+ assert_eq!(i.right.right, i.left.right);+ assert_eq!(i.middle.width(), px(MIDDLE_HEIGHT, scale));+ assert!(i.left.bottom + px(MIN_GAP, scale) <= i.middle.top);+ assert!(i.middle.bottom + px(MIN_GAP, scale) <= i.right.top);+ let p = placements_on_edge(&i, work, scale, false, DockEdge::Right);+ assert!(p.middle.window.covers(&i.middle));+ assert!(work.covers(&p.middle.window));+ assert!(p.middle.window.left < i.middle.left);+ assert_eq!(edge_axes(edge_axes(i.middle, DockEdge::Right), DockEdge::Right), i.middle);+ assert_eq!(growth_room_on_edge(&i, scale, DockEdge::Right), growth_room(&islands_with(edge_axes(work, DockEdge::Right), scale, widths, SIDE_HEIGHT), scale));+ }+ let reserve = Rect::new(-80, 100, 0, 1540);+ let usable = Rect::new(-1920, 100, -80, 1540);+ assert_eq!(placement_area_on_edge(usable, Some(reserve), work, DockEdge::Right), work);+ }++ #[test]+ fn bottom_edge_layout_is_exactly_the_existing_layout() {+ let work = Rect::new(-2560, 0, 0, 1440);+ for scale in [1.0, 1.25, 1.5] {+ let old = islands_with(work, scale, W, SIDE_HEIGHT);+ let next = islands_on_edge(work, scale, W, SIDE_HEIGHT, DockEdge::Bottom);+ assert_eq!(next, old);+ assert_eq!(placements_on_edge(&next, work, scale, false, DockEdge::Bottom), placements(&old, work, scale, false));+ assert_eq!(growth_room_on_edge(&next, scale, DockEdge::Bottom), growth_room(&old, scale));+ }+ }+#[test]fn rounding_is_per_number() {assert_eq!(px(10.0, 1.25), 13); // 12.5 rounds updiff --git a/crates/rf-win/src/dock/system.rs b/crates/rf-win/src/dock/system.rsindex 27ccfcee..e7be1016 100644--- a/crates/rf-win/src/dock/system.rs+++ b/crates/rf-win/src/dock/system.rs@@ -12,7 +12,7 @@ use std::sync::{Arc, Mutex};use std::time::Duration;use super::band::{AppBarCalls, Applied, Band, MAX_REGISTER_TRIES, TrayId, announcement_is_restart};-use super::layout::{Rect, placement_area};+use super::layout::{DockEdge, Rect, placement_area_on_edge};use crate::shellhost::ShellMode;use crate::shellhost::watch::{Cause, ModeWatch, Seen, SystemLook};@@ -109,6 +109,7 @@ pub enum SystemEvent {struct Shared {/// The thickness the app wants reserved (`None`: no band), device px.want: Option<i32>,+ edge: DockEdge,/// The band the system granted.band: Option<Rect>,}@@ -302,7 +303,16 @@ impl DockSystem {/// primary monitor: maximised windows then stop above the band. Registers the toolbar the first time and moves it afterwards./// Asynchronous: a [`SystemEvent::LayoutChanged`] follows when the work area has changed.pub fn reserve(&self, thickness_px: i32) {- self.shared.lock().unwrap_or_else(|p| p.into_inner()).want = Some(thickness_px.max(1));+ self.reserve_on(Some(thickness_px), DockEdge::Bottom);+ }++ /// Keep the selected edge free, or release the band when the thickness is absent.+ pub fn reserve_on(&self, thickness_px: Option<i32>, edge: DockEdge) {+ {+ let mut shared = self.shared.lock().unwrap_or_else(|p| p.into_inner());+ shared.want = thickness_px.map(|t| t.max(1));+ shared.edge = edge;+ }self.post_reserve();}@@ -329,7 +339,11 @@ impl DockSystem {/// [`placement_area`]). `None` without a monitor.pub fn placement_area(&self) -> Option<(MonitorInfo, Rect)> {let m = primary_monitor()?;- Some((m, placement_area(m.work, edge_band().or(self.band()).or(own_band()), m.rect)))+ let shared = self.shared.lock().unwrap_or_else(|p| p.into_inner());+ let band = edge_band().or(shared.band).or(own_band());+ // The active band may still belong to the previous edge during a change.+ let edge = band.map_or(shared.edge, |b| if b.width() < b.height() { DockEdge::Right } else { DockEdge::Bottom });+ Some((m, placement_area_on_edge(m.work, band, m.rect, edge)))}/// The last known state of the full-screen check (kept up to date by the watch).@@ -396,6 +410,7 @@ fn bar_data(hwnd: windows::Win32::Foundation::HWND) -> windows::Win32::UI::Shell/// The real toolbar calls: messages to Explorer's taskbar window (`SHAppBarMessage`), for this window.struct RealBar {hwnd: windows::Win32::Foundation::HWND,+ edge: DockEdge,}impl AppBarCalls for RealBar {@@ -410,7 +425,10 @@ impl AppBarCalls for RealBar {fn query(&mut self, edge: Rect) -> Rect {let mut d = bar_data(self.hwnd);- d.uEdge = windows::Win32::UI::Shell::ABE_BOTTOM;+ d.uEdge = match self.edge {+ DockEdge::Bottom => windows::Win32::UI::Shell::ABE_BOTTOM,+ DockEdge::Right => windows::Win32::UI::Shell::ABE_RIGHT,+ };d.rc = windows::Win32::Foundation::RECT { left: edge.left, top: edge.top, right: edge.right, bottom: edge.bottom };unsafe { windows::Win32::UI::Shell::SHAppBarMessage(windows::Win32::UI::Shell::ABM_QUERYPOS, &mut d) };rect_of(d.rc)@@ -418,7 +436,10 @@ impl AppBarCalls for RealBar {fn set_pos(&mut self, rc: Rect) {let mut d = bar_data(self.hwnd);- d.uEdge = windows::Win32::UI::Shell::ABE_BOTTOM;+ d.uEdge = match self.edge {+ DockEdge::Bottom => windows::Win32::UI::Shell::ABE_BOTTOM,+ DockEdge::Right => windows::Win32::UI::Shell::ABE_RIGHT,+ };d.rc = windows::Win32::Foundation::RECT { left: rc.left, top: rc.top, right: rc.right, bottom: rc.bottom };unsafe { windows::Win32::UI::Shell::SHAppBarMessage(windows::Win32::UI::Shell::ABM_SETPOS, &mut d) };}@@ -434,12 +455,19 @@ impl AppBarCalls for RealBar {unsafe fn apply_reservation(hwnd: windows::Win32::Foundation::HWND, ctx: &mut Ctx) {use windows::Win32::UI::WindowsAndMessaging::SetTimer;// While the host owns the bottom edge no band is registered (the host sets the work area itself): the wish is "none".- let want = if APPBAR_SUPPRESSED.load(Ordering::SeqCst) { None } else { ctx.shared().want };+ let (want, edge) = {+ let shared = ctx.shared();+ (if APPBAR_SUPPRESSED.load(Ordering::SeqCst) { None } else { shared.want }, shared.edge)+ };let view = primary_monitor().map(|m| (m.rect, m.work));- let applied = ctx.band.apply(&mut RealBar { hwnd }, want, view);+ let applied = ctx.band.apply_on(&mut RealBar { hwnd, edge }, want, view, edge);APPBAR_HELD.store(ctx.band.registered(), Ordering::SeqCst);if !ctx.band.registered() {ctx.tray_at_registration = None;+ let stale = ctx.shared().band.take().is_some();+ if stale && applied != Applied::Released {+ ctx.emit(SystemEvent::LayoutChanged);+ }}match applied {Applied::Set(granted) => {@@ -553,7 +581,7 @@ unsafe extern "system" fn wndproc(hwnd: windows::Win32::Foundation::HWND, msg: uSetWindowLongPtrW(hwnd, GWLP_USERDATA, 0);// (the band is given back: want None)SYSTEM_WINDOW.store(0, Ordering::SeqCst);- ctx.band.apply(&mut RealBar { hwnd }, None, None);+ ctx.band.apply(&mut RealBar { hwnd, edge: DockEdge::Bottom }, None, None);APPBAR_HELD.store(false, Ordering::SeqCst);ctx.shared().band = None;drop(ctx);@@ -698,7 +726,7 @@ unsafe extern "system" fn wndproc(hwnd: windows::Win32::Foundation::HWND, msg: uif wp.0 != 0 {// (written to the log so that a dock that ends with the session says why)log::warn!("shell host exits: the session is ending");- ctx.band.apply(&mut RealBar { hwnd }, None, None);+ ctx.band.apply(&mut RealBar { hwnd, edge: DockEdge::Bottom }, None, None);}LRESULT(0)}diff --git a/crates/rf-win/src/shellhost/workarea.rs b/crates/rf-win/src/shellhost/workarea.rsindex 89d91fd7..fc7a0f7f 100644--- a/crates/rf-win/src/shellhost/workarea.rs+++ b/crates/rf-win/src/shellhost/workarea.rs@@ -23,7 +23,7 @@//! The tests show the rule [`permitted`] that [`SystemSetter`] asks before it calls Windows, and the keeper on a fake.use super::appcmd::{Shell, shell_now};-use crate::dock::layout::Rect;+use crate::dock::layout::{DockEdge, Rect};/// Who owns the shell window, looked at fresh.pub trait ShellState {@@ -80,7 +80,11 @@ pub struct WorkAreaKeeper {/// The arithmetic is shared with the work-area rule of the taskbar hide beside Explorer (`rf_shellguard::tbwork`, which sets the same/// rectangle for a monitor whose taskbar we hid): two owners of the work area, one rule for "the monitor less the band".pub fn target(monitor: Rect, thickness: i32) -> Rect {- let [left, top, right, bottom] = rf_shellguard::tbwork::monitor_less_band([monitor.left, monitor.top, monitor.right, monitor.bottom], thickness);+ target_on(monitor, thickness, DockEdge::Bottom)+}++pub fn target_on(monitor: Rect, thickness: i32, edge: DockEdge) -> Rect {+ let [left, top, right, bottom] = rf_shellguard::tbwork::monitor_less_band_on([monitor.left, monitor.top, monitor.right, monitor.bottom], thickness, edge);Rect { left, top, right, bottom }}@@ -102,6 +106,10 @@ impl WorkAreaKeeper {/// Brings the work area in line: `thickness` Some = the monitor less the band; None = put back what was there. `work`: the work area/// of `monitor` now.pub fn apply(&mut self, state: &dyn ShellState, setter: &mut dyn WorkAreaSetter, thickness: Option<i32>, monitor: Rect, work: Rect) -> Done {+ self.apply_on(state, setter, thickness, monitor, work, DockEdge::Bottom)+ }++ pub fn apply_on(&mut self, state: &dyn ShellState, setter: &mut dyn WorkAreaSetter, thickness: Option<i32>, monitor: Rect, work: Rect, edge: DockEdge) -> Done {// lock 1: the shell is looked at now, not rememberedlet shell = state.shell();if shell != Shell::Nobody {@@ -113,7 +121,7 @@ impl WorkAreaKeeper {}match thickness {Some(t) => {- let want = target(monitor, t);+ let want = target_on(monitor, t, edge);if work == want {// Already as wanted. When it is not from this keeper (a host that ran before set it and was restarted: the work// area outlives the process), it is adopted: the band is ours, or the islands would be placed from the shrunkendiff --git a/crates/rf-win/src/taskbar_hide.rs b/crates/rf-win/src/taskbar_hide.rsindex 82f19c08..f9cb6412 100644--- a/crates/rf-win/src/taskbar_hide.rs+++ b/crates/rf-win/src/taskbar_hide.rs@@ -29,6 +29,7 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};use rf_shellguard::statefile::{self, ShellStateFile};use rf_shellguard::tbctl::{Controller, HideWorld, Status};+use rf_shellguard::tbwork::DockEdge;use rf_shellguard::tbmodel::{LiveWindow, MonitorGeom, Refusal, Target};use crate::dock::layout::Rect;use rf_shellguard::win::tbwin;@@ -347,7 +348,7 @@ pub fn install_panic_restore() {enum Cmd {Wanted(bool),/// The dock's band changed (`None`: it reserves none).- Band(Option<i32>),+ Band(Option<i32>, DockEdge),/// The docks on the other monitors changed their bands (monitor device name, thickness in device px).OtherBands(Vec<(String, i32)>),/// Leave (restore what is hidden, tell the guard) and end the thread.@@ -491,8 +492,8 @@ unsafe extern "system" fn wndproc(hwnd: HWND, msg: u32, wp: WPARAM, lp: LPARAM)ctx.guarded(|c, w| c.set_wanted(w, on));sync_timer(hwnd, ctx);}- Cmd::Band(band) => {- ctx.guarded(|c, w| c.set_band(w, band));+ Cmd::Band(band, edge) => {+ ctx.guarded(|c, w| c.set_band_on(w, band, edge));sync_timer(hwnd, ctx);}Cmd::OtherBands(bands) => {@@ -656,11 +657,15 @@ impl TaskbarHider {/// Starts the thread and its window. Nothing is hidden until [`TaskbarHider::set_wanted`]`(true)`. The thread first undoes the/// record of a crashed earlier host, whatever the setting says.pub fn start(cfg: Config) -> Result<TaskbarHider, String> {+ Self::start_on(cfg, DockEdge::Bottom)+ }++ pub fn start_on(cfg: Config, edge: DockEdge) -> Result<TaskbarHider, String> {install_panic_restore();let host_pid = std::process::id();let host_start = tbwin::process_start_time(host_pid).unwrap_or(0);let ctl = Controller::new(host_pid, host_start);- let ctl = if cfg.band_known { ctl.with_band(cfg.band_px) } else { ctl };+ let ctl = if cfg.band_known { ctl.with_band_on(cfg.band_px, edge) } else { ctl };let (tx, rx) = std::sync::mpsc::channel::<Cmd>();let status = Arc::new(Mutex::new(Status::Off));let ctx = Box::new(Ctx { ctl, world: RealWorld::new(cfg), rx, status: status.clone(), wanted: false, dead: false, follow_ups: 0, stopping: false });@@ -696,7 +701,11 @@ impl TaskbarHider {/// force the work area follows; before, it is the wish for when it comes - and the first word the dock says is what lets the/// bottom edge be taken at all. Session only.pub fn set_band(&self, band_px: Option<i32>) {- self.post(Cmd::Band(band_px));+ self.set_band_on(band_px, DockEdge::Bottom);+ }++ pub fn set_band_on(&self, band_px: Option<i32>, edge: DockEdge) {+ self.post(Cmd::Band(band_px, edge));}/// The docks on the monitors that are not the primary one changed their bands: `(the monitor's device name, thickness in device px)`