From 2eda7e8993158bdfb281432bc9676ca90611973e Mon Sep 17 00:00:00 2001 From: DreamMaoMao <30348075+DreamMaoMao@users.noreply.github.com> Date: Tue, 5 Nov 2024 20:49:14 +0800 Subject: [PATCH] fix: set focus to valid desktop window in an empty workspace (#821) --- packages/wm/src/common/platform/platform.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/wm/src/common/platform/platform.rs b/packages/wm/src/common/platform/platform.rs index 5a3afc9e9..62a151828 100644 --- a/packages/wm/src/common/platform/platform.rs +++ b/packages/wm/src/common/platform/platform.rs @@ -21,7 +21,7 @@ use windows::{ CreateWindowExW, DispatchMessageW, GetAncestor, GetCursorPos, 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, SW_HIDE, @@ -49,9 +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 { GetDesktopWindow() }; + let mut handle = unsafe { GetShellWindow() }; + if handle == HWND(0) { + handle = unsafe { GetDesktopWindow() }; + } NativeWindow::new(handle.0) }