GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: use window's insertion target when transitioning to tiling
Lars Bergera03bb2c8343d
diff --git a/packages/wm/src/windows/commands/update_window_state.rs b/packages/wm/src/windows/commands/update_window_state.rsindex 245fef09..1517087a 100644--- a/packages/wm/src/windows/commands/update_window_state.rs+++ b/packages/wm/src/windows/commands/update_window_state.rs@@ -37,10 +37,21 @@ fn set_tiling(.parent_workspace().context("Window has no workspace.")?;- let insertion_target = window- .descendant_focus_order()- .filter(|c| c.is_tiling_window())- .next();+ // Get the position in the tree to insert the new tiling window. This+ // will be the window's previous tiling position if it has one, or+ // instead beside the last focused tiling window in the workspace.+ let (target_parent, target_index) = window+ .insertion_target()+ .or_else(|| {+ // Get the last focused tiling window within the workspace.+ let focused_window = window+ .descendant_focus_order()+ .filter(|c| c.is_tiling_window())+ .next()?;++ Some((focused_window.parent()?, focused_window.index() + 1))+ })+ .unwrap_or((workspace.into(), 0));let tiling_window =window.to_tiling(config.value.gaps.inner_gap.clone());@@ -52,24 +63,11 @@ fn set_tiling(window.index(),)?;- // Insert the created tiling window after the last focused tiling- // window within the workspace.- match insertion_target {- Some(insertion_target) => {- move_container_within_tree(- tiling_window.clone().into(),- insertion_target.parent().context("No parent.")?,- insertion_target.index() + 1,- )?;- }- None => {- move_container_within_tree(- tiling_window.clone().into(),- workspace.into(),- 0,- )?;- }- }+ move_container_within_tree(+ tiling_window.clone().into(),+ target_parent,+ target_index,+ )?;state.add_container_to_redraw(tiling_window.into());}diff --git a/packages/wm/src/windows/non_tiling_window.rs b/packages/wm/src/windows/non_tiling_window.rsindex c20716a5..a0e6b898 100644--- a/packages/wm/src/windows/non_tiling_window.rs+++ b/packages/wm/src/windows/non_tiling_window.rs@@ -32,7 +32,7 @@ struct NonTilingWindowInner {native: NativeWindow,state: WindowState,prev_state: Option<WindowState>,- insertion_reference: Option<(Container, usize)>,+ insertion_target: Option<(Container, usize)>,display_state: DisplayState,border_delta: RectDelta,has_pending_dpi_adjustment: bool,@@ -45,7 +45,7 @@ impl NonTilingWindow {native: NativeWindow,state: WindowState,prev_state: Option<WindowState>,- insertion_reference: Option<(Container, usize)>,+ insertion_target: Option<(Container, usize)>,floating_placement: Rect,) -> Self {let window = NonTilingWindowInner {@@ -56,7 +56,7 @@ impl NonTilingWindow {native,state,prev_state,- insertion_reference,+ insertion_target,display_state: DisplayState::Shown,border_delta: RectDelta::new(LengthValue::new_px(0.),@@ -71,6 +71,10 @@ impl NonTilingWindow {Self(Rc::new(RefCell::new(window)))}+ pub fn insertion_target(&self) -> Option<(Container, usize)> {+ self.0.borrow().insertion_target.clone()+ }+pub fn set_state(&self, state: WindowState) {self.0.borrow_mut().state = state;}