Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

fix: conditionally wrap siblings in split container on move; clamp target index

Lars Bergerfa434a58d556
diff --git a/packages/wm/src/common/vec_deque_ext.rs b/packages/wm/src/common/vec_deque_ext.rs
index 5c31486c..cc370d26 100644
--- a/packages/wm/src/common/vec_deque_ext.rs
+++ b/packages/wm/src/common/vec_deque_ext.rs
@@ -21,7 +21,10 @@ where
fn shift_to_index(&mut self, target_index: usize, value: T) {
if let Some(index) = self.iter().position(|e| e == &value) {
self.remove(index);
- self.insert(target_index, value);
+
+ // Adjust for when the target index becomes out of bounds because of
+ // the removal above.
+ self.insert(target_index.clamp(0, self.len()), value);
}
}
diff --git a/packages/wm/src/containers/commands/move_container_within_tree.rs b/packages/wm/src/containers/commands/move_container_within_tree.rs
index da74d33a..72c9b25f 100644
--- a/packages/wm/src/containers/commands/move_container_within_tree.rs
+++ b/packages/wm/src/containers/commands/move_container_within_tree.rs
@@ -159,16 +159,10 @@ fn move_to_lowest_common_ancestor(
detach_container(container_to_move.clone())?;
- // Adjust for when target index changes on detach of container. For
- // example, when shifting a top-level container to the right in a
- // workspace.
- let adjusted_target_index =
- target_index.clamp(0, lowest_common_ancestor.child_count());
-
attach_container(
&container_to_move.clone(),
&lowest_common_ancestor.clone(),
- Some(adjusted_target_index),
+ Some(target_index),
)?;
lowest_common_ancestor
diff --git a/packages/wm/src/windows/commands/move_window_in_direction.rs b/packages/wm/src/windows/commands/move_window_in_direction.rs
index fd02dfb3..b64dba25 100644
--- a/packages/wm/src/windows/commands/move_window_in_direction.rs
+++ b/packages/wm/src/windows/commands/move_window_in_direction.rs
@@ -245,13 +245,10 @@ fn change_workspace_tiling_direction(
state: &mut WmState,
config: &UserConfig,
) -> anyhow::Result<()> {
- // 1. Change the tiling direction of the workspace.
- // 2. All other containers are wrapped in a split container.
- // 3. Split container is resized to be 50% (and window is also 50%).
- // 4. Depending on direction, place window before/after split container.
-
let workspace = window_to_move.workspace().context("No workspace.")?;
let parent = window_to_move.parent().context("No parent.")?;
+ let tiling_siblings =
+ window_to_move.tiling_siblings().collect::<Vec<_>>();
if let Some(split_parent) = parent.as_split().cloned() {
if split_parent.child_count() == 1 {
@@ -260,16 +257,18 @@ fn change_workspace_tiling_direction(
}
// Create a new split container to wrap the window's siblings.
- let split_container = SplitContainer::new(
- workspace.tiling_direction(),
- config.value.gaps.inner_gap.clone(),
- );
-
- wrap_in_split_container(
- split_container,
- parent.clone(),
- window_to_move.clone().tiling_siblings().collect(),
- )?;
+ if tiling_siblings.len() > 0 {
+ let split_container = SplitContainer::new(
+ workspace.tiling_direction(),
+ config.value.gaps.inner_gap.clone(),
+ );
+
+ wrap_in_split_container(
+ split_container,
+ parent.clone(),
+ tiling_siblings,
+ )?;
+ }
// Invert the tiling direction of the workspace.
workspace.set_tiling_direction(workspace.tiling_direction().inverse());
@@ -279,6 +278,8 @@ fn change_workspace_tiling_direction(
_ => workspace.child_count(),
};
+ // Depending on the direction, place the window either before or after
+ // the split container.
move_container_within_tree(
window_to_move.clone().into(),
parent,
@@ -286,6 +287,7 @@ fn change_workspace_tiling_direction(
state,
)?;
+ // Resize the window such that the split container and window are each 0.5.
resize_tiling_container(&window_to_move.into(), 0.5);
state