Skip to content

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

feat: make target index optional when attaching a container

Lars Bergere9812367eecd
diff --git a/packages/wm/src/containers/commands/attach_container.rs b/packages/wm/src/containers/commands/attach_container.rs
index 65907735..d96574ab 100644
--- a/packages/wm/src/containers/commands/attach_container.rs
+++ b/packages/wm/src/containers/commands/attach_container.rs
@@ -14,15 +14,20 @@ use super::resize_tiling_container;
pub fn attach_container(
child: Container,
target_parent: &TilingContainer,
- target_index: usize,
+ target_index: Option<usize>,
) -> anyhow::Result<()> {
if !child.is_detached() {
bail!("Cannot attach an already attached container.");
}
- target_parent
- .borrow_children_mut()
- .insert(target_index, child.clone());
+ // Insert the child at the specified index.
+ if let Some(target_index) = target_index {
+ target_parent
+ .borrow_children_mut()
+ .insert(target_index, child.clone());
+ } else {
+ target_parent.borrow_children_mut().push_back(child.clone());
+ }
target_parent
.borrow_child_focus_order_mut()
diff --git a/packages/wm/src/containers/commands/flatten_split_container.rs b/packages/wm/src/containers/commands/flatten_split_container.rs
index f0530057..47aa1d6d 100644
--- a/packages/wm/src/containers/commands/flatten_split_container.rs
+++ b/packages/wm/src/containers/commands/flatten_split_container.rs
@@ -5,6 +5,10 @@ use crate::containers::{
SplitContainer,
};
+/// Removes a split container from the tree and moves its children
+/// into the parent container.
+///
+/// The children will be resized to fit the size of the split container.
pub fn flatten_split_container(
split_container: SplitContainer,
) -> anyhow::Result<()> {
diff --git a/packages/wm/src/monitors/commands/add_monitor.rs b/packages/wm/src/monitors/commands/add_monitor.rs
index d108b3ad..3874c142 100644
--- a/packages/wm/src/monitors/commands/add_monitor.rs
+++ b/packages/wm/src/monitors/commands/add_monitor.rs
@@ -19,7 +19,7 @@ pub fn add_monitor(
attach_container(
monitor.clone().into(),
&state.root_container.clone().into(),
- 0,
+ None,
)?;
state.emit_event(WmEvent::MonitorAdded {
diff --git a/packages/wm/src/windows/commands/manage_window_command.rs b/packages/wm/src/windows/commands/manage_window_command.rs
index ba728855..09a41fe4 100644
--- a/packages/wm/src/windows/commands/manage_window_command.rs
+++ b/packages/wm/src/windows/commands/manage_window_command.rs
@@ -136,7 +136,7 @@ fn create_window(
attach_container(
window_container.clone().into(),
&target_parent,
- target_index,
+ Some(target_index),
)?;
// The OS might spawn the window on a different monitor to the target
diff --git a/packages/wm/src/workspaces/commands/activate_workspace.rs b/packages/wm/src/workspaces/commands/activate_workspace.rs
index 2fbfa634..33aa3e8a 100644
--- a/packages/wm/src/workspaces/commands/activate_workspace.rs
+++ b/packages/wm/src/workspaces/commands/activate_workspace.rs
@@ -39,7 +39,7 @@ pub fn activate_workspace(
attach_container(
workspace.clone().into(),
&target_monitor.clone().into(),
- 0,
+ None,
)?;
state.emit_event(WmEvent::WorkspaceActivated {