GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: handle window shown event
Lars Berger356d16a39c9a
diff --git a/packages/ipc-client/src/ipc_message.rs b/packages/ipc-client/src/ipc_message.rsdeleted file mode 100644index e2b99eff..00000000--- a/packages/ipc-client/src/ipc_message.rs+++ /dev/null@@ -1,9 +0,0 @@-// pub enum IpcMessage {-// QueryMonitors,-// QueryWorkspaces,-// QueryWindows,-// QueryFocusedContainer,-// QueryBindingMode,-// InvokeCommand,-// SubscribeEvent,-// }diff --git a/packages/wm/src/app_command.rs b/packages/wm/src/app_command.rsindex 6c8f5071..86576e46 100644--- a/packages/wm/src/app_command.rs+++ b/packages/wm/src/app_command.rs@@ -1,13 +1,10 @@use std::{iter, path::PathBuf};-use clap::{- error::{KindFormatter, RichFormatter},- Args, Command, CommandFactory, Parser, Subcommand,-};+use clap::{error::KindFormatter, Args, Parser};use serde::{Deserialize, Deserializer};use tracing::Level;-use crate::common::{Direction, LengthValue, TilingDirection};+use crate::common::{Direction, LengthValue};#[derive(Clone, Debug, Parser)]#[clap(author, version, about, long_about = None)]diff --git a/packages/wm/src/common/events/handle_window_shown.rs b/packages/wm/src/common/events/handle_window_shown.rsnew file mode 100644index 00000000..ce09fcae--- /dev/null+++ b/packages/wm/src/common/events/handle_window_shown.rs@@ -0,0 +1,44 @@+use tracing::info;++use crate::{+ common::{+ commands::sync_native_focus, platform::NativeWindow, DisplayState,+ },+ containers::commands::redraw,+ user_config::UserConfig,+ windows::{commands::manage_window, traits::WindowGetters},+ wm_state::WmState,+};++pub fn handle_window_shown(+ native_window: NativeWindow,+ state: &mut WmState,+ config: &UserConfig,+) -> anyhow::Result<()> {+ // TODO: Refresh monitor state.+ if native_window.is_app_bar() {+ state.app_bar_windows.push(native_window);+ return Ok(());+ }++ let found_window = state.window_from_native(&native_window);++ // Manage the window if it's manageable.+ if found_window.is_none() && native_window.is_manageable() {+ manage_window(native_window, None, state, config)?;+ redraw(state, config)?;+ sync_native_focus(state)?;+ return Ok(());+ }++ if let Some(window) = found_window {+ // TODO: Log window details.+ info!("Showing window");++ // Update display state if window is already managed.+ if window.display_state() == DisplayState::Showing {+ window.set_display_state(DisplayState::Shown);+ }+ }+ Ok(())+}diff --git a/packages/wm/src/common/events/mod.rs b/packages/wm/src/common/events/mod.rsnew file mode 100644index 00000000..feb78d5e--- /dev/null+++ b/packages/wm/src/common/events/mod.rs@@ -0,0 +1,3 @@+mod handle_window_shown;++pub use handle_window_shown::*;diff --git a/packages/wm/src/common/mod.rs b/packages/wm/src/common/mod.rsindex 7469602e..fb9b235c 100644--- a/packages/wm/src/common/mod.rs+++ b/packages/wm/src/common/mod.rs@@ -1,6 +1,7 @@pub mod commands;mod direction;mod display_state;+pub mod events;mod focus_mode;pub mod platform;mod rect;diff --git a/packages/wm/src/common/platform/native_window.rs b/packages/wm/src/common/platform/native_window.rsindex 355bf8db..319fb79c 100644--- a/packages/wm/src/common/platform/native_window.rs+++ b/packages/wm/src/common/platform/native_window.rs@@ -196,7 +196,8 @@ impl NativeWindow {}pub fn is_app_bar(&self) -> bool {- todo!()+ // TODO+ false}pub fn set_foreground(&self) -> anyhow::Result<()> {diff --git a/packages/wm/src/ipc_server.rs b/packages/wm/src/ipc_server.rsindex bfd9fa86..7946bd11 100644--- a/packages/wm/src/ipc_server.rs+++ b/packages/wm/src/ipc_server.rs@@ -15,25 +15,19 @@ use tokio_tungstenite::accept_async;use tracing::info;use crate::{- app_command::InvokeCommand, wm_event::WmEvent, wm_state::WmState,+ app_command::{AppCommand, InvokeCommand},+ wm_event::WmEvent,+ wm_state::WmState,};-#[derive(Debug)]-pub enum IpcMessage {- Monitors,- Windows,- InvokeCommand,- Subscribe,-}-pub struct IpcServer {- pub message_rx: mpsc::UnboundedReceiver<IpcMessage>,+ pub message_rx: mpsc::UnboundedReceiver<AppCommand>,pub wm_command_rx: mpsc::UnboundedReceiver<InvokeCommand>,}impl IpcServer {pub async fn start() -> Result<Self> {- let (message_tx, message_rx) = mpsc::unbounded_channel::<IpcMessage>();+ let (message_tx, message_rx) = mpsc::unbounded_channel::<AppCommand>();let (wm_command_tx, wm_command_rx) =mpsc::unbounded_channel::<InvokeCommand>();@@ -66,7 +60,7 @@ impl IpcServer {pub async fn process_message(&self,- _message: IpcMessage,+ _message: AppCommand,wm_state: Arc<Mutex<WmState>>,) {// TODO: Spawn a task so that it doesn't block main thread execution.diff --git a/packages/wm/src/main.rs b/packages/wm/src/main.rsindex 3d2582f4..a9a6707e 100644--- a/packages/wm/src/main.rs+++ b/packages/wm/src/main.rs@@ -77,7 +77,7 @@ async fn start_wm(config_path: Option<PathBuf>) -> Result<()> {tokio::select! {Some(event) = event_listener.event_rx.recv() => {info!("Received platform event: {:?}", event);- wm.process_event(event).await+ let _ = wm.process_event(event, config.deref_mut()).await;},Some(wm_event) = wm.event_rx.recv() => {info!("Received WM event: {:?}", wm_event);diff --git a/packages/wm/src/wm.rs b/packages/wm/src/wm.rsindex b1b62803..911dad86 100644--- a/packages/wm/src/wm.rs+++ b/packages/wm/src/wm.rs@@ -10,9 +10,12 @@ use tokio::sync::{};use crate::{- app_command::InvokeCommand, common::platform::PlatformEvent,- containers::commands::redraw, user_config::UserConfig,- wm_event::WmEvent, wm_state::WmState,+ app_command::InvokeCommand,+ common::{events::handle_window_shown, platform::PlatformEvent},+ containers::commands::redraw,+ user_config::UserConfig,+ wm_event::WmEvent,+ wm_state::WmState,};pub struct WindowManager {@@ -34,8 +37,29 @@ impl WindowManager {})}- pub async fn process_event(&mut self, event: PlatformEvent) {- // TODO+ pub async fn process_event(+ &mut self,+ event: PlatformEvent,+ config: &mut UserConfig,+ ) -> anyhow::Result<()> {+ let mut state = self.state.lock().await;++ match event {+ PlatformEvent::DisplaySettingsChanged => Ok(()),+ PlatformEvent::KeybindingTriggered(_) => Ok(()),+ PlatformEvent::MouseMove => Ok(()),+ PlatformEvent::WindowDestroyed(_) => Ok(()),+ PlatformEvent::WindowFocused(_) => Ok(()),+ PlatformEvent::WindowHidden(_) => Ok(()),+ PlatformEvent::WindowLocationChanged(_) => Ok(()),+ PlatformEvent::WindowMinimized(_) => Ok(()),+ PlatformEvent::WindowMinimizeEnded(_) => Ok(()),+ PlatformEvent::WindowMovedOrResized(_) => Ok(()),+ PlatformEvent::WindowShown(w) => {+ handle_window_shown(w, state.deref_mut(), config)+ }+ PlatformEvent::WindowTitleChanged(_) => Ok(()),+ }}pub async fn process_command(diff --git a/packages/wm/src/wm_state.rs b/packages/wm/src/wm_state.rsindex e0f3a25f..19c68d9c 100644--- a/packages/wm/src/wm_state.rs+++ b/packages/wm/src/wm_state.rs@@ -36,6 +36,11 @@ pub struct WmState {/// Names of any currently enabled binding modes.pub binding_modes: Vec<String>,+ /// Any appbar windows (application desktop toolbars) that have been+ /// detected. Positioning changes of appbars can affect the working area+ /// of the parent monitor, and requires windows to be redrawn.+ pub app_bar_windows: Vec<NativeWindow>,+/// Sender for emitting WM-related events.event_tx: mpsc::UnboundedSender<WmEvent>,}@@ -47,6 +52,7 @@ impl WmState {containers_to_redraw: Vec::new(),has_pending_focus_sync: false,binding_modes: Vec::new(),+ app_bar_windows: Vec::new(),event_tx,}}@@ -64,6 +70,11 @@ impl WmState {}for native_window in Platform::manageable_windows()? {+ // Register appbar windows.+ if native_window.is_app_bar() {+ self.app_bar_windows.push(native_window.clone());+ }+let nearest_workspace = self.nearest_monitor(&native_window).and_then(|m| m.displayed_workspace());