From 9b34f90b3e2037b29e97735e7da22e95ebc885ed Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Tue, 5 Nov 2024 17:25:53 +0800 Subject: [PATCH] use GetShellWindow() as default workspace window --- packages/wm/src/common/platform/platform.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/wm/src/common/platform/platform.rs b/packages/wm/src/common/platform/platform.rs index 774a92731..63dd94e2f 100644 --- a/packages/wm/src/common/platform/platform.rs +++ b/packages/wm/src/common/platform/platform.rs @@ -19,9 +19,9 @@ use windows::{ }, WindowsAndMessaging::{ CreateWindowExW, DispatchMessageW, GetAncestor, GetCursorPos, - FindWindowA, GetForegroundWindow, GetMessageW, MessageBoxW, + GetDesktopWindow, GetForegroundWindow, GetMessageW, MessageBoxW, PeekMessageW, PostThreadMessageW, RegisterClassW, SetCursorPos, - SystemParametersInfoW, TranslateMessage, WindowFromPoint, + SystemParametersInfoW, TranslateMessage, WindowFromPoint, GetShellWindow, ANIMATIONINFO, CS_HREDRAW, CS_VREDRAW, CW_USEDEFAULT, GA_ROOT, MB_ICONERROR, MB_OK, MB_SYSTEMMODAL, MSG, PM_REMOVE, SPI_GETANIMATION, SPI_SETANIMATION, SW_NORMAL, @@ -49,11 +49,14 @@ impl Platform { NativeWindow::new(handle.0) } - /// Gets the `NativeWindow` instance of the desktop window. + // Get Explorer wallpaper window (i.e. "Progman"). Default to the + // desktop window on which the wallpaper window sits above for edge + // case where Explorer isn't running. pub fn desktop_window() -> NativeWindow { - let handle = unsafe { - FindWindowA(PCSTR("Progman\0".as_ptr() as *const u8), PCSTR::null()) - }; + let mut handle = unsafe { GetShellWindow() }; + if handle == HWND(0) { + handle = unsafe { GetDesktopWindow() }; + } NativeWindow::new(handle.0) }