diff --git a/NEWS.md b/NEWS.md index 1eb81d3..33fcf6f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,7 +3,8 @@ swayr v0.11.0 - New command: `configure-outputs` lets you repeatedly issue output commands until you abort the menu program. - +- Formats can now include a `{output_name}` placeholder which is replaced by + the name of the output containing the shown workspace, container or window. swayr v0.10.0 ============= diff --git a/src/cmds.rs b/src/cmds.rs index c5d0e22..fa82e5e 100644 --- a/src/cmds.rs +++ b/src/cmds.rs @@ -719,7 +719,10 @@ pub fn focus_window_in_direction( if consider_wins == &ConsiderWindows::CurrentWorkspace { let cur_ws = tree.get_current_workspace(); wins.retain(|w| { - tree.get_workspace_node(w.node.id).unwrap().id == cur_ws.id + tree.get_parent_node_of_type(w.node.id, t::Type::Workspace) + .unwrap() + .id + == cur_ws.id }); } diff --git a/src/config.rs b/src/config.rs index c9159c4..d350987 100644 --- a/src/config.rs +++ b/src/config.rs @@ -216,20 +216,23 @@ impl Default for Format { fn default() -> Self { Format { workspace_format: Some( - "{indent}Workspace {name} [{layout}] \ + "{indent}Workspace {name} [{layout}] \ + on output {output_name} \ ({id})" .to_string(), ), container_format: Some( "{indent}Container [{layout}] \ - on workspace {workspace_name} {marks} \ + {marks} \ + on workspace {workspace_name} \ ({id})" .to_string(), ), window_format: Some( "img:{app_icon}:text:{indent}{app_name} — \ {urgency_start}“{title}”{urgency_end} \ - on workspace {workspace_name} {marks} \ + {marks} \ + on workspace {workspace_name} / {output_name} \ ({id})" .to_string(), ), diff --git a/src/tree.rs b/src/tree.rs index 48d97a8..bbe7e00 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -196,12 +196,16 @@ impl<'a> Tree<'a> { self.id_parent.get(&id).map(|pid| self.get_node_by_id(*pid)) } - pub fn get_workspace_node(&self, id: i64) -> Option<&&s::Node> { + pub fn get_parent_node_of_type( + &self, + id: i64, + t: Type, + ) -> Option<&&s::Node> { let n = self.get_node_by_id(id); - if n.get_type() == Type::Workspace { + if n.get_type() == t { Some(n) } else if let Some(pid) = self.id_parent.get(&id) { - self.get_workspace_node(*pid) + self.get_parent_node_of_type(*pid, t) } else { None } @@ -482,12 +486,12 @@ impl DisplayFormat for DisplayNode<'_> { &maybe_html_escape(html_escape, self.node.get_app_name()), ) .replace( - "{workspace_name}", + "{output_name}", &maybe_html_escape( html_escape, self.tree - .get_workspace_node(self.node.id) - .map_or("", |w| w.get_name()), + .get_parent_node_of_type(self.node.id, Type::Output) + .map_or("", |w| w.get_name()), ), ) .replace( @@ -495,7 +499,7 @@ impl DisplayFormat for DisplayNode<'_> { &maybe_html_escape( html_escape, self.tree - .get_workspace_node(self.node.id) + .get_parent_node_of_type(self.node.id, Type::Workspace) .map_or("", |w| w.get_name()), ), )