From 37a87f89cea4d3ce0c8ef16fc6ad846706eed9af Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Wed, 17 Nov 2021 16:57:54 +0100 Subject: [PATCH] Rotate but keep urgent windows on top in switch-window --- src/tree.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/tree.rs b/src/tree.rs index 703e3cf..ba1597f 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -257,12 +257,26 @@ impl<'a> Tree<'a> { pub fn get_windows(&self) -> Vec { let mut v = self.sorted_nodes_of_type(Type::Window); - // 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); + // Rotate, but only non-urgent windows. Those should stay at the front + // as they are the most likely switch candidates. + let mut x; + if !v.is_empty() { + x = vec![]; + loop { + if !v.is_empty() && v[0].urgent { + x.push(v.remove(0)); + } else { + break; + } + } + if !v.is_empty() { + v.rotate_left(1); + } + x.append(&mut v); + } else { + x = v; } - self.as_display_nodes(&v, IndentLevel::Fixed(0)) + self.as_display_nodes(&x, IndentLevel::Fixed(0)) } pub fn get_workspaces_and_windows(&self) -> Vec { @@ -395,7 +409,7 @@ fn maybe_html_escape(do_it: bool, text: &str) -> String { } } -fn format_marks(marks: &Vec) -> String { +fn format_marks(marks: &[String]) -> String { if marks.is_empty() { "".to_string() } else {