From 4f97eac4f9983c8cfa6ee506a3a20b0abb33f2a3 Mon Sep 17 00:00:00 2001 From: tcmal Date: Mon, 15 Jul 2024 19:25:03 +0100 Subject: Fix crash when run with multiple monitors --- src/clients/mod.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 37a88c0..053b4de 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -359,11 +359,17 @@ impl ClientState { /// Set the new amount of screens, without unmanaging any clients. fn truncate_screens(&mut self, new_size: usize) { // hack: working around double borrow stuff - let mut moved_clients = vec![]; - for old in self.mons.drain(new_size - self.mons.len()..self.mons.len()) { - moved_clients.extend(old.clients.into_iter()); + if new_size < self.mons.len() { + let mut moved_clients = vec![]; + for old in self.mons.drain(new_size - self.mons.len()..self.mons.len()) { + moved_clients.extend(old.clients.into_iter()); + } + self.mons[0].clients.extend(moved_clients); + } else if new_size > self.mons.len() { + for _ in 0..new_size - self.mons.len() { + self.mons.push(MonitorInfo::default()); + } } - self.mons[0].clients.extend(moved_clients); } /// Set the given screen's geometry, resizing the monitor list if necessary. -- cgit v1.2.3