Skip to content

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

feat: use subject container ID when processing command

Lars Berger65bea176c4ff
diff --git a/packages/wm/src/ipc_server.rs b/packages/wm/src/ipc_server.rs
index 2a6a19f9..2643eae9 100644
--- a/packages/wm/src/ipc_server.rs
+++ b/packages/wm/src/ipc_server.rs
@@ -23,7 +23,8 @@ use crate::{
pub struct IpcServer {
pub message_rx: mpsc::UnboundedReceiver<AppCommand>,
- pub wm_command_rx: mpsc::UnboundedReceiver<(InvokeCommand, Uuid)>,
+ pub wm_command_rx:
+ mpsc::UnboundedReceiver<(InvokeCommand, Option<Uuid>)>,
}
impl IpcServer {
diff --git a/packages/wm/src/main.rs b/packages/wm/src/main.rs
index 0dd3a88d..e7834d00 100644
--- a/packages/wm/src/main.rs
+++ b/packages/wm/src/main.rs
@@ -76,7 +76,7 @@ async fn start_wm(config_path: Option<PathBuf>) -> Result<()> {
tokio::select! {
Some(event) = event_listener.event_rx.recv() => {
debug!("Received platform event: {:?}", event);
- let res = wm.process_event(event, config.deref_mut()).await;
+ let res = wm.process_event(event, &mut config).await;
if let Err(err) = res {
error!("Failed to process event: {:?}", err);
@@ -88,9 +88,8 @@ 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);
- // TODO: Pass the UUID for the subject container.
- let (command, _) = wm_command;
- let res = wm.process_command(command, config.deref_mut()).await;
+ let (command, subject_container_id) = wm_command;
+ let res = wm.process_command(command, subject_container_id, &mut config).await;
if let Err(err) = res {
error!("Failed to process command: {:?}", err);
diff --git a/packages/wm/src/wm.rs b/packages/wm/src/wm.rs
index 5fccaf91..a8c74a0d 100644
--- a/packages/wm/src/wm.rs
+++ b/packages/wm/src/wm.rs
@@ -1,10 +1,11 @@
-use std::{ops::DerefMut, sync::Arc};
+use std::sync::Arc;
use anyhow::{bail, Context, Result};
use tokio::sync::{
mpsc::{self},
Mutex,
};
+use uuid::Uuid;
use crate::{
app_command::InvokeCommand,
@@ -55,7 +56,7 @@ impl WindowManager {
drop(state);
for command in kb_config.commands {
// TODO: Postpone redraw + focus sync till after all commands are run.
- self.process_command(command, config).await?;
+ self.process_command(command, None, config).await?;
}
return Ok(());
}
@@ -88,16 +89,19 @@ impl WindowManager {
pub async fn process_command(
&mut self,
command: InvokeCommand,
+ subject_container_id: Option<Uuid>,
config: &mut UserConfig,
) -> anyhow::Result<()> {
let mut state = self.state.lock().await;
- let subject_container = state
- .focused_container()
+ let subject_container = subject_container_id
+ .map(|id| state.container_by_id(id))
+ .context("No container found with the given ID.")?
+ .or_else(|| state.focused_container())
.context("No subject container for command.")?;
if subject_container.is_detached() {
- bail!("Subject container is detached.");
+ bail!("Cannot run command because subject container is detached.");
}
match command {
@@ -172,9 +176,9 @@ impl WindowManager {
InvokeCommand::WmExit => todo!(),
InvokeCommand::WmEnableBindingMode { name } => todo!(),
InvokeCommand::WmRedraw => {
- let state = state.deref_mut();
- state.add_container_to_redraw(state.root_container.clone().into());
- redraw(state, &config)
+ let root_container = state.root_container.clone();
+ state.add_container_to_redraw(root_container.into());
+ Ok(())
}
InvokeCommand::WmReloadConfig => todo!(),
InvokeCommand::WmToggleFocusMode => todo!(),