Skip to content

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

feat: add client message to ipc response

Lars Berger98bafa83a969
diff --git a/packages/watcher/src/main.rs b/packages/watcher/src/main.rs
index 44726e02..1aadfb24 100644
--- a/packages/watcher/src/main.rs
+++ b/packages/watcher/src/main.rs
@@ -3,6 +3,5 @@ use wm::user_config::UserConfig;
#[tokio::main]
async fn main() {
let config = UserConfig::read(None).await.unwrap();
- let config = config.lock().await;
- println!("config: {:?}", *config);
+ println!("config: {:?}", config);
}
diff --git a/packages/wm/src/ipc_server.rs b/packages/wm/src/ipc_server.rs
index 9fe5cec4..55d339f6 100644
--- a/packages/wm/src/ipc_server.rs
+++ b/packages/wm/src/ipc_server.rs
@@ -50,6 +50,7 @@ pub enum ClientResponseData {
Workspaces(Vec<Workspace>),
BindingModes(Vec<String>),
Focused(Option<Container>),
+ Command,
}
#[derive(Debug, Serialize)]
@@ -69,7 +70,7 @@ struct EventSubscription {
pub struct IpcServer {
pub message_rx:
- mpsc::UnboundedReceiver<(AppCommand, mpsc::UnboundedSender<Message>)>,
+ mpsc::UnboundedReceiver<(String, mpsc::UnboundedSender<Message>)>,
pub wm_command_rx:
mpsc::UnboundedReceiver<(InvokeCommand, Option<Uuid>)>,
pub wm_command_tx: mpsc::UnboundedSender<(InvokeCommand, Option<Uuid>)>,
@@ -123,7 +124,7 @@ impl IpcServer {
addr: SocketAddr,
event_subs: Arc<Mutex<HashMap<Uuid, EventSubscription>>>,
message_tx: mpsc::UnboundedSender<(
- AppCommand,
+ String,
mpsc::UnboundedSender<Message>,
)>,
) -> anyhow::Result<()> {
@@ -144,15 +145,11 @@ impl IpcServer {
break;
}
}
- msg = incoming.next() => {
- let msg = msg.unwrap().context("Error reading next websocket message.")?;
+ message = incoming.next() => {
+ let message = message.unwrap().context("Could not read next websocket message.")?;
- if msg.is_text() || msg.is_binary() {
- let split_msg =
- iter::once("").chain(msg.to_text()?.split_whitespace());
-
- let app_command = AppCommand::try_parse_from(split_msg)?;
- message_tx.send((app_command, response_tx.clone()))?;
+ if message.is_text() || message.is_binary() {
+ message_tx.send((message.to_text()?.to_owned(), response_tx.clone()))?;
}
}
}
@@ -176,10 +173,14 @@ impl IpcServer {
pub async fn process_message(
&self,
- app_command: AppCommand,
+ message: String,
response_tx: mpsc::UnboundedSender<Message>,
state: &mut WmState,
) -> anyhow::Result<()> {
+ let app_command = AppCommand::try_parse_from(
+ iter::once("").chain(message.split_whitespace()),
+ )?;
+
// TODO: Handle subscribe messages.
let response = match app_command {
AppCommand::Query { command } => match command {
@@ -206,10 +207,7 @@ impl IpcServer {
.wm_command_tx
.send((command, context_container_id))
.map_err(|_| anyhow::anyhow!("Failed to send WM command."))
- .and_then(|_| {
- // TODO: Add a proper response type for command execution.
- Ok(ClientResponseData::Focused(state.focused_container()))
- }),
+ .and_then(|_| Ok(ClientResponseData::Command)),
_ => Err(anyhow::anyhow!("Unsupported IPC command.")),
};
@@ -217,7 +215,7 @@ impl IpcServer {
let success = response.as_ref().is_ok();
let response = ClientResponseMessage {
- client_message: "TODO".to_string(),
+ client_message: message,
data: response.ok(),
error,
success,
diff --git a/packages/wm/src/main.rs b/packages/wm/src/main.rs
index 002a5f82..fdc64696 100644
--- a/packages/wm/src/main.rs
+++ b/packages/wm/src/main.rs
@@ -99,9 +99,9 @@ async fn start_wm(
error!("Failed to process event: {:?}", err);
}
},
- Some((app_command, response_tx)) = ipc_server.message_rx.recv() => {
- info!("Received IPC message: {:?}", app_command);
- ipc_server.process_message(app_command, response_tx, &mut wm.state).await;
+ Some((message, response_tx)) = ipc_server.message_rx.recv() => {
+ info!("Received IPC message: {:?}", message);
+ ipc_server.process_message(message, response_tx, &mut wm.state).await;
},
Some((command, subject_container_id)) = ipc_server.wm_command_rx.recv() => {
info!("Received WM command via IPC: {:?}", command);