A lightweight, macOS-style dock for Windows 11, with glass visuals, smooth magnification, and Genie effect.
fix(dock): restore taskbar hiding across displays
Rafaelf006e276c46a
diff --git a/apps/dock/src/app.rs b/apps/dock/src/app.rsindex dd88970..7891c92 100644--- a/apps/dock/src/app.rs+++ b/apps/dock/src/app.rs@@ -3841,6 +3841,14 @@ impl App {}fn edge_changed(&mut self) -> Result<()> {+ // Explorer can recreate a secondary taskbar while the dock is running.+ // Check on monitor entry so it is transparent before the edge dwell.+ if self.config.auto_hide+ && self.taskbar_worker.is_none()+ && taskbar::needs_visibility_repair()+ {+ self.request_taskbar(false)?;+ }let (target, wait) = edge_watch::pending();let on_dock_edge = matches!(target, Some(EdgeTarget::Dock(screen))if self.stage.as_ref().is_some_and(|stage| stage.key.screen == screen));@@ -4619,7 +4627,13 @@ unsafe extern "system" fn wndproc(hwnd: HWND, msg: u32, w: WPARAM, l: LPARAM) ->});}// SAFETY: `hwnd` is our window; scheduling the same timer resets it.- unsafe { SetTimer(Some(hwnd), REFRESH_TIMER, REFRESH_DELAY_MS, None) };+ unsafe {+ SetTimer(Some(hwnd), REFRESH_TIMER, REFRESH_DELAY_MS, None);+ if msg == WM_DISPLAYCHANGE && hwnd == main_window() {+ // Let Explorer settle and create any new secondary taskbars.+ SetTimer(Some(hwnd), TASKBAR_TIMER, TASKBAR_DELAY_MS, None);+ }+ }}// On battery or charging, or energy saver turned on or off: glass may// have to become solid, or the other way round.diff --git a/apps/dock/src/edge_watch.rs b/apps/dock/src/edge_watch.rsindex a714b7f..d6572eb 100644--- a/apps/dock/src/edge_watch.rs+++ b/apps/dock/src/edge_watch.rs@@ -48,6 +48,7 @@ struct Edges {window: isize,top: Option<RECT>,bottoms: Vec<RECT>,+ pointer_screen: Option<RECT>,target: Option<Target>,entered: Option<Instant>,}@@ -56,31 +57,34 @@ static EDGES: Mutex<Edges> = Mutex::new(Edges {window: 0,top: None,bottoms: Vec::new(),+ pointer_screen: None,target: None,entered: None,});impl Edges {- fn at(&self, point: POINT) -> Option<Target> {- let within_x = |rect: RECT| point.x >= rect.left && point.x < rect.right;- if self.top.is_some_and(|screen| {- within_x(screen) && (screen.top..screen.top + EDGE_DEPTH).contains(&point.y)+ fn at(&self, point: POINT, screen: Option<RECT>) -> Option<Target> {+ if self.top.is_some_and(|top| {+ (top.left..top.right).contains(&point.x)+ && (top.top..top.top + EDGE_DEPTH).contains(&point.y)}) {return Some(Target::MenuBar);}- self.bottoms- .iter()- .copied()- .find(|&screen| {- within_x(screen) && (screen.bottom - EDGE_DEPTH..screen.bottom).contains(&point.y)- })+ screen+ .filter(|screen| point.y >= screen.bottom - EDGE_DEPTH).map(Target::Dock)}fn observe(&mut self, point: POINT, now: Instant) -> bool {- let target = self.at(point);+ let screen = self.bottoms.iter().copied().find(|screen| {+ (screen.left..screen.right).contains(&point.x)+ && (screen.top..screen.bottom).contains(&point.y)+ });+ let changed_screen = self.pointer_screen != screen;+ self.pointer_screen = screen;+ let target = self.at(point, screen);if target == self.target {- return false;+ return changed_screen;}self.target = target;self.entered = target.map(|_| now);@@ -208,6 +212,7 @@ impl Drop for EdgeWatch {{let mut edges = lock();edges.window = 0;+ edges.pointer_screen = None;edges.target = None;edges.entered = None;}@@ -378,6 +383,28 @@ mod tests {assert!(matches!(edges.dwell(left, start + DWELL * 3), Reveal::Idle));}+ #[test]+ fn monitor_entry_notifies_before_the_pointer_reaches_the_edge() {+ let primary = RECT {+ left: 0,+ top: 0,+ right: 1920,+ bottom: 1080,+ };+ let secondary = RECT {+ left: 1920,+ right: 3840,+ ..primary+ };+ let mut edges = Edges::default();+ edges.set_bottoms(vec![primary, secondary]);+ let now = Instant::now();+ assert!(edges.observe(POINT { x: 700, y: 500 }, now));+ assert!(edges.observe(POINT { x: 2500, y: 500 }, now));+ assert_eq!(edges.target, None);+ assert!(!edges.observe(POINT { x: 2600, y: 500 }, now));+ }+#[test]fn pending_reveal_cancels_when_the_pointer_crosses_the_edge() {let mut edges = Edges::default();diff --git a/crates/muelle-shell/src/taskbar.rs b/crates/muelle-shell/src/taskbar.rsindex 0a97e92..2aa0faf 100644--- a/crates/muelle-shell/src/taskbar.rs+++ b/crates/muelle-shell/src/taskbar.rs@@ -43,6 +43,11 @@ pub fn take_over() -> bool {take_over_taskbars(&taskbars(), &state_file())}+/// Whether Explorer has restored the visibility of a taskbar window.+pub fn needs_visibility_repair() -> bool {+ taskbars().into_iter().any(|hwnd| !is_ghosted(hwnd))+}+fn take_over_taskbars(bars: &[HWND], file: &std::path::Path) -> bool {// A logon task can run before Explorer creates Shell_TrayWnd. Saving// an absent shell's state would lose the user's original preference.@@ -64,10 +69,12 @@ fn take_over_taskbars(bars: &[HWND], file: &std::path::Path) -> bool {return false;}}- set_autohide(true);+ if !autohide_enabled() {+ set_autohide(true);+ }let mut hidden = true;for &hwnd in bars {- hidden &= set_ghost(hwnd, true);+ hidden &= is_ghosted(hwnd) || set_ghost(hwnd, true);}hidden}@@ -157,15 +164,21 @@ fn set_ghost(hwnd: HWND, ghost: bool) -> bool {let _ = SetLayeredWindowAttributes(hwnd, COLORREF(0), 255, LWA_ALPHA);SetWindowLongPtrW(hwnd, GWL_EXSTYLE, style & !GHOST_STYLES);}- if !ghost {- return true;+ }+ !ghost || is_ghosted(hwnd)+}++fn is_ghosted(hwnd: HWND) -> bool {+ // SAFETY: Read-only queries with valid outputs. A destroyed window fails the check.+ unsafe {+ if GetWindowLongPtrW(hwnd, GWL_EXSTYLE) & GHOST_STYLES != GHOST_STYLES {+ return false;}let mut alpha = 255;let mut flags = Default::default();GetLayeredWindowAttributes(hwnd, None, Some(&mut alpha), Some(&mut flags)).is_ok()&& alpha == 0&& flags.contains(LWA_ALPHA)- && GetWindowLongPtrW(hwnd, GWL_EXSTYLE) & GHOST_STYLES == GHOST_STYLES}}@@ -205,11 +218,18 @@ mod tests {None,None,)?;+ let initially_ghosted = is_ghosted(window);let hidden = set_ghost(window, true);+ SetLayeredWindowAttributes(window, COLORREF(0), 255, LWA_ALPHA)?;+ let reset_was_detected = !is_ghosted(window);+ let hidden_again = set_ghost(window, true);let restored = set_ghost(window, false);let styles = GetWindowLongPtrW(window, GWL_EXSTYLE);let _ = DestroyWindow(window);+ assert!(!initially_ghosted);assert!(hidden);+ assert!(reset_was_detected);+ assert!(hidden_again);assert!(restored);assert_eq!(styles & GHOST_STYLES, 0);}