fix(wm): skip layout calc for empty workspaces

While investigating issue #2 I was able to reproduce it and view the
panic that causes the komorebi process to become non-responsive.

When switching to a columnar layout (which is the default for the 2nd
workspace in the sample ahk config), there is the possibility to cause a
divide by zero panic if the len passed to Layout::calculate is 0.

I have remedied this by changing the type of len from usize to
NonZeroUsize, and also by ensuring that Layout::calculate is only called
from within the komorebi crate if the workspace has at least one
container.

While moving containers around I also noticed that creating a new
container for a window may also cause a panic if focused_idx + 1 is
greater than the length of the VecDeque of containers, so this was
addressed by pushing to the back of the VecDeque in that case.

re #2
This commit is contained in:
LGUG2Z
2021-08-15 06:24:39 -07:00
parent a550c088dc
commit a53b2cc28c
8 changed files with 35 additions and 15 deletions
+4 -1
View File
@@ -1,3 +1,5 @@
use std::num::NonZeroUsize;
use clap::Clap;
use serde::Deserialize;
use serde::Serialize;
@@ -127,11 +129,12 @@ impl Layout {
pub fn calculate(
&self,
area: &Rect,
len: usize,
len: NonZeroUsize,
container_padding: Option<i32>,
layout_flip: Option<LayoutFlip>,
resize_dimensions: &[Option<Rect>],
) -> Vec<Rect> {
let len = usize::from(len);
let mut dimensions = match self {
Layout::BSP => recursive_fibonacci(
0,