GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: add root container and monitor structs
Lars Berger054b0b9ea4e0
diff --git a/packages/wm/src/common/mod.rs b/packages/wm/src/common/mod.rsindex b386c534..3f5a86f4 100644--- a/packages/wm/src/common/mod.rs+++ b/packages/wm/src/common/mod.rs@@ -1,3 +1,5 @@+mod rect_delta;mod units;+pub use rect_delta::*;pub use units::*;diff --git a/packages/wm/src/common/rect_delta.rs b/packages/wm/src/common/rect_delta.rsnew file mode 100644index 00000000..4e25c737--- /dev/null+++ b/packages/wm/src/common/rect_delta.rs@@ -0,0 +1,24 @@+pub struct RectDelta {+ /// The diff in x-coordinates of the upper-left corner of the rectangle.+ left: i32,++ /// The diff in y-coordinates of the upper-left corner of the rectangle.+ top: i32,++ /// The diff in x-coordinates of the lower-right corner of the rectangle.+ right: i32,++ /// The diff in y-coordinates of the lower-right corner of the rectangle.+ bottom: i32,+}++impl RectDelta {+ pub fn new(left: i32, top: i32, right: i32, bottom: i32) -> Self {+ Self {+ left,+ top,+ right,+ bottom,+ }+ }+}diff --git a/packages/wm/src/containers/container.rs b/packages/wm/src/containers/container.rsindex 7799bd47..2811701c 100644--- a/packages/wm/src/containers/container.rs+++ b/packages/wm/src/containers/container.rs@@ -1,3 +1,5 @@+use std::sync::Arc;+use uuid::Uuid;use super::container_type::ContainerType;@@ -6,7 +8,7 @@ pub trait Container {/// A unique identifier for the container.fn id(&self) -> Uuid;- /// Derived container type (eg. `ContainerType.Monitor`).+ /// Derived container type (eg. `ContainerType::Monitor`).fn r#type(&self) -> ContainerType;fn height(&self) -> u32;@@ -14,14 +16,23 @@ pub trait Container {fn x(&self) -> u32;fn y(&self) -> u32;- fn parent(&self) -> Box<dyn Container>;- fn children(&self) -> Vec<Box<dyn Container>>;+ fn parent(&self) -> Option<Arc<dyn Container>>;+ fn set_parent(&mut self, parent: Arc<dyn Container>) -> ();- /// The order of which child containers last had focus.- fn child_focus_order(&self) -> Vec<Box<dyn Container>>;+ fn children(&self) -> Vec<Arc<dyn Container>>;+ fn set_children(&self, children: Vec<Arc<dyn Container>>) -> ();- // /// The child container that last had focus.- // public Container LastFocusedChild => ChildFocusOrder.ElementAtOrDefault(0);+ /// The order of which child containers last had focus.+ fn child_focus_order(&self) -> Vec<Arc<dyn Container>>;+ fn set_child_focus_order(+ &self,+ child_focus_order: Vec<Arc<dyn Container>>,+ ) -> ();++ /// The child container that last had focus.+ fn last_focused_child(&self) -> Option<Arc<dyn Container>> {+ self.child_focus_order().get(0).cloned()+ }// /// Index of this container in parent's child focus order.// public int FocusIndex => this is RootContainer ? 0 : Parent.ChildFocusOrder.IndexOf(this);diff --git a/packages/wm/src/containers/mod.rs b/packages/wm/src/containers/mod.rsindex f64f25d3..76a008c8 100644--- a/packages/wm/src/containers/mod.rs+++ b/packages/wm/src/containers/mod.rs@@ -1,5 +1,7 @@mod container;mod container_type;+mod root_container;pub use container::*;pub use container_type::*;+pub use root_container::*;diff --git a/packages/wm/src/containers/root_container.rs b/packages/wm/src/containers/root_container.rsnew file mode 100644index 00000000..03cc6160--- /dev/null+++ b/packages/wm/src/containers/root_container.rs@@ -0,0 +1,85 @@+use std::sync::Arc;++use uuid::Uuid;++use crate::{+ containers::{Container, ContainerType},+ workspaces::Workspace,+};++pub struct RootContainer {+ id: Uuid,+ children: Vec<Arc<Workspace>>,+ child_focus_order: Vec<Arc<Workspace>>,+ width: u32,+ height: u32,+ x: u32,+ y: u32,+}++impl RootContainer {+ pub fn new(width: u32, height: u32, x: u32, y: u32) -> Self {+ Self {+ id: Uuid::new_v4(),+ children: Vec::new(),+ child_focus_order: Vec::new(),+ width,+ height,+ x,+ y,+ }+ }+}++impl Container for RootContainer {+ fn id(&self) -> Uuid {+ self.id+ }++ fn r#type(&self) -> ContainerType {+ ContainerType::RootContainer+ }++ fn height(&self) -> u32 {+ self.height+ }++ fn width(&self) -> u32 {+ self.width+ }++ fn x(&self) -> u32 {+ self.x+ }++ fn y(&self) -> u32 {+ self.y+ }++ fn parent(&self) -> Arc<dyn Container> {+ todo!()+ }++ fn children(&self) -> Vec<Arc<dyn Container>> {+ self.children+ }++ fn child_focus_order(&self) -> Vec<Arc<dyn Container>> {+ self.child_focus_order+ }++ fn set_parent(&mut self, parent: Arc<dyn Container>) -> () {+ self.parent = parent+ }++ fn set_children(&self, children: Vec<Arc<dyn Container>>) -> () {+ self.children = children+ }++ fn set_child_focus_order(+ &self,+ child_focus_order: Vec<Arc<dyn Container>>,+ ) -> () {+ self.child_focus_order = child_focus_order+ }+}diff --git a/packages/wm/src/containers/tiling_container.rs b/packages/wm/src/containers/tiling_container.rsindex 2d2fad3a..45faf7cf 100644--- a/packages/wm/src/containers/tiling_container.rs+++ b/packages/wm/src/containers/tiling_container.rs@@ -1,4 +1,4 @@pub trait TilingContainer {- fn is_tiling_active(&self) -> bool;+ fn can_tile(&self) -> bool;fn size_percentage(&self) -> f32;}diff --git a/packages/wm/src/main.rs b/packages/wm/src/main.rsindex e755dfc0..24d49827 100644--- a/packages/wm/src/main.rs+++ b/packages/wm/src/main.rs@@ -1,12 +1,14 @@use clap::Parser;+use common::RectDelta;use ipc_client;+use workspaces::Workspace;use crate::cli::{Cli, CliCommand};mod cli;mod common;mod containers;-// mod monitors;+mod monitors;// mod user_config;// mod windows;mod wm_state;@@ -17,7 +19,14 @@ async fn main() {let cli = Cli::parse();match cli.command {- CliCommand::Start { config } => {}+ CliCommand::Start { config } => {+ let workspace = Workspace::new(+ "name".into(),+ "display_name".into(),+ true,+ RectDelta::new(1, 2, 3, 4),+ );+ }_ => {let args = std::env::args_os();ipc_client::send_raw(args).unwrap()diff --git a/packages/wm/src/monitors/mod.rs b/packages/wm/src/monitors/mod.rsnew file mode 100644index 00000000..407205d6--- /dev/null+++ b/packages/wm/src/monitors/mod.rs@@ -0,0 +1,3 @@+mod monitor;++pub use monitor::*;diff --git a/packages/wm/src/monitors/monitor.rs b/packages/wm/src/monitors/monitor.rsnew file mode 100644index 00000000..def35e9f--- /dev/null+++ b/packages/wm/src/monitors/monitor.rs@@ -0,0 +1,96 @@+use std::sync::Arc;++use uuid::Uuid;++use crate::{+ containers::{Container, ContainerType, RootContainer},+ workspaces::Workspace,+};++pub struct Monitor {+ id: Uuid,+ parent: Arc<RootContainer>,+ children: Vec<Arc<Workspace>>,+ child_focus_order: Vec<Arc<Workspace>>,+ device_name: String,+ width: u32,+ height: u32,+ x: u32,+ y: u32,+}++impl Monitor {+ pub fn new(+ parent: RootContainer,+ device_name: String,+ width: u32,+ height: u32,+ x: u32,+ y: u32,+ ) -> Self {+ Self {+ id: Uuid::new_v4(),+ parent: Arc::new(parent),+ children: Vec::new(),+ child_focus_order: Vec::new(),+ device_name,+ width,+ height,+ x,+ y,+ }+ }+}++impl Container for Monitor {+ fn id(&self) -> Uuid {+ self.id+ }++ fn r#type(&self) -> ContainerType {+ ContainerType::Monitor+ }++ fn height(&self) -> u32 {+ self.height+ }++ fn width(&self) -> u32 {+ self.width+ }++ fn x(&self) -> u32 {+ self.x+ }++ fn y(&self) -> u32 {+ self.y+ }++ fn parent(&self) -> Arc<dyn Container> {+ self.parent+ }++ fn children(&self) -> Vec<Arc<dyn Container>> {+ self.children+ }++ fn child_focus_order(&self) -> Vec<Arc<dyn Container>> {+ self.child_focus_order+ }++ fn set_parent(&mut self, parent: Arc<dyn Container>) -> () {+ self.parent = parent+ }++ fn set_children(&self, children: Vec<Arc<dyn Container>>) -> () {+ self.children = children+ }++ fn set_child_focus_order(+ &self,+ child_focus_order: Vec<Arc<dyn Container>>,+ ) -> () {+ self.child_focus_order = child_focus_order+ }+}diff --git a/packages/wm/src/workspaces/workspace.rs b/packages/wm/src/workspaces/workspace.rsindex bf2f70e7..41370bbf 100644--- a/packages/wm/src/workspaces/workspace.rs+++ b/packages/wm/src/workspaces/workspace.rs@@ -1,9 +1,16 @@+use std::sync::Arc;+use uuid::Uuid;-use crate::containers::{Container, ContainerType};+use crate::{+ common::RectDelta,+ containers::{Container, ContainerType},+ monitors::Monitor,+};pub struct Workspace {id: Uuid,+ parent: Monitor,name: String,display_name: String,keep_alive: bool,@@ -16,6 +23,7 @@ impl Workspace {display_name: String,keep_alive: bool,outer_gaps: RectDelta,+ parent: Monitor,) -> Self {Self {id: Uuid::new_v4(),@@ -23,6 +31,7 @@ impl Workspace {display_name,keep_alive,outer_gaps,+ parent,}}}@@ -52,15 +61,33 @@ impl Container for Workspace {todo!()}- fn parent(&self) -> Box<dyn Container> {+ fn parent(&self) -> Arc<dyn Container> {+ todo!()+ }++ fn children(&self) -> Vec<Arc<dyn Container>> {+ todo!()+ }++ fn child_focus_order(&self) -> Vec<Arc<dyn Container>> {+ todo!()+ }++ fn set_parent(&mut self, parent: std::sync::Arc<dyn Container>) -> () {todo!()}- fn children(&self) -> Vec<Box<dyn Container>> {+ fn set_children(+ &self,+ children: Vec<std::sync::Arc<dyn Container>>,+ ) -> () {todo!()}- fn child_focus_order(&self) -> Vec<Box<dyn Container>> {+ fn set_child_focus_order(+ &self,+ child_focus_order: Vec<std::sync::Arc<dyn Container>>,+ ) -> () {todo!()}}