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<T>.

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
This commit is contained in:
LGUG2Z
2021-08-13 07:05:42 -07:00
parent 0d3751a7cc
commit 55b62c2bc9
2 changed files with 9 additions and 2 deletions

View File

@@ -185,7 +185,12 @@ impl WindowsApi {
workspace.containers_mut() as *mut VecDeque<Container> 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() {

View File

@@ -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 {