Skip to content

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

feat: watcher - tracking managed windows for cleanup

holby162252f93c8b
diff --git a/Cargo.lock b/Cargo.lock
index ccd4f917..c0146e49 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1932,6 +1932,7 @@ dependencies = [
"tokio",
"tracing",
"tracing-subscriber",
+ "windows",
"wm",
]
diff --git a/packages/watcher/Cargo.toml b/packages/watcher/Cargo.toml
index 1f49f0f3..44e936ef 100644
--- a/packages/watcher/Cargo.toml
+++ b/packages/watcher/Cargo.toml
@@ -9,6 +9,9 @@ path = "src/main.rs"
[dependencies]
wm = { path = "../wm" }
+windows = { version = "0.52", features = [
+ "Win32_UI_WindowsAndMessaging",
+] }
anyhow = { workspace = true }
tokio = { workspace = true }
diff --git a/packages/watcher/src/main.rs b/packages/watcher/src/main.rs
index 10207b92..df6ff7f6 100644
--- a/packages/watcher/src/main.rs
+++ b/packages/watcher/src/main.rs
@@ -1,6 +1,10 @@
use anyhow::Context;
-
use tracing::info;
+use windows::Win32::{
+ Foundation::HWND,
+ UI::WindowsAndMessaging::{ShowWindowAsync, SW_MINIMIZE},
+};
+
use wm::containers::ContainerDto;
use wm::ipc_client::IpcClient;
use wm::ipc_server::ClientResponseData;
@@ -31,6 +35,8 @@ async fn main() -> anyhow::Result<()> {
})
.context("No subscription ID in watcher event subscription.")?;
+ let mut managed_handles = Vec::new();
+
loop {
let event_data = client
.event_subscription(&subscription_id)
@@ -41,14 +47,14 @@ async fn main() -> anyhow::Result<()> {
Some(WmEvent::WindowManaged { managed_window }) => {
if let ContainerDto::Window(window) = managed_window {
info!("Watcher added handle: {}.", window.handle);
- // TODO: Add handle to list of managed handles.
+ managed_handles.push(window.handle);
}
}
Some(WmEvent::WindowUnmanaged {
unmanaged_handle, ..
}) => {
info!("Watcher removed handle: {}.", unmanaged_handle);
- // TODO: Pop handle from list of managed handles.
+ managed_handles.retain(|&handle| handle != unmanaged_handle);
}
Some(_) => unreachable!(),
None => {
@@ -58,7 +64,15 @@ async fn main() -> anyhow::Result<()> {
}
}
- // TODO: Run shared cleanup fn here.
+ info!(
+ "Cleanup: Remaining managed window handles: {:?}",
+ managed_handles
+ );
+
+ // TODO: create a shared function that the wm can also use for cleanup
+ managed_handles.iter().for_each(|handle| unsafe {
+ ShowWindowAsync(HWND(*handle), SW_MINIMIZE);
+ });
Ok(())
}