Skip to content

Commit

Permalink
fix: set focus to valid desktop window in an empty workspace (#821)
Browse files Browse the repository at this point in the history
DreamMaoMao authored Nov 5, 2024
1 parent 4fd4e17 commit 2eda7e8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/wm/src/common/platform/platform.rs
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 2eda7e8

Please sign in to comment.