aboutsummaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-09-02 09:20:23 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2024-09-01 23:47:19 -0700
commitf7181fb066e6390d516dfb4ee39e5812efad6f59 (patch)
tree782630e468dc2d8f2e4b3f9da17184e80d08d434 /src/layout
parent17ac52e1d4c28efa205d38b134bb1f32c43f9d50 (diff)
downloadniri-f7181fb066e6390d516dfb4ee39e5812efad6f59.tar.gz
niri-f7181fb066e6390d516dfb4ee39e5812efad6f59.tar.bz2
niri-f7181fb066e6390d516dfb4ee39e5812efad6f59.zip
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.
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/mod.rs26
-rw-r--r--src/layout/workspace.rs4
2 files changed, 30 insertions, 0 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 20c63d28..9a9e084d 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -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, .. } => {
diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs
index 26d6a785..f85ec622 100644
--- a/src/layout/workspace.rs
+++ b/src/layout/workspace.rs
@@ -133,6 +133,10 @@ impl WorkspaceId {
pub fn get(self) -> u64 {
self.0
}
+
+ pub fn specific(id: u64) -> Self {
+ Self(id)
+ }
}
niri_render_elements! {