GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: add channel for wm commands from ipc
Lars Berger3912df08e8dd
diff --git a/packages/wm/src/ipc_server.rs b/packages/wm/src/ipc_server.rsindex d170b16e..8dbe5d1c 100644--- a/packages/wm/src/ipc_server.rs+++ b/packages/wm/src/ipc_server.rs@@ -13,7 +13,7 @@ use tokio::{use tokio_tungstenite::accept_async;use tracing::info;-use crate::{wm_event::WmEvent, wm_state::WmState};+use crate::{wm_command::WmCommand, wm_event::WmEvent, wm_state::WmState};#[derive(Debug)]pub enum IpcMessage {@@ -24,14 +24,17 @@ pub enum IpcMessage {}pub struct IpcServer {- message_tx: UnboundedSender<IpcMessage>,pub message_rx: UnboundedReceiver<IpcMessage>,+ pub wm_command_rx: UnboundedReceiver<WmCommand>,}impl IpcServer {pub async fn start() -> Result<Self> {let (message_tx, message_rx) = mpsc::unbounded_channel::<IpcMessage>();+ let (wm_command_tx, wm_command_rx) =+ mpsc::unbounded_channel::<WmCommand>();+let server = TcpListener::bind(DEFAULT_IPC_ADDR).await?;while let Ok((stream, _)) = server.accept().await {@@ -47,8 +50,8 @@ impl IpcServer {}Ok(Self {- message_tx,message_rx,+ wm_command_rx,})}diff --git a/packages/wm/src/main.rs b/packages/wm/src/main.rsindex b12aef63..e1034d08 100644--- a/packages/wm/src/main.rs+++ b/packages/wm/src/main.rs@@ -2,7 +2,7 @@ use std::{env, sync::Arc};use anyhow::{Context, Result};use clap::Parser;-use common::platform::{EventListener, Platform};+use common::platform::Platform;use ipc_client::IpcClient;use ipc_server::IpcServer;@@ -71,7 +71,6 @@ async fn start_wm(config_path: Option<String>) -> Result<()> {loop {let wm_state = wm.state.clone();- // let wm_state = wm.state.clone().lock().await;tokio::select! {Some(event) = event_listener.event_rx.recv() => {@@ -89,6 +88,10 @@ async fn start_wm(config_path: Option<String>) -> Result<()> {info!("Received IPC message: {:?}", ipc_message);ipc_server.process_message(ipc_message, wm_state).await},+ Some(wm_command) = ipc_server.wm_command_rx.recv() => {+ info!("Received WM command via IPC: {:?}", wm_command);+ wm.process_command(wm_command).await+ },}}}diff --git a/packages/wm/src/wm.rs b/packages/wm/src/wm.rsindex a142ff0d..00efacea 100644--- a/packages/wm/src/wm.rs+++ b/packages/wm/src/wm.rs@@ -8,7 +8,8 @@ use tokio::sync::{use wineventhook::WindowEvent;use crate::{- user_config::UserConfig, wm_event::WmEvent, wm_state::WmState,+ user_config::UserConfig, wm_command::WmCommand, wm_event::WmEvent,+ wm_state::WmState,};pub struct WindowManager {@@ -25,11 +26,19 @@ impl WindowManager {Ok(Self {event_rx,- state: Arc::new(Mutex::new(WmState::new(config))),+ state: Arc::new(Mutex::new(WmState::new(+ config,+ config_changes_tx,+ event_tx,+ ))),})}pub async fn process_event(&mut self, event: WindowEvent) {todo!()}++ pub async fn process_command(&mut self, command: WmCommand) {+ todo!()+ }}diff --git a/packages/wm/src/wm_state.rs b/packages/wm/src/wm_state.rsindex 17a505f1..52a09d38 100644--- a/packages/wm/src/wm_state.rs+++ b/packages/wm/src/wm_state.rs@@ -5,7 +5,8 @@ use std::{sync::Arc,};-use tokio::sync::Mutex;+use anyhow::Result;+use tokio::sync::{mpsc::UnboundedSender, Mutex};use uuid::Uuid;use crate::{@@ -13,6 +14,7 @@ use crate::{containers::{Container, ContainerType, RootContainer},monitors::Monitor,user_config::{BindingModeConfig, UserConfig},+ wm_event::WmEvent,};pub struct WmState {@@ -32,16 +34,26 @@ pub struct WmState {/// Parsed user config.config: Arc<Mutex<UserConfig>>,++ config_changes_tx: UnboundedSender<UserConfig>,++ event_tx: UnboundedSender<WmEvent>,}impl WmState {- pub fn new(config: Arc<Mutex<UserConfig>>) -> Self {+ pub fn new(+ config: Arc<Mutex<UserConfig>>,+ config_changes_tx: UnboundedSender<UserConfig>,+ event_tx: UnboundedSender<WmEvent>,+ ) -> Self {Self {root_container: RootContainer::new(),containers_to_redraw: Vec::new(),has_pending_focus_sync: false,binding_modes: Vec::new(),config,+ config_changes_tx,+ event_tx,}}@@ -56,6 +68,10 @@ impl WmState {.push_front(Rc::new(RefCell::new(Container::Monitor(monitor))));}+ pub fn emit_event(&self, event: WmEvent) -> Result<()> {+ self.event_tx.send(event)+ }+// Get the currently focused container. This can either be a `Window` or// a `Workspace` without any descendant windows.// pub fn focused_container(&self) -> Arc<Container> {