From 64052993d42b228799916fe6847c84ed2a884cee Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Fri, 5 Nov 2021 22:15:23 +0100 Subject: [PATCH] A bit refactoring --- src/cmds.rs | 2 +- src/con.rs | 23 +++++++++++++++++++---- src/config.rs | 14 ++++++++++++++ src/layout.rs | 2 +- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/cmds.rs b/src/cmds.rs index f0304e2..71496b9 100644 --- a/src/cmds.rs +++ b/src/cmds.rs @@ -635,7 +635,7 @@ pub fn quit_workspace_or_window(extra_props: &HashMap) { { match ws_or_win { con::WsOrWin::Ws { ws } => { - for win in &ws.windows { + for win in ws.get_windows() { quit_window_by_id(win.get_id()) } } diff --git a/src/con.rs b/src/con.rs index 8f64aa1..465696e 100644 --- a/src/con.rs +++ b/src/con.rs @@ -69,9 +69,13 @@ pub trait NodeMethods { /// Returns all nodes being application windows. fn windows(&self) -> Vec<&s::Node>; + /// Returns all nodes being containers. + fn containers(&self) -> Vec<&s::Node>; + /// Returns all nodes being workspaces. fn workspaces(&self) -> Vec<&s::Node>; + // Returns true if this node is the scratchpad workspace. fn is_scratchpad(&self) -> bool; } @@ -87,16 +91,19 @@ impl NodeMethods for s::Node { } fn is_container(&self) -> bool { - self.node_type == s::NodeType::Workspace - || self.node_type == s::NodeType::Con - && self.name.is_none() - && self.layout != s::NodeLayout::None + self.node_type == s::NodeType::Con + && self.name.is_none() + && self.layout != s::NodeLayout::None } fn windows(&self) -> Vec<&s::Node> { self.iter().filter(|n| n.is_window()).collect() } + fn containers(&self) -> Vec<&s::Node> { + self.iter().filter(|n| n.is_container()).collect() + } + fn workspaces(&self) -> Vec<&s::Node> { self.iter() .filter(|n| n.node_type == s::NodeType::Workspace) @@ -439,10 +446,18 @@ impl Workspace<'_> { self.node.id } + pub fn get_windows(&self) -> &Vec { + &self.windows + } + pub fn is_scratchpad(&self) -> bool { self.node.is_scratchpad() } + pub fn is_focused(&self) -> bool { + self.node.focused + } + pub fn is_current(&self) -> bool { is_current_container(self.node) } diff --git a/src/config.rs b/src/config.rs index 3ad532e..8c6d961 100644 --- a/src/config.rs +++ b/src/config.rs @@ -79,6 +79,14 @@ impl Config { .expect("No format.workspace_format defined.") } + pub fn get_format_container_format(&self) -> String { + self.format + .as_ref() + .and_then(|f| f.container_format.clone()) + .or_else(|| Format::default().container_format) + .expect("No format.container_format defined.") + } + pub fn get_format_urgency_start(&self) -> String { self.format .as_ref() @@ -147,6 +155,7 @@ pub struct Menu { pub struct Format { window_format: Option, workspace_format: Option, + container_format: Option, urgency_start: Option, urgency_end: Option, html_escape: Option, @@ -207,6 +216,11 @@ impl Default for Format { ({id})" .to_string(), ), + container_format: Some( + "Container {name} \ + ({id})" + .to_string(), + ), html_escape: Some(true), urgency_start: Some( "" diff --git a/src/layout.rs b/src/layout.rs index 18c3757..2daf9c5 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -139,7 +139,7 @@ pub fn relayout_current_workspace( if let Ok(mut con) = s::Connection::new() { let mut moved_wins: Vec<&con::Window> = vec![]; let mut focused_win = None; - for win in &cur_ws.windows { + for win in cur_ws.get_windows() { if win.is_focused() { focused_win = Some(win); }