GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: add handlers for close, minimize, and maximize commands
Lars Berger89cb8d43f3da
diff --git a/packages/wm/src/common/platform/native_window.rs b/packages/wm/src/common/platform/native_window.rsindex 319fb79c..aa0dc0cc 100644--- a/packages/wm/src/common/platform/native_window.rs+++ b/packages/wm/src/common/platform/native_window.rs@@ -17,14 +17,15 @@ use windows::{WindowsAndMessaging::{EnumWindows, GetClassNameW, GetWindow, GetWindowLongPtrW,GetWindowPlacement, GetWindowTextW, GetWindowThreadProcessId,- IsWindowVisible, SetForegroundWindow, SetWindowPos,- ShowWindowAsync, GWL_EXSTYLE, GWL_STYLE, GW_OWNER, HWND_NOTOPMOST,- HWND_TOPMOST, SWP_ASYNCWINDOWPOS, SWP_FRAMECHANGED,- SWP_HIDEWINDOW, SWP_NOACTIVATE, SWP_NOCOPYBITS, SWP_NOMOVE,- SWP_NOSENDCHANGING, SWP_NOSIZE, SWP_SHOWWINDOW, SW_RESTORE,- WINDOWPLACEMENT, WINDOW_EX_STYLE, WINDOW_STYLE, WS_CAPTION,- WS_CHILD, WS_EX_NOACTIVATE, WS_EX_TOOLWINDOW, WS_MAXIMIZE,- WS_MINIMIZE, WS_THICKFRAME,+ IsWindowVisible, SendNotifyMessageW, SetForegroundWindow,+ SetWindowPos, ShowWindowAsync, GWL_EXSTYLE, GWL_STYLE, GW_OWNER,+ HWND_NOTOPMOST, HWND_TOPMOST, SWP_ASYNCWINDOWPOS,+ SWP_FRAMECHANGED, SWP_HIDEWINDOW, SWP_NOACTIVATE, SWP_NOCOPYBITS,+ SWP_NOMOVE, SWP_NOSENDCHANGING, SWP_NOSIZE, SWP_SHOWWINDOW,+ SW_MAXIMIZE, SW_MINIMIZE, SW_RESTORE, WINDOWPLACEMENT,+ WINDOW_EX_STYLE, WINDOW_STYLE, WM_CLOSE, WS_CAPTION, WS_CHILD,+ WS_EX_NOACTIVATE, WS_EX_TOOLWINDOW, WS_MAXIMIZE, WS_MINIMIZE,+ WS_THICKFRAME,},},},@@ -251,6 +252,21 @@ impl NativeWindow {Ok(())}+ pub fn maximize(&self) -> anyhow::Result<()> {+ unsafe { ShowWindowAsync(self.handle, SW_MAXIMIZE).ok() }?;+ Ok(())+ }++ pub fn minimize(&self) -> anyhow::Result<()> {+ unsafe { ShowWindowAsync(self.handle, SW_MINIMIZE).ok() }?;+ Ok(())+ }++ pub fn close(&self) -> anyhow::Result<()> {+ unsafe { SendNotifyMessageW(self.handle, WM_CLOSE, None, None) }?;+ Ok(())+ }+pub fn set_position(&self,args: &SetPositionArgs,diff --git a/packages/wm/src/main.rs b/packages/wm/src/main.rsindex 36b50914..88392637 100644--- a/packages/wm/src/main.rs+++ b/packages/wm/src/main.rs@@ -4,7 +4,7 @@ use std::{env, ops::DerefMut, path::PathBuf};use anyhow::{Context, Result};use tokio::process::Command;-use tracing::{debug, info};+use tracing::{debug, error, info};use common::platform::Platform;use ipc_server::IpcServer;@@ -76,7 +76,11 @@ async fn start_wm(config_path: Option<PathBuf>) -> Result<()> {tokio::select! {Some(event) = event_listener.event_rx.recv() => {debug!("Received platform event: {:?}", event);- wm.process_event(event, config.deref_mut()).await;+ let res = wm.process_event(event, config.deref_mut()).await;++ if let Err(err) = res {+ error!("Failed to process event: {:?}", err);+ }},Some(ipc_message) = ipc_server.message_rx.recv() => {info!("Received IPC message: {:?}", ipc_message);@@ -84,7 +88,11 @@ async fn start_wm(config_path: Option<PathBuf>) -> Result<()> {},Some(wm_command) = ipc_server.wm_command_rx.recv() => {info!("Received WM command via IPC: {:?}", wm_command);- wm.process_command(wm_command, config.deref_mut()).await;+ let res = wm.process_command(wm_command, config.deref_mut()).await;++ if let Err(err) = res {+ error!("Failed to process command: {:?}", err);+ }},Some(_) = config.changes_rx.recv() => {info!("Received user config update: {:?}", config);diff --git a/packages/wm/src/wm.rs b/packages/wm/src/wm.rsindex 9444b49b..91ec65e9 100644--- a/packages/wm/src/wm.rs+++ b/packages/wm/src/wm.rs@@ -1,11 +1,10 @@use std::{ops::DerefMut, sync::Arc};-use anyhow::Result;+use anyhow::{Context, Result};use tokio::sync::{mpsc::{self},Mutex,};-use tracing::error;use crate::{app_command::InvokeCommand,@@ -16,8 +15,9 @@ use crate::{},platform::PlatformEvent,},- containers::commands::redraw,+ containers::{commands::redraw, traits::CommonGetters},user_config::UserConfig,+ windows::traits::WindowGetters,wm_event::WmEvent,wm_state::WmState,};@@ -45,12 +45,12 @@ impl WindowManager {&mut self,event: PlatformEvent,config: &mut UserConfig,- ) {- let res = match event {+ ) -> anyhow::Result<()> {+ match event {PlatformEvent::DisplaySettingsChanged => Ok(()),PlatformEvent::KeybindingTriggered(kb_config) => {for command in kb_config.commands {- self.process_command(command, config).await;+ self.process_command(command, config).await?;}Ok(())}@@ -80,10 +80,6 @@ impl WindowManager {config,),PlatformEvent::WindowTitleChanged(_) => Ok(()),- };-- if let Err(err) = res {- error!("Failed to process event: {:?}", err);}}@@ -91,12 +87,21 @@ impl WindowManager {&mut self,command: InvokeCommand,config: &mut UserConfig,- ) {+ ) -> anyhow::Result<()> {let mut state = self.state.lock().await;- let res = match command {+ let subject_container = state+ .focused_container()+ .context("No subject container for command.")?;++ match command {InvokeCommand::AdjustBorders(_) => todo!(),- InvokeCommand::Close => todo!(),+ InvokeCommand::Close => {+ if let Ok(window) = subject_container.as_window_container() {+ window.native().close()?+ }+ Ok(())+ }InvokeCommand::Focus(_) => todo!(),InvokeCommand::Ignore => todo!(),InvokeCommand::Move(_) => todo!(),@@ -104,8 +109,18 @@ impl WindowManager {InvokeCommand::Resize(_) => todo!(),InvokeCommand::SetFloating { centered } => todo!(),InvokeCommand::SetFullscreen => todo!(),- InvokeCommand::SetMaximized => todo!(),- InvokeCommand::SetMinimized => todo!(),+ InvokeCommand::SetMaximized => {+ if let Ok(window) = subject_container.as_window_container() {+ window.native().maximize()?+ }+ Ok(())+ }+ InvokeCommand::SetMinimized => {+ if let Ok(window) = subject_container.as_window_container() {+ window.native().minimize()?+ }+ Ok(())+ }InvokeCommand::SetTiling => todo!(),InvokeCommand::ShellExec { command } => todo!(),InvokeCommand::ToggleFloating { centered } => todo!(),@@ -120,10 +135,6 @@ impl WindowManager {InvokeCommand::WmRedraw => redraw(state.deref_mut(), &config),InvokeCommand::WmReloadConfig => todo!(),InvokeCommand::WmToggleFocusMode => todo!(),- };-- if let Err(err) = res {- error!("Failed to process command: {:?}", err);}}}