From 55b62c2bc90d09c68da0682bcba902bcc78c9516 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 13 Aug 2021 07:05:42 -0700 Subject: [PATCH] fix(wm): check resize_dimensions before removing A user, possibly using multiple monitors, reported a panic on startup which I traced back to an unchecked remove op on a Vec. Spent so much time working with VecDeque that I forgot that removing from a Vec panics instead of returning an Option. This change ensures that when trying to remove a container's resize dimensions in a workspace, we check that the container actually has a corresponding resize dimension before calling remove. Similarly, in order to ensure consistency with workspace updates which always resize the length of the resize dimensions to match the length of the number of container layouts, sets the length of the resize dimensions array when initialising a workspace in WindowsApi::load_workspace_information. fix #1 --- komorebi/src/windows_api.rs | 7 ++++++- komorebi/src/workspace.rs | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/komorebi/src/windows_api.rs b/komorebi/src/windows_api.rs index bd556c39..4e4bd053 100644 --- a/komorebi/src/windows_api.rs +++ b/komorebi/src/windows_api.rs @@ -185,7 +185,12 @@ impl WindowsApi { workspace.containers_mut() as *mut VecDeque as isize, )?; - // So we have to prune each monitor's primary workspace of undesired windows here + // Ensure that the resize_dimensions Vec length matches the number of containers for + // the potential later calls to workspace.remove_window later in this fn + let len = workspace.containers().len(); + workspace.resize_dimensions_mut().resize(len, None); + + // We have to prune each monitor's primary workspace of undesired windows here let mut windows_on_other_monitors = vec![]; for container in workspace.containers_mut() { diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index c1ea4f49..569635e6 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -281,7 +281,9 @@ impl Workspace { .context("there is no container")?; // Whenever a container is empty, we need to remove any resize dimensions for it too - self.resize_dimensions_mut().remove(container_idx); + if self.resize_dimensions().get(container_idx).is_some() { + self.resize_dimensions_mut().remove(container_idx); + } } if container_idx != 0 {