From fdcb1a0bf408742b60b7e559d8b12713b966b0e6 Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Wed, 17 Feb 2021 22:01:33 +0100 Subject: [PATCH] scratchpad windows aren't considered in next-/prev-window fixes #1 --- src/cmds.rs | 17 +++++++++-------- src/con.rs | 26 +++++++++++++++----------- src/ipc.rs | 6 ++++++ 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/cmds.rs b/src/cmds.rs index c71f6c6..c1e46f5 100644 --- a/src/cmds.rs +++ b/src/cmds.rs @@ -91,7 +91,7 @@ pub fn switch_to_urgent_or_lru_window( extra_props: Option<&HashMap>, ) { let root = get_tree(); - let windows = con::get_windows(&root, extra_props); + let windows = con::get_windows(&root, true, extra_props); if let Some(win) = windows .iter() .find(|w| w.is_urgent()) @@ -106,7 +106,7 @@ pub fn switch_to_urgent_or_lru_window( pub fn switch_window(extra_props: Option<&HashMap>) { let root = get_tree(); - let windows = con::get_windows(&root, extra_props); + let windows = con::get_windows(&root, true, extra_props); if let Some(window) = con::select_window("Switch to window", &windows) { focus_window_by_id(window.get_id()) @@ -123,7 +123,7 @@ pub fn focus_next_window_in_direction( extra_props: Option<&HashMap>, ) { let root = get_tree(); - let windows = con::get_windows(&root, None); + let windows = con::get_windows(&root, false, None); if windows.len() < 2 { return; @@ -131,10 +131,11 @@ pub fn focus_next_window_in_direction( let pred: Box bool> = if windows.iter().find(|w| w.is_focused()).is_none() { - let last_focused_win_id = con::get_windows(&root, extra_props) - .get(0) - .unwrap() - .get_id(); + let last_focused_win_id = + con::get_windows(&root, false, extra_props) + .get(0) + .unwrap() + .get_id(); Box::new(move |w| w.get_id() == last_focused_win_id) } else { Box::new(|w: &con::Window| w.is_focused()) @@ -187,7 +188,7 @@ pub fn switch_workspace_or_window( pub fn quit_window(extra_props: Option<&HashMap>) { let root = get_tree(); - let windows = con::get_windows(&root, extra_props); + let windows = con::get_windows(&root, true, extra_props); if let Some(window) = con::select_window("Quit window", &windows) { quit_window_by_id(window.get_id()) diff --git a/src/con.rs b/src/con.rs index cbaeaab..26aff6f 100644 --- a/src/con.rs +++ b/src/con.rs @@ -109,10 +109,15 @@ impl<'a> fmt::Display for Window<'a> { fn build_windows<'a>( root: &'a r::Node, + include_scratchpad_windows: bool, extra_props: Option<&HashMap>, ) -> Vec> { let mut v = vec![]; for workspace in root.workspaces() { + if !include_scratchpad_windows && workspace.is_scratchpad() { + continue; + } + for n in workspace.windows() { v.push(Window { node: &n, @@ -126,10 +131,15 @@ fn build_windows<'a>( fn build_workspaces<'a>( root: &'a r::Node, + include_scratchpad: bool, extra_props: Option<&HashMap>, ) -> Vec> { let mut v = vec![]; for workspace in root.workspaces() { + if !include_scratchpad && workspace.is_scratchpad() { + continue; + } + let mut wins: Vec = workspace .windows() .iter() @@ -154,10 +164,11 @@ fn build_workspaces<'a>( /// Gets all application windows of the tree. pub fn get_windows<'a>( root: &'a r::Node, + include_scratchpad_windows: bool, extra_props: Option<&HashMap>, ) -> Vec> { let extra_props_given = extra_props.is_some(); - let mut wins = build_windows(root, extra_props); + let mut wins = build_windows(root, include_scratchpad_windows, extra_props); if extra_props_given { wins.sort(); } @@ -170,15 +181,8 @@ pub fn get_workspaces<'a>( include_scratchpad: bool, extra_props: Option<&HashMap>, ) -> Vec> { - let workspaces = build_workspaces(root, extra_props); - let mut workspaces = if include_scratchpad { - workspaces - } else { - workspaces - .into_iter() - .filter(|ws| !ws.is_scratchpad()) - .collect() - }; + let mut workspaces = + build_workspaces(root, include_scratchpad, extra_props); workspaces.rotate_left(1); workspaces } @@ -252,7 +256,7 @@ impl Workspace<'_> { } pub fn is_scratchpad(&self) -> bool { - self.get_name().eq("__i3_scratch") + self.node.is_scratchpad() } } diff --git a/src/ipc.rs b/src/ipc.rs index 9a61ada..3d3a74a 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -50,6 +50,8 @@ pub trait NodeMethods { /// Returns all nodes being workspaces. fn workspaces(&self) -> Vec<&r::Node>; + + fn is_scratchpad(&self) -> bool; } impl NodeMethods for r::Node { @@ -72,6 +74,10 @@ impl NodeMethods for r::Node { .filter(|n| n.node_type == r::NodeType::Workspace) .collect() } + + fn is_scratchpad(&self) -> bool { + self.name.is_some() && self.name.as_ref().unwrap().eq("__i3_scratch") + } } #[derive(Clap, Debug, Deserialize, Serialize)]