From 1b43ce3acb991707134eeffe5917007cba68481d Mon Sep 17 00:00:00 2001 From: GuilhermeLima Date: Wed, 25 Nov 2026 01:07:35 -0300 Subject: [PATCH] topbar: the file manager's windows belong to the File Explorer pin refresh_buttons matches windows to pins by exe. The File Explorer pin takes explorer.exe from its icon location, but the windows on a WinRust machine are rust-explorer.exe, so they went to another pin (or none) and the File Explorer button never showed them: a minimized window looked gone and a click started a second one. With a File Explorer pin they now go to it. Co-Authored-By: Claude Sonnet 5.5 --- plugins/topbar/src/main.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/plugins/topbar/src/main.rs b/plugins/topbar/src/main.rs index e1efe5e..ab97de1 100644 --- a/plugins/topbar/src/main.rs +++ b/plugins/topbar/src/main.rs @@ -1196,14 +1196,29 @@ unsafe fn load_pins() { } } +/// The exe the File Explorer pin stands for (lower-case): its icon location, "%windir%\explorer.exe". +fn file_explorer_exe() -> String { + expand_env(r"%windir%\explorer.exe").to_lowercase() +} + +/// The windows of WinRust's file manager belong to the File Explorer pin when there is one: that pin is what the user clicks +/// to open "Explorer" here, and only windows of explorer.exe matched it, so its button never showed them (a minimized +/// window looked gone and the click started a second one). Without such a pin they keep their own exe's button. +fn as_pinned_exe(exe: &str, explorer: &str, explorer_pinned: bool) -> String { + if explorer_pinned && exe.ends_with(r"\rust-explorer\rust-explorer.exe") { explorer.to_string() } else { exe.to_string() } +} + fn refresh_buttons() { let mut wins: Vec = Vec::new(); unsafe { EnumWindows(Some(collect), &mut wins as *mut _ as LPARAM) }; let mut btns = vec![Btn { pin: None, wins: vec![], icon: null_mut() }]; PINS.with_borrow(|pins| btns.extend((0..pins.len()).map(|i| Btn { pin: Some(i), wins: vec![], icon: null_mut() }))); let mut loose: Vec = Vec::new(); + let explorer = file_explorer_exe(); + let explorer_pinned = PINS.with_borrow(|p| p.iter().any(|p| p.target == explorer)); for w in wins { let exe = unsafe { exe_of(w) }; + let exe = as_pinned_exe(&exe, &explorer, explorer_pinned); // pins of one exe (two browser profiles, #132) tell their windows apart by AppUserModelID; a pin or window without one // takes any window of its exe let pin = PINS.with_borrow(|p| { @@ -3093,6 +3108,15 @@ mod tests { assert_eq!((arcs_lit(0), arcs_lit(40), arcs_lit(100)), (1, 2, 3)); } + #[test] + fn file_manager_windows_belong_to_the_file_explorer_pin() { + use super::as_pinned_exe; + let (rx, ex) = (r"c:\program files\rust-explorer\rust-explorer.exe", r"c:\windows\explorer.exe"); + assert_eq!(as_pinned_exe(rx, ex, true), ex); // the pin the user clicks gets the windows + assert_eq!(as_pinned_exe(rx, ex, false), rx); // no such pin: the file manager's own pin keeps them + assert_eq!(as_pinned_exe(r"c:\tools\other.exe", ex, true), r"c:\tools\other.exe"); + } + #[test] fn mix_blends() { assert_eq!(super::mix(super::rgb(0, 0, 0), super::rgb(200, 100, 50), 0.0), super::rgb(0, 0, 0));