Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

fix: set focus to valid desktop window in an empty workspace (#821)

DreamMaoMao2eda7e899315
diff --git a/packages/wm/src/common/platform/platform.rs b/packages/wm/src/common/platform/platform.rs
index 5a3afc9e..62a15182 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)
}