Skip to content

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

fix: window z-order update failing sporadically (#1090)

Lars Berger204d426c6eb3
diff --git a/packages/wm-platform/src/native_window.rs b/packages/wm-platform/src/native_window.rs
index 4973c6d9..f3316013 100644
--- a/packages/wm-platform/src/native_window.rs
+++ b/packages/wm-platform/src/native_window.rs
@@ -1,4 +1,7 @@
+use std::time::Duration;
+
use anyhow::{bail, Context};
+use tokio::task;
use tracing::warn;
use windows::{
core::PWSTR,
@@ -866,23 +869,29 @@ impl NativeWindow {
)
}?;
+ let handle = self.handle;
+
// Z-order can sometimes still be incorrect after the above call.
- unsafe {
- SetWindowPos(
- HWND(self.handle),
- z_order,
- 0,
- 0,
- 0,
- 0,
- SWP_NOACTIVATE
- | SWP_NOCOPYBITS
- | SWP_ASYNCWINDOWPOS
- | SWP_SHOWWINDOW
- | SWP_NOMOVE
- | SWP_NOSIZE,
- )
- }?;
+ task::spawn(async move {
+ tokio::time::sleep(Duration::from_millis(10)).await;
+
+ let _ = unsafe {
+ SetWindowPos(
+ HWND(handle),
+ z_order,
+ 0,
+ 0,
+ 0,
+ 0,
+ SWP_NOACTIVATE
+ | SWP_NOCOPYBITS
+ | SWP_ASYNCWINDOWPOS
+ | SWP_SHOWWINDOW
+ | SWP_NOMOVE
+ | SWP_NOSIZE,
+ )
+ };
+ });
Ok(())
}