From 637cbff935decb1dd962aaa8873e9b31d15f1c73 Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Fri, 15 Oct 2021 21:30:14 +0200 Subject: [PATCH] Fix bug #6, release 0.8.0-beta.1 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/cmds.rs | 38 ++++++++++++++++++++++++++++---------- src/con.rs | 7 +++++-- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 560af8c..93286b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -357,7 +357,7 @@ dependencies = [ [[package]] name = "swayr" -version = "0.8.0-beta.0" +version = "0.8.0-beta.1" dependencies = [ "clap", "directories", diff --git a/Cargo.toml b/Cargo.toml index 5e4b20a..8708fbe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "swayr" -version = "0.8.0-beta.0" +version = "0.8.0-beta.1" description = "A LRU window-switcher (and more) for the sway window manager" homepage = "https://sr.ht/~tsdh/swayr/" repository = "https://git.sr.ht/~tsdh/swayr" diff --git a/src/cmds.rs b/src/cmds.rs index 81a235a..3090c78 100644 --- a/src/cmds.rs +++ b/src/cmds.rs @@ -181,13 +181,17 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) { Direction::Forward, windows, Some(&*props.read().unwrap()), - Box::new(|w: &con::Window| w.is_child_of_tiled_container()), + Box::new(|w: &con::Window| { + !w.is_floating() && w.is_child_of_tiled_container() + }), ), SwayrCommand::PrevTiledWindow { windows } => focus_window_in_direction( Direction::Backward, windows, Some(&*props.read().unwrap()), - Box::new(|w: &con::Window| w.is_child_of_tiled_container()), + Box::new(|w: &con::Window| { + !w.is_floating() && w.is_child_of_tiled_container() + }), ), SwayrCommand::NextTabbedOrStackedWindow { windows } => { focus_window_in_direction( @@ -195,7 +199,8 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) { windows, Some(&*props.read().unwrap()), Box::new(|w: &con::Window| { - w.is_child_of_tabbed_or_stacked_container() + !w.is_floating() + && w.is_child_of_tabbed_or_stacked_container() }), ) } @@ -205,7 +210,8 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) { windows, Some(&*props.read().unwrap()), Box::new(|w: &con::Window| { - w.is_child_of_tabbed_or_stacked_container() + !w.is_floating() + && w.is_child_of_tabbed_or_stacked_container() }), ) } @@ -387,7 +393,10 @@ pub fn focus_window_in_direction( } }; - let windows = con::get_windows(root, false, extra_props); + let windows: Vec = con::get_windows(root, false, extra_props) + .into_iter() + .filter(|w| pred(w)) + .collect(); if windows.len() < 2 { return; @@ -409,7 +418,7 @@ pub fn focus_window_in_direction( loop { let win = iter.next().unwrap(); if is_focused_window(win) { - let win = iter.find(|w| pred(w)).unwrap(); + let win = iter.next().unwrap(); focus_window_by_id(win.get_id()); return; } @@ -435,10 +444,19 @@ pub fn focus_similar_window_in_direction( extra_props, if current_window.is_floating() { Box::new(|w| w.is_floating()) - } else if current_window.is_child_of_tabbed_or_stacked_container() { - Box::new(|w| w.is_child_of_tabbed_or_stacked_container()) - } else if current_window.is_child_of_tiled_container() { - Box::new(|w| w.is_child_of_tiled_container()) + } else if !current_window.is_floating() + && current_window.is_child_of_tabbed_or_stacked_container() + { + Box::new(|w| { + !w.is_floating() + && w.is_child_of_tabbed_or_stacked_container() + }) + } else if !current_window.is_floating() + && current_window.is_child_of_tiled_container() + { + Box::new(|w| { + !w.is_floating() && w.is_child_of_tiled_container() + }) } else { Box::new(always_true) }, diff --git a/src/con.rs b/src/con.rs index 7256802..e711df9 100644 --- a/src/con.rs +++ b/src/con.rs @@ -160,8 +160,11 @@ impl Window<'_> { pub fn get_parent(&self) -> &s::Node { NodeIter::new(self.workspace) - .find(|n| n.nodes.contains(self.node)) - .expect("No parent node of a window!") + .find(|n| { + n.nodes.contains(self.node) + || n.floating_nodes.contains(self.node) + }) + .unwrap_or_else(|| panic!("Window {:?} has no parent node!", self)) } pub fn is_child_of_tiled_container(&self) -> bool {