GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: change container `children` to a `VecDeque`
Lars Berger9414e852340e
diff --git a/packages/wm/src/containers/root_container.rs b/packages/wm/src/containers/root_container.rsindex a4839d16..8eae0c11 100644--- a/packages/wm/src/containers/root_container.rs+++ b/packages/wm/src/containers/root_container.rs@@ -1,5 +1,6 @@use std::{cell::{Ref, RefCell, RefMut},+ collections::VecDeque,rc::Rc,};@@ -20,7 +21,7 @@ pub struct RootContainer(Rc<RefCell<RootContainerInner>>);struct RootContainerInner {id: Uuid,parent: Option<TilingContainer>,- children: Vec<Container>,+ children: VecDeque<Container>,size_percent: f32,}@@ -29,7 +30,7 @@ impl RootContainer {let root = RootContainerInner {id: Uuid::new_v4(),parent: None,- children: Vec::new(),+ children: VecDeque::new(),size_percent: 1.0,};diff --git a/packages/wm/src/containers/split_container.rs b/packages/wm/src/containers/split_container.rsindex 72ab20c9..be9e8a06 100644--- a/packages/wm/src/containers/split_container.rs+++ b/packages/wm/src/containers/split_container.rs@@ -1,5 +1,6 @@use std::{cell::{Ref, RefCell, RefMut},+ collections::VecDeque,rc::Rc,};@@ -22,7 +23,7 @@ pub struct SplitContainer(Rc<RefCell<SplitContainerInner>>);struct SplitContainerInner {id: Uuid,parent: Option<TilingContainer>,- children: Vec<Container>,+ children: VecDeque<Container>,size_percent: f32,tiling_direction: TilingDirection,}@@ -32,7 +33,7 @@ impl SplitContainer {let split = SplitContainerInner {id: Uuid::new_v4(),parent: None,- children: Vec::new(),+ children: VecDeque::new(),size_percent: 1.0,tiling_direction,};diff --git a/packages/wm/src/containers/traits/common_behavior.rs b/packages/wm/src/containers/traits/common_behavior.rsindex f327cdb6..06c0f561 100644--- a/packages/wm/src/containers/traits/common_behavior.rs+++ b/packages/wm/src/containers/traits/common_behavior.rs@@ -1,4 +1,7 @@-use std::cell::{Ref, RefMut};+use std::{+ cell::{Ref, RefMut},+ collections::VecDeque,+};use enum_dispatch::enum_dispatch;use uuid::Uuid;@@ -27,9 +30,9 @@ pub trait CommonBehavior {fn borrow_parent_mut(&self) -> RefMut<'_, Option<TilingContainer>>;- fn borrow_children(&self) -> Ref<'_, Vec<Container>>;+ fn borrow_children(&self) -> Ref<'_, VecDeque<Container>>;- fn borrow_children_mut(&self) -> RefMut<'_, Vec<Container>>;+ fn borrow_children_mut(&self) -> RefMut<'_, VecDeque<Container>>;/// Returns a reference to the parent container, unless this container is/// the root.@@ -41,7 +44,7 @@ pub trait CommonBehavior {self.borrow_parent().clone()}- fn children(&self) -> Vec<Container> {+ fn children(&self) -> VecDeque<Container> {self.borrow_children().clone()}@@ -53,7 +56,7 @@ pub trait CommonBehavior {fn self_and_descendants(&self) -> Descendants {let mut stack = self.children();- stack.push(self.as_container());+ stack.push_front(self.as_container());Descendants { stack }}@@ -136,14 +139,14 @@ impl_container_iterator!(Siblings, |container: &Container| {/// An iterator over descendants of a given container.pub struct Descendants {- stack: Vec<Container>,+ stack: VecDeque<Container>,}impl Iterator for Descendants {type Item = Container;fn next(&mut self) -> Option<Container> {- while let Some(container) = self.stack.pop() {+ while let Some(container) = self.stack.pop_front() {self.stack.extend(container.children());return Some(container);}@@ -179,11 +182,11 @@ macro_rules! impl_common_behavior {RefMut::map(self.0.borrow_mut(), |c| &mut c.parent)}- fn borrow_children(&self) -> Ref<'_, Vec<Container>> {+ fn borrow_children(&self) -> Ref<'_, VecDeque<Container>> {Ref::map(self.0.borrow(), |c| &c.children)}- fn borrow_children_mut(&self) -> RefMut<'_, Vec<Container>> {+ fn borrow_children_mut(&self) -> RefMut<'_, VecDeque<Container>> {RefMut::map(self.0.borrow_mut(), |c| &mut c.children)}}diff --git a/packages/wm/src/monitors/monitor.rs b/packages/wm/src/monitors/monitor.rsindex fed62b5c..c4750c56 100644--- a/packages/wm/src/monitors/monitor.rs+++ b/packages/wm/src/monitors/monitor.rs@@ -1,5 +1,6 @@use std::{cell::{Ref, RefCell, RefMut},+ collections::VecDeque,rc::Rc,};@@ -22,7 +23,7 @@ pub struct Monitor(Rc<RefCell<MonitorInner>>);struct MonitorInner {id: Uuid,parent: Option<TilingContainer>,- children: Vec<Container>,+ children: VecDeque<Container>,size_percent: f32,native: NativeMonitor,}@@ -32,7 +33,7 @@ impl Monitor {let monitor = MonitorInner {id: Uuid::new_v4(),parent: None,- children: Vec::new(),+ children: VecDeque::new(),size_percent: 1.0,native: native_monitor,};diff --git a/packages/wm/src/windows/non_tiling_window.rs b/packages/wm/src/windows/non_tiling_window.rsindex 9837578b..cb15463c 100644--- a/packages/wm/src/windows/non_tiling_window.rs+++ b/packages/wm/src/windows/non_tiling_window.rs@@ -1,5 +1,6 @@use std::{cell::{Ref, RefCell, RefMut},+ collections::VecDeque,rc::Rc,};@@ -21,7 +22,7 @@ pub struct NonTilingWindow(Rc<RefCell<NonTilingWindowInner>>);struct NonTilingWindowInner {id: Uuid,parent: Option<TilingContainer>,- children: Vec<Container>,+ children: VecDeque<Container>,native: NativeWindow,position: Rect,}@@ -31,7 +32,7 @@ impl NonTilingWindow {let window = NonTilingWindowInner {id: Uuid::new_v4(),parent: None,- children: Vec::new(),+ children: VecDeque::new(),native: native_window,position: Rect::from_xy(0, 0, 0, 0),};diff --git a/packages/wm/src/windows/tiling_window.rs b/packages/wm/src/windows/tiling_window.rsindex de310a1d..69db9e4b 100644--- a/packages/wm/src/windows/tiling_window.rs+++ b/packages/wm/src/windows/tiling_window.rs@@ -1,5 +1,6 @@use std::{cell::{Ref, RefCell, RefMut},+ collections::VecDeque,rc::Rc,};@@ -22,7 +23,7 @@ pub struct TilingWindow(Rc<RefCell<TilingWindowInner>>);struct TilingWindowInner {id: Uuid,parent: Option<TilingContainer>,- children: Vec<Container>,+ children: VecDeque<Container>,size_percent: f32,native: NativeWindow,}@@ -32,7 +33,7 @@ impl TilingWindow {let window = TilingWindowInner {id: Uuid::new_v4(),parent: None,- children: Vec::new(),+ children: VecDeque::new(),size_percent: 1.0,native: native_window,};diff --git a/packages/wm/src/workspaces/workspace.rs b/packages/wm/src/workspaces/workspace.rsindex ba3176cb..bd72e023 100644--- a/packages/wm/src/workspaces/workspace.rs+++ b/packages/wm/src/workspaces/workspace.rs@@ -1,5 +1,6 @@use std::{cell::{Ref, RefCell, RefMut},+ collections::VecDeque,rc::Rc,};@@ -22,7 +23,7 @@ pub struct Workspace(Rc<RefCell<WorkspaceInner>>);struct WorkspaceInner {id: Uuid,parent: Option<TilingContainer>,- children: Vec<Container>,+ children: VecDeque<Container>,size_percent: f32,config: WorkspaceConfig,outer_gaps: RectDelta,@@ -33,7 +34,7 @@ impl Workspace {let workspace = WorkspaceInner {id: Uuid::new_v4(),parent: None,- children: Vec::new(),+ children: VecDeque::new(),size_percent: 1.0,config,outer_gaps,