Implement by-id workspace action addressing

It's not added to clap because there's no convenient mutually-exclusive
argument enum derive yet (to have either the current <REFERENCE> or an
--id <ID>). It's not added to config parsing because I don't see how it
could be useful there. As such, it's only accessible through raw IPC.
This commit is contained in:
Ivan Molodetskikh
2024-09-02 09:20:23 +03:00
parent 17ac52e1d4
commit f7181fb066
5 changed files with 42 additions and 6 deletions
+26
View File
@@ -836,6 +836,32 @@ impl<W: LayoutElement> Layout<W> {
None
}
pub fn find_workspace_by_id(&self, id: WorkspaceId) -> Option<(usize, &Workspace<W>)> {
match &self.monitor_set {
MonitorSet::Normal { ref monitors, .. } => {
for mon in monitors {
if let Some((index, workspace)) = mon
.workspaces
.iter()
.enumerate()
.find(|(_, w)| w.id() == id)
{
return Some((index, workspace));
}
}
}
MonitorSet::NoOutputs { workspaces } => {
if let Some((index, workspace)) =
workspaces.iter().enumerate().find(|(_, w)| w.id() == id)
{
return Some((index, workspace));
}
}
}
None
}
pub fn find_workspace_by_name(&self, workspace_name: &str) -> Option<(usize, &Workspace<W>)> {
match &self.monitor_set {
MonitorSet::Normal { ref monitors, .. } => {