GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: watcher (WIP)
holby56c9cb267bcf
diff --git a/Cargo.lock b/Cargo.lockindex cfd0f4b6..16cfe356 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1928,6 +1928,7 @@ name = "watcher"version = "0.0.0"dependencies = ["anyhow",+ "serde_json","tokio","wm",]diff --git a/packages/watcher/Cargo.toml b/packages/watcher/Cargo.tomlindex 0d1919df..b198d085 100644--- a/packages/watcher/Cargo.toml+++ b/packages/watcher/Cargo.toml@@ -12,3 +12,4 @@ wm = { path = "../wm" }anyhow = { workspace = true }tokio = { workspace = true }+serde_json = "1.0.117"diff --git a/packages/watcher/src/main.rs b/packages/watcher/src/main.rsindex 5a5f5400..eb6afef2 100644--- a/packages/watcher/src/main.rs+++ b/packages/watcher/src/main.rs@@ -1,23 +1,55 @@+use anyhow::Context;+use wm::ipc_client::IpcClient;-use wm::user_config::UserConfig;+use wm::ipc_server::{ClientResponseData, ServerMessage};#[tokio::main]-async fn main() {- let config = UserConfig::new(None).await.unwrap();- match IpcClient::connect().await {- Ok(mut client) => {- loop {- client.send("Watcher process | PING").await.unwrap();- tokio::time::sleep(std::time::Duration::from_secs(1)).await;- }- },- Err(e) => {- eprintln!("Failed to connect to IPC server: {:?}", e);- loop {- tokio::time::sleep(std::time::Duration::from_secs(1)).await;+async fn main() -> anyhow::Result<()> {+ let mut client = IpcClient::connect().await?;++ let subscription_message =+ "subscribe -e window_managed window_unmanaged";++ client+ .send(&subscription_message)+ .await+ .context("Failed to send command to IPC server.")?;++ let client_response = client+ .client_response(&subscription_message)+ .await+ .context("Failed to receive response from IPC server.")?;++ match listen_events(&mut client, &client_response).await {+ Ok(_) => {}+ Err(err) => eprintln!("{}", err),+ }++ Ok(())+}++async fn listen_events(+ ipc_client: &mut IpcClient,+ client_response: &ServerMessage,+) -> anyhow::Result<()> {+ if let ServerMessage::ClientResponse(client_response) = client_response {+ match &client_response.data {+ // For event subscriptions, omit the initial response message and+ // continuously output subsequent event messages.+ Some(ClientResponseData::EventSubscribe(data)) => loop {+ let event_subscription = ipc_client+ .event_subscription(&data.subscription_id)+ .await+ .context("Failed to receive response from IPC server.")?;++ println!("{}", serde_json::to_string(&event_subscription)?);+ },+ // For all other messages, output and exit when the first response+ // message is received.+ _ => {+ println!("{}", serde_json::to_string(&client_response)?);}}}-- println!("config: {:?}", config);+ Ok(())}