mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-21 08:59:11 +01:00
feat(cli): add focused-workspace-name query
This commit adds the StateQuery::FocusedWorkspaceName variant to allow users to query the name of the focused workspace via the komorebic query command. re #1238
This commit is contained in:
@@ -330,6 +330,7 @@ pub enum StateQuery {
|
||||
FocusedWorkspaceIndex,
|
||||
FocusedContainerIndex,
|
||||
FocusedWindowIndex,
|
||||
FocusedWorkspaceName,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
|
||||
@@ -107,6 +107,13 @@ impl Monitor {
|
||||
workspace_names: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn focused_workspace_name(&self) -> Option<String> {
|
||||
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() {
|
||||
|
||||
@@ -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())?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user