From be1d07e397b50ad512b5c41bccc7d264afa6f68a Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Mon, 9 Aug 2021 09:46:01 -0700 Subject: [PATCH] fix(wm): enforce resize constraints universally Previously resize constraints on odd and even container numbers were not being enforced consistently. Now, instead of trying to enforce them on individual operations, every time an update operation is called for a workspace, the resize constraints will be enforced before trying to calculate and apply an updated layout. --- komorebi/src/workspace.rs | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 61768e80..86c089cc 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -84,6 +84,8 @@ impl Workspace { let mut adjusted_work_area = *work_area; adjusted_work_area.add_padding(self.workspace_padding()); + self.enforce_resize_constraints(); + if let Some(container) = self.monocle_container_mut() { if let Some(window) = container.focused_window_mut() { window.set_position(&adjusted_work_area, true)?; @@ -264,12 +266,6 @@ impl Workspace { // Whenever a container is empty, we need to remove any resize dimensions for it too self.resize_dimensions_mut().remove(container_idx); - - // The last container can never be resized to the bottom or the right - if let Some(Some(last)) = self.resize_dimensions_mut().last_mut() { - last.bottom = 0; - last.right = 0; - } } if container_idx != 0 { @@ -416,14 +412,35 @@ impl Workspace { container.load_focused_window(); } + self.floating_windows_mut().push(window); + + Ok(()) + } + + fn enforce_resize_constraints(&mut self) { + for (i, rect) in self.resize_dimensions_mut().iter_mut().enumerate() { + if let Some(rect) = rect { + // Even containers can't be resized to the bottom + if i % 2 == 0 { + rect.bottom = 0; + // Odd containers can't be resized to the right + } else { + rect.right = 0; + } + } + } + + // The first container can never be resized to the left or the top + if let Some(Some(first)) = self.resize_dimensions_mut().first_mut() { + first.top = 0; + first.left = 0; + } + + // The last container can never be resized to the bottom or the right if let Some(Some(last)) = self.resize_dimensions_mut().last_mut() { last.bottom = 0; last.right = 0; } - - self.floating_windows_mut().push(window); - - Ok(()) } pub fn new_monocle_container(&mut self) -> Result<()> {