Skip to content

Commit

Permalink
fix(wm): enforce resize constraints universally
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LGUG2Z committed Aug 9, 2021
1 parent f366132 commit be1d07e
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions komorebi/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<()> {
Expand Down

0 comments on commit be1d07e

Please sign in to comment.