GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: partially implement `flatten_split_container` command
Lars Berger196403d35808
diff --git a/packages/wm/src/common/commands/sync_native_focus.rs b/packages/wm/src/common/commands/sync_native_focus.rsindex be46c0a9..1e581149 100644--- a/packages/wm/src/common/commands/sync_native_focus.rs+++ b/packages/wm/src/common/commands/sync_native_focus.rs@@ -21,8 +21,7 @@ pub fn sync_native_focus(state: &mut WmState) -> anyhow::Result<()> {};// Set focus to the given window handle. If the container is a normal- // window, then this will trigger `EVENT_SYSTEM_FOREGROUND` window event- // and its handler.+ // window, then this will trigger a `PlatformEvent::WindowFocused` event.let _ = native_window.set_foreground();state.emit_event(WmEvent::NativeFocusSynced {diff --git a/packages/wm/src/containers/commands/flatten_split_container.rs b/packages/wm/src/containers/commands/flatten_split_container.rsnew file mode 100644index 00000000..c02b9891--- /dev/null+++ b/packages/wm/src/containers/commands/flatten_split_container.rs@@ -0,0 +1,68 @@+use std::collections::VecDeque;++use anyhow::Context;++use crate::{+ containers::{+ traits::{CommonGetters, DirectionGetters, TilingGetters},+ Container, SplitContainer,+ },+ wm_state::WmState,+};++pub fn flatten_split_container(+ split_container: SplitContainer,+ state: &WmState,+) -> anyhow::Result<()> {+ let parent = split_container.parent().context("No parent.")?;++ let updated_children = split_container.children().iter().map(|child| {+ *child.borrow_parent_mut() = Some(parent.clone());++ // Resize tiling children to fit the size of the split container.+ if let Ok(tiling_child) = child.as_tiling_container() {+ tiling_child.set_size_percent(+ split_container.size_percent() * tiling_child.size_percent(),+ );+ }++ // Inverse the tiling direction of any child split containers.+ if let Some(split_child) = child.as_split() {+ split_child.set_tiling_direction(+ split_container.tiling_direction().inverse(),+ );+ }+ });++ // let mut deque = VecDeque::from(vec![1, 2, 3, 4, 5]);+ // let position = 2;+ // let new_elements = vec![10, 11, 12];++ // deque.splice(position..position + 1, new_elements.iter().cloned());++ // println!("{:?}", deque);++ let focus_index = split_container.focus_index();+ parent+ .borrow_child_focus_order_mut()+ .iter_mut()+ .collect::<Vec<_>>()+ .splice(+ focus_index..focus_index,+ split_container+ .borrow_child_focus_order()+ .clone()+ .iter_mut(),+ );++ let index = split_container.index();+ parent+ .borrow_children_mut()+ .iter_mut()+ .collect::<Vec<_>>()+ .splice(index..index, updated_children.collect::<Vec<_>>());+ // .collect();+ // .retain(|id| id != &split_container.id());++ Ok(())+}diff --git a/packages/wm/src/containers/commands/mod.rs b/packages/wm/src/containers/commands/mod.rsindex 001a17f0..63ebb916 100644--- a/packages/wm/src/containers/commands/mod.rs+++ b/packages/wm/src/containers/commands/mod.rs@@ -1,9 +1,11 @@mod attach_container;+mod flatten_split_container;mod redraw;mod resize_tiling_container;mod set_focused_descendant;pub use attach_container::*;+pub use flatten_split_container::*;pub use redraw::*;pub use resize_tiling_container::*;pub use set_focused_descendant::*;