Skip to content

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.

Tray host: tell message-only windows that the taskbar came (768)

gelenmedya4a5b91172245
diff --git a/crates/rf-win/src/trayhost/win.rs b/crates/rf-win/src/trayhost/win.rs
index 1ca8c822..e526cd63 100644
--- a/crates/rf-win/src/trayhost/win.rs
+++ b/crates/rf-win/src/trayhost/win.rs
@@ -8,7 +8,7 @@
//! `SetWindowPos(HWND_TOPMOST)` on OUR window only (Explorer's is never moved, hidden or restyled); its rectangle, its child's
//! rectangle and its window properties (`TaskbandHWND`: programs read it from the first `Shell_TrayWnd` to find the taskbar's
//! button window) are copied from Explorer's;
-//! * [`Win32Broadcast`]: `SendNotifyMessage(HWND_BROADCAST, TaskbarCreated)`;
+//! * [`Win32Broadcast`]: `SendNotifyMessage(HWND_BROADCAST, TaskbarCreated)`, and the same to each message-only window;
//! * [`Win32Owners`]: `IsWindow`, `GetWindowThreadProcessId`, `AllowSetForegroundWindow`, `SendNotifyMessage` to an icon's owner;
//! * [`Win32Pixels`]: `GetIconInfo` + `GetDIBits`, with the arithmetic in `pixels.rs`;
//! * the host thread: window class, message loop, the window procedure.
@@ -40,7 +40,7 @@ use windows::Win32::System::Threading::{OpenProcess, PROCESS_NAME_WIN32, PROCESS
use windows::Win32::UI::HiDpi::{DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2, SetThreadDpiAwarenessContext};
use windows::Win32::UI::WindowsAndMessaging::{
AllowSetForegroundWindow, CS_DBLCLKS, CreateWindowExW, DefWindowProcW, DestroyWindow, DispatchMessageW, EnumPropsExW, EnumWindows, FindWindowExW, GWL_EXSTYLE,
- FindWindowW, GetClassNameW, GetMessageW, GetPropW, GetWindowLongPtrW, GetWindowRect, GetWindowThreadProcessId, HICON, HWND_BROADCAST, HWND_TOPMOST, ICONINFO, IsWindow, KillTimer,
+ FindWindowW, GetClassNameW, GetMessageW, GetPropW, GetWindowLongPtrW, GetWindowRect, GetWindowThreadProcessId, HICON, HWND_BROADCAST, HWND_MESSAGE, HWND_TOPMOST, ICONINFO, IsWindow, KillTimer,
LWA_ALPHA, MSG, PostMessageW, PostQuitMessage, RegisterClassExW, RegisterWindowMessageW, RemovePropW, SMTO_ABORTIFHUNG, SW_SHOWNOACTIVATE, SWP_NOACTIVATE,
SWP_NOMOVE, SWP_NOSIZE, SWP_NOZORDER, SendMessageTimeoutW, SendNotifyMessageW, SetLayeredWindowAttributes, SetPropW, SetTimer, SetWindowLongPtrW, SetWindowPos,
ShowWindow, TranslateMessage, UnregisterClassW, WM_CLOSE, WM_COPYDATA, WM_DESTROY, WM_DISPLAYCHANGE, WM_DPICHANGED, WM_ENDSESSION, WM_QUERYENDSESSION, WM_SETTINGCHANGE,
@@ -207,10 +207,36 @@ impl Broadcast for Win32Broadcast {
unsafe {
let _ = SendNotifyMessageW(HWND_BROADCAST, self.taskbar_created, WPARAM(0), LPARAM(0));
}
+ let told = tell_message_only_windows(self.taskbar_created);
+ log::info!("tray host: TaskbarCreated also sent to {told} message-only windows");
}
}
}
+/// Sends `msg` to every message-only window of another process. A broadcast reaches top-level windows only, and some programs keep
+/// their tray icon on a message-only window (NVIDIA's display container does, `NotificationIconWindowClass`): they never heard the
+/// announcement and never added their icon to the host (issue 768, 2 of 11 icons in the dock). A window that did not register the
+/// message ignores it, as it ignores the broadcast. Returns how many were sent to.
+fn tell_message_only_windows(msg: u32) -> usize {
+ let own = std::process::id();
+ let mut told = 0;
+ let mut after = HWND::default();
+ // (bounded: a system has some hundreds; the list cannot loop, but a cap keeps a changing list from running long)
+ for _ in 0..4096 {
+ let Ok(h) = (unsafe { FindWindowExW(Some(HWND_MESSAGE), Some(after), PCWSTR::null(), PCWSTR::null()) }) else { break };
+ if h.0.is_null() {
+ break;
+ }
+ after = h;
+ let mut pid = 0u32;
+ unsafe { GetWindowThreadProcessId(h, Some(&mut pid)) };
+ if pid != 0 && pid != own && unsafe { SendNotifyMessageW(h, msg, WPARAM(0), LPARAM(0)) }.is_ok() {
+ told += 1;
+ }
+ }
+ told
+}
+
// ---------------------------------------------------------------- pixels
pub struct Win32Pixels;