From ac4eee711e313c1dbcdd3fdf7fb13c3ad360eabd Mon Sep 17 00:00:00 2001 From: tcmal Date: Sun, 25 Aug 2024 21:10:02 +0100 Subject: Deal with focused window being destroyed better --- src/clients/mod.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 750a30a..c42a385 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -222,12 +222,19 @@ impl ClientState { self.clients.remove(i); - self.focused_client = self.focused_client.filter(|f| *f < self.clients.len()); + self.focused_client = self.focused_client.and_then(|f| match f.cmp(&i) { + Ordering::Less => Some(f), + Ordering::Greater => Some(f - 1), + Ordering::Equal => None, + }); if self.focused_client.is_none() { - self.focused_client = self + if let Some(i) = self .clients .iter() - .position(|c| focused_mon.contains(c.x(), c.y())); + .position(|c| focused_mon.contains(c.x(), c.y())) + { + self.refocus(conn, i); + } } self.rearrange(conn); -- cgit v1.2.3