diff --git a/komorebi/src/core/mod.rs b/komorebi/src/core/mod.rs index d9bd230c..eeb1b351 100644 --- a/komorebi/src/core/mod.rs +++ b/komorebi/src/core/mod.rs @@ -330,6 +330,7 @@ pub enum StateQuery { FocusedWorkspaceIndex, FocusedContainerIndex, FocusedWindowIndex, + FocusedWorkspaceName, } #[derive( diff --git a/komorebi/src/monitor.rs b/komorebi/src/monitor.rs index d4a151a2..d38ffeb3 100644 --- a/komorebi/src/monitor.rs +++ b/komorebi/src/monitor.rs @@ -107,6 +107,13 @@ impl Monitor { workspace_names: Default::default(), } } + + pub fn focused_workspace_name(&self) -> Option { + self.focused_workspace() + .map(|w| w.name().clone()) + .unwrap_or(None) + } + pub fn load_focused_workspace(&mut self, mouse_follows_focus: bool) -> Result<()> { let focused_idx = self.focused_workspace_idx(); for (i, workspace) in self.workspaces_mut().iter_mut().enumerate() { diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index fc42105e..c9c40204 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -1063,19 +1063,29 @@ impl WindowManager { } SocketMessage::Query(query) => { let response = match query { - StateQuery::FocusedMonitorIndex => self.focused_monitor_idx(), + StateQuery::FocusedMonitorIndex => self.focused_monitor_idx().to_string(), StateQuery::FocusedWorkspaceIndex => self .focused_monitor() .ok_or_else(|| anyhow!("there is no monitor"))? - .focused_workspace_idx(), - StateQuery::FocusedContainerIndex => { - self.focused_workspace()?.focused_container_idx() - } + .focused_workspace_idx() + .to_string(), + StateQuery::FocusedContainerIndex => self + .focused_workspace()? + .focused_container_idx() + .to_string(), StateQuery::FocusedWindowIndex => { - self.focused_container()?.focused_window_idx() + self.focused_container()?.focused_window_idx().to_string() } - } - .to_string(); + StateQuery::FocusedWorkspaceName => { + let focused_monitor = self + .focused_monitor() + .ok_or_else(|| anyhow!("there is no monitor"))?; + + focused_monitor + .focused_workspace_name() + .unwrap_or_else(|| focused_monitor.focused_workspace_idx().to_string()) + } + }; reply.write_all(response.as_bytes())?; }