From b9cecab9a340f6c5852f7699bf94157b770608a6 Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Wed, 17 Nov 2021 10:42:28 +0100 Subject: [PATCH] Release v0.10.0-beta.3 Urgent windows were not on top of the switcher list --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/tree.rs | 16 +++++++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7b7f418..41dff29 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -360,7 +360,7 @@ dependencies = [ [[package]] name = "swayr" -version = "0.10.0-beta.2" +version = "0.10.0-beta.3" dependencies = [ "clap", "directories", diff --git a/Cargo.toml b/Cargo.toml index 5be3c2b..27b41e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "swayr" -version = "0.10.0-beta.2" +version = "0.10.0-beta.3" 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/tree.rs b/src/tree.rs index ad7d26e..703e3cf 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -218,7 +218,7 @@ impl<'a> Tree<'a> { t: Type, ) -> Vec<&s::Node> { let mut v: Vec<&s::Node> = node.nodes_of_type(t); - self.sort_by_lru_time(&mut v); + self.sort_by_urgency_and_lru_time_1(&mut v); v } @@ -249,13 +249,19 @@ impl<'a> Tree<'a> { pub fn get_workspaces(&self) -> Vec { let mut v = self.sorted_nodes_of_type(Type::Workspace); - v.rotate_left(1); + if !v.is_empty() { + v.rotate_left(1); + } self.as_display_nodes(&v, IndentLevel::Fixed(0)) } pub fn get_windows(&self) -> Vec { let mut v = self.sorted_nodes_of_type(Type::Window); - v.rotate_left(1); + // Don't rotate if there's an urgent window because that should be the + // first in the list because it's the most likely switch candidate. + if !v.is_empty() && !v[0].urgent { + v.rotate_left(1); + } self.as_display_nodes(&v, IndentLevel::Fixed(0)) } @@ -276,7 +282,7 @@ impl<'a> Tree<'a> { self.as_display_nodes(&v, IndentLevel::WorkspacesZeroWindowsOne) } - fn sort_by_lru_time(&self, v: &mut Vec<&s::Node>) { + fn sort_by_urgency_and_lru_time_1(&self, v: &mut Vec<&s::Node>) { v.sort_by(|a, b| { if a.urgent && !b.urgent { cmp::Ordering::Less @@ -299,7 +305,7 @@ impl<'a> Tree<'a> { let mut children: Vec<&s::Node> = n.nodes.iter().collect(); children.append(&mut n.floating_nodes.iter().collect()); - self.sort_by_lru_time(&mut children); + self.sort_by_urgency_and_lru_time_1(&mut children); for c in children { self.push_subtree_sorted(c, Rc::clone(&v));