GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
fix: flatten redundant split containers on workspace invert
Lars Berger657cfb6e8a74
diff --git a/packages/wm/src/containers/commands/flatten_child_split_containers.rs b/packages/wm/src/containers/commands/flatten_child_split_containers.rsindex c3699431..ba239d06 100644--- a/packages/wm/src/containers/commands/flatten_child_split_containers.rs+++ b/packages/wm/src/containers/commands/flatten_child_split_containers.rs@@ -11,7 +11,8 @@ use super::flatten_split_container;/// For example:/// ```/// H[1 H[V[2, 3]]] -> H[1, 2, 3]-/// H[V[1]] -> H[1]+/// H[1 H[2, 3]] -> H[1, 2, 3]+/// H[V[1]] -> V[1]/// ```pub fn flatten_child_split_containers(parent: Container,@@ -34,17 +35,25 @@ pub fn flatten_child_split_containers(}}_ => {- for split_child in tiling_children+ let split_children = tiling_children.into_iter().filter_map(|child| child.as_split().cloned())- .filter(|split_child| split_child.child_count() == 1)- {- if let Some(split_grandchild) =- split_child.children()[0].as_split()- {- flatten_split_container(split_grandchild.clone())?;- flatten_split_container(split_child.clone())?;+ .collect::<Vec<_>>();++ for split_child in split_children.iter().filter(|split_child| {+ split_child.tiling_direction() == parent.tiling_direction()+ }) {+ // Additionally flatten redundant top-level split containers in+ // the child.+ if split_child.child_count() == 1 {+ if let Some(split_grandchild) =+ split_child.children()[0].as_split()+ {+ flatten_split_container(split_grandchild.clone())?;+ }}++ flatten_split_container(split_child.clone())?;}}}diff --git a/packages/wm/src/windows/commands/move_window_in_direction.rs b/packages/wm/src/windows/commands/move_window_in_direction.rsindex 7ddd1c52..a3ebb979 100644--- a/packages/wm/src/windows/commands/move_window_in_direction.rs+++ b/packages/wm/src/windows/commands/move_window_in_direction.rs@@ -6,8 +6,8 @@ use crate::{common::{Direction, Rect, TilingDirection},containers::{commands::{- flatten_split_container, move_container_within_tree,- resize_tiling_container,+ flatten_child_split_containers, flatten_split_container,+ move_container_within_tree, resize_tiling_container,},traits::{CommonGetters, PositionGetters, TilingDirectionGetters,@@ -109,7 +109,7 @@ fn move_tiling_window(match target_ancestor {// If there is no suitable ancestor, then change the tiling direction// of the workspace.- None => change_workspace_tiling_direction(+ None => invert_workspace_tiling_direction(window_to_move,direction,state,@@ -255,7 +255,7 @@ fn move_to_workspace_in_direction(Ok(())}-fn change_workspace_tiling_direction(+fn invert_workspace_tiling_direction(window_to_move: TilingWindow,direction: &Direction,state: &mut WmState,@@ -303,6 +303,11 @@ fn change_workspace_tiling_direction(state,)?;+ // Workspace might have redundant split containers after the tiling+ // direction change. For example, V[H[1 2] 3] where container 3 is moved+ // up results in H[3 H[1 2]], and needs to be flattened to H[3 1 2].+ flatten_child_split_containers(workspace.clone().into())?;+// Resize the window such that the split container and window are each 0.5.resize_tiling_container(&window_to_move.into(), 0.5);