A bit refactoring

timeout_old
Tassilo Horn 3 years ago
parent 360f8cd90d
commit 64052993d4
  1. 2
      src/cmds.rs
  2. 23
      src/con.rs
  3. 14
      src/config.rs
  4. 2
      src/layout.rs

@ -635,7 +635,7 @@ pub fn quit_workspace_or_window(extra_props: &HashMap<i64, con::ExtraProps>) {
{ {
match ws_or_win { match ws_or_win {
con::WsOrWin::Ws { ws } => { con::WsOrWin::Ws { ws } => {
for win in &ws.windows { for win in ws.get_windows() {
quit_window_by_id(win.get_id()) quit_window_by_id(win.get_id())
} }
} }

@ -69,9 +69,13 @@ pub trait NodeMethods {
/// Returns all nodes being application windows. /// Returns all nodes being application windows.
fn windows(&self) -> Vec<&s::Node>; fn windows(&self) -> Vec<&s::Node>;
/// Returns all nodes being containers.
fn containers(&self) -> Vec<&s::Node>;
/// Returns all nodes being workspaces. /// Returns all nodes being workspaces.
fn workspaces(&self) -> Vec<&s::Node>; fn workspaces(&self) -> Vec<&s::Node>;
// Returns true if this node is the scratchpad workspace.
fn is_scratchpad(&self) -> bool; fn is_scratchpad(&self) -> bool;
} }
@ -87,16 +91,19 @@ impl NodeMethods for s::Node {
} }
fn is_container(&self) -> bool { fn is_container(&self) -> bool {
self.node_type == s::NodeType::Workspace self.node_type == s::NodeType::Con
|| self.node_type == s::NodeType::Con && self.name.is_none()
&& self.name.is_none() && self.layout != s::NodeLayout::None
&& self.layout != s::NodeLayout::None
} }
fn windows(&self) -> Vec<&s::Node> { fn windows(&self) -> Vec<&s::Node> {
self.iter().filter(|n| n.is_window()).collect() 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> { fn workspaces(&self) -> Vec<&s::Node> {
self.iter() self.iter()
.filter(|n| n.node_type == s::NodeType::Workspace) .filter(|n| n.node_type == s::NodeType::Workspace)
@ -439,10 +446,18 @@ impl Workspace<'_> {
self.node.id self.node.id
} }
pub fn get_windows(&self) -> &Vec<Window> {
&self.windows
}
pub fn is_scratchpad(&self) -> bool { pub fn is_scratchpad(&self) -> bool {
self.node.is_scratchpad() self.node.is_scratchpad()
} }
pub fn is_focused(&self) -> bool {
self.node.focused
}
pub fn is_current(&self) -> bool { pub fn is_current(&self) -> bool {
is_current_container(self.node) is_current_container(self.node)
} }

@ -79,6 +79,14 @@ impl Config {
.expect("No format.workspace_format defined.") .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 { pub fn get_format_urgency_start(&self) -> String {
self.format self.format
.as_ref() .as_ref()
@ -147,6 +155,7 @@ pub struct Menu {
pub struct Format { pub struct Format {
window_format: Option<String>, window_format: Option<String>,
workspace_format: Option<String>, workspace_format: Option<String>,
container_format: Option<String>,
urgency_start: Option<String>, urgency_start: Option<String>,
urgency_end: Option<String>, urgency_end: Option<String>,
html_escape: Option<bool>, html_escape: Option<bool>,
@ -207,6 +216,11 @@ impl Default for Format {
<span alpha=\"20000\">({id})</span>" <span alpha=\"20000\">({id})</span>"
.to_string(), .to_string(),
), ),
container_format: Some(
"<i>Container {name}</i> \
<span alpha=\"20000\">({id})</span>"
.to_string(),
),
html_escape: Some(true), html_escape: Some(true),
urgency_start: Some( urgency_start: Some(
"<span background=\"darkred\" foreground=\"yellow\">" "<span background=\"darkred\" foreground=\"yellow\">"

@ -139,7 +139,7 @@ pub fn relayout_current_workspace(
if let Ok(mut con) = s::Connection::new() { if let Ok(mut con) = s::Connection::new() {
let mut moved_wins: Vec<&con::Window> = vec![]; let mut moved_wins: Vec<&con::Window> = vec![];
let mut focused_win = None; let mut focused_win = None;
for win in &cur_ws.windows { for win in cur_ws.get_windows() {
if win.is_focused() { if win.is_focused() {
focused_win = Some(win); focused_win = Some(win);
} }

Loading…
Cancel
Save