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
Sidebar rail peek: ignore sampled screen colours that mismatch the window theme (issue 851)
Marcos Gramelich4e969d99838d
diff --git a/crates/rf-app/src/workspace.rs b/crates/rf-app/src/workspace.rsindex 94f9e8e8..037227d7 100644--- a/crates/rf-app/src/workspace.rs+++ b/crates/rf-app/src/workspace.rs@@ -5744,6 +5744,13 @@ const RAIL_IN_MS: u64 = 130;fn rail_peek_width(full: f32, shown: f32) -> f32 {(RAIL_W + (full - RAIL_W) * shown).max(RAIL_W)}++/// Whether a colour sampled off the screen behind the rail matches this window's theme.+/// When a file dialog opens over an app of the opposite theme and the pointer is already over the rail+/// before DWM finishes presenting the dialog, `screen_color` can read the caller app behind it (issue 851).+fn rail_peek_color_matches(c: Hsla, dark: bool) -> bool {+ if dark { c.l < 0.45 } else { c.l > 0.55 }+}const RAIL_SNAP: f32 = 120.;const SIDEBAR_MAX: f32 = 420.;const PREVIEW_MIN: f32 = 220.;@@ -6493,6 +6500,7 @@ impl Render for Workspace {let frame_key = (p.dark, window.appearance());if self.frame_dark != Some(frame_key) {self.frame_dark = Some(frame_key);+ self.rail_peek_bg = None;use raw_window_handle::{HasWindowHandle, RawWindowHandle};if let Ok(h) = window.window_handle() {if let RawWindowHandle::Win32(w) = h.as_raw() {@@ -6607,7 +6615,7 @@ impl Render for Workspace {.w(px(full_w))// (the sidebar inside keeps its full width while the panel's own width moves: nothing in it is laid out anew).overflow_hidden()- .bg(self.rail_peek_bg.unwrap_or(Hsla { a: 1., ..p.content_bg }))+ .bg(self.rail_peek_bg.filter(|c| rail_peek_color_matches(*c, p.dark)).unwrap_or(Hsla { a: 1., ..p.content_bg })).border_r_1().border_color(p.border).rounded_r(theme::RADIUS)@@ -7176,10 +7184,13 @@ impl Render for Workspace {let s = window.scale_factor();let height = f32::from(window.viewport_size().height);let at = |v: f32| (v * s) as i32;- // (over glass the screen shows the desktop behind the window, not the window's tint)+ let dark = Palette::for_window(window).dark;+ // (over glass the screen shows the desktop behind the window, not the window's tint;+ // before a new dialog finishes presenting, it can show the caller app behind it, issue 851)this.rail_peek_bg = rf_win::window::screen_color(crate::look::window::hwnd_of(window), at(3.), at(110.), at(height - 60.)).filter(|_| this.glass_hwnd == 0)- .map(|[r, g, b]| Hsla::from(gpui_kit::rgb(u32::from(r) << 16 | u32::from(g) << 8 | u32::from(b))));+ .map(|[r, g, b]| Hsla::from(gpui_kit::rgb(u32::from(r) << 16 | u32::from(g) << 8 | u32::from(b))))+ .filter(|c| rail_peek_color_matches(*c, dark));}this.rail_peek[0] = *h;cx.notify();@@ -7422,7 +7433,8 @@ mod launch_tests {#[cfg(test)]mod rail_peek_tests {- use super::{RAIL_W, rail_peek_width};+ use super::{RAIL_W, rail_peek_color_matches, rail_peek_width};+ use gpui_kit::Hsla;/// The sidebar that comes out of the rail: from the rail's own width to the full one, a little past it while the spring swings,/// and never narrower than the rail.@@ -7434,6 +7446,21 @@ mod rail_peek_tests {assert_eq!(rail_peek_width(240.0, -0.2), RAIL_W);assert!(rail_peek_width(240.0, 0.5) > RAIL_W && rail_peek_width(240.0, 0.5) < 240.0);}++ #[test]+ fn sampled_rail_color_must_match_theme_polarity() {+ let dark_mica = Hsla::from(gpui_kit::rgb(0x202228));+ let light_app = Hsla::from(gpui_kit::rgb(0xf3f3f3));+ let mid_grey = Hsla::from(gpui_kit::rgb(0x808080));++ assert!(rail_peek_color_matches(dark_mica, true));+ assert!(!rail_peek_color_matches(light_app, true));+ assert!(!rail_peek_color_matches(mid_grey, true));++ assert!(rail_peek_color_matches(light_app, false));+ assert!(!rail_peek_color_matches(dark_mica, false));+ assert!(!rail_peek_color_matches(mid_grey, false));+ }}/// The stops of Tab in a window, in order.