GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
wip
Lars Bergereb4cc93244ce
diff --git a/packages/wm/src/common/platform/native_monitor.rs b/packages/wm/src/common/platform/native_monitor.rsindex a14361b9..4cc915d7 100644--- a/packages/wm/src/common/platform/native_monitor.rs+++ b/packages/wm/src/common/platform/native_monitor.rs@@ -5,3 +5,21 @@ pub struct NativeMonitor {pub x: u32,pub y: u32,}++impl NativeMonitor {+ pub fn new(+ device_name: String,+ width: u32,+ height: u32,+ x: u32,+ y: u32,+ ) -> Self {+ Self {+ device_name,+ width,+ height,+ x,+ y,+ }+ }+}diff --git a/packages/wm/src/common/platform/native_window.rs b/packages/wm/src/common/platform/native_window.rsindex 9d91a1f5..67d601e0 100644--- a/packages/wm/src/common/platform/native_window.rs+++ b/packages/wm/src/common/platform/native_window.rs@@ -21,38 +21,38 @@ impl NativeWindow {}}- fn title(&self) -> Result<String> {- match self.title {- Some(title) => Ok(title.borrow().clone()),- None => {- let title = windows_api::window_title_by_handle()?;- self.title = Some(RefCell::new(title));- Ok(title)- }- }- }+ // fn title(&self) -> Result<String> {+ // match self.title {+ // Some(title) => Ok(title.borrow().clone()),+ // None => {+ // let title = windows_api::window_title_by_handle()?;+ // self.title = Some(RefCell::new(title));+ // Ok(title)+ // }+ // }+ // }- fn process_name(&self) -> Result<String> {- match self.process_name {- Some(process_name) => Ok(process_name.borrow().clone()),- None => {- let process_name = windows_api::process_name_by_handle()?;- self.process_name = Some(RefCell::new(process_name));- Ok(process_name)- }- }- }+ // fn process_name(&self) -> Result<String> {+ // match self.process_name {+ // Some(process_name) => Ok(process_name.borrow().clone()),+ // None => {+ // let process_name = windows_api::process_name_by_handle()?;+ // self.process_name = Some(RefCell::new(process_name));+ // Ok(process_name)+ // }+ // }+ // }- fn class_name(&self) -> Result<String> {- match self.class_name {- Some(class_name) => Ok(class_name.borrow().clone()),- None => {- let class_name = windows_api::class_name_by_handle()?;- self.class_name = Some(RefCell::new(class_name));- Ok(class_name)- }- }- }+ // fn class_name(&self) -> Result<String> {+ // match self.class_name {+ // Some(class_name) => Ok(class_name.borrow().clone()),+ // None => {+ // let class_name = windows_api::class_name_by_handle()?;+ // self.class_name = Some(RefCell::new(class_name));+ // Ok(class_name)+ // }+ // }+ // }pub fn is_visible(&self) -> bool {todo!()@@ -78,11 +78,11 @@ impl NativeWindow {todo!()}- fn window_styles(&self) -> Vec<WindowStyle> {- todo!()- }+ // fn window_styles(&self) -> Vec<WindowStyle> {+ // todo!()+ // }- fn window_styles_ex(&self) -> Vec<WindowStyleEx> {- todo!()- }+ // fn window_styles_ex(&self) -> Vec<WindowStyleEx> {+ // todo!()+ // }}diff --git a/packages/wm/src/common/platform/platform.rs b/packages/wm/src/common/platform/platform.rsindex f1801812..7b067e34 100644--- a/packages/wm/src/common/platform/platform.rs+++ b/packages/wm/src/common/platform/platform.rs@@ -14,11 +14,11 @@ pub struct Platform;impl Platform {pub fn monitors() -> Result<Vec<NativeMonitor>> {- Ok(())+ todo!()}pub fn manageable_windows() -> Result<Vec<NativeWindow>> {- Ok(())+ todo!()}pub async fn new_event_listener(diff --git a/packages/wm/src/containers/container.rs b/packages/wm/src/containers/container.rsindex a2ea9667..6b0d5bc3 100644--- a/packages/wm/src/containers/container.rs+++ b/packages/wm/src/containers/container.rs@@ -15,6 +15,32 @@ use crate::{use super::{ContainerType, RootContainer, SplitContainer};#[derive(Debug)]+// TODO: Consider renaming to ContainerRelations and removing `container_type`.+// Instead create a `CommonContainer` trait that all containers implement (including+// the `Container` enum itself). Then change `relations` to be private and only+// accessible through `CommonContainer` trait methods.+// pub trait CommonContainer {+// id() -> Uuid;+// r#type() -> ContainerType;+// relations() -> ContainerRelations;+// }++// It's possible to get `InnerContainer` to point to the outer via `Rc::new_cyclic`+// eg. https://stackoverflow.com/questions/67525645/constructor-for-a-structure-with-weak-reference-to-its-owner++// ----------++// If RcTree was used instead, could do:++/// Strong reference to an element in the SVG tree.+// pub type Node = rctree::Node<ContainerProperties>;++/// Weak reference to an element in the SVG tree.+// pub type WeakNode = rctree::WeakNode<ContainerProperties>;++// Could do `borrow_monitor` to get derived type.+// Ref: https://github.com/GNOME/librsvg/blob/d3c3269fa54c9b3fb60fcfdba29ff97e2029f600/rsvg/src/node.rs#L223+pub struct InnerContainer {pub id: Uuid,container_type: ContainerType,@@ -38,9 +64,13 @@ impl InnerContainer {self.container_type}- pub fn insert_child(&mut self, target_index: usize, child: Container) {- child.inner_mut().parent = Some(Rc::downgrade(&self));- self.children.insert(target_index, child);+ pub fn insert_child(&self, target_index: usize, child: Container) {+ child.inner_mut().parent = Some(Weak::new(RefCell::new(self)));++ self+ .children+ .insert(target_index, Rc::new(RefCell::new(child)));+self.child_focus_order.push_front(child.id());}@@ -48,7 +78,7 @@ impl InnerContainer {if let Some(index) = self.children.iter()- .position(|child| child.id() == child_id)+ .position(|child| child.borrow().id() == child_id){self.children.remove(index);self.child_focus_order.retain(|id| *id != child_id);@@ -104,57 +134,57 @@ impl Container {}}- /// Height of the container. Implementation varies by container type.- pub fn height(&self) -> u32 {- match self.value {- Self::Monitor(c) => c.height,- Self::Workspace(c) => c.height,- Self::SplitContainer(c) => c.height(),- Self::Window(c) => c.height(),- _ => 0,- }- }+ // /// Height of the container. Implementation varies by container type.+ // pub fn height(&self) -> u32 {+ // match self.value {+ // Self::Monitor(c) => c.height,+ // Self::Workspace(c) => c.height,+ // Self::SplitContainer(c) => c.height(),+ // Self::Window(c) => c.height(),+ // _ => 0,+ // }+ // }- /// Width of the container. Implementation varies by container type.- pub fn width(&self) -> u32 {- match self.value {- Self::Monitor(c) => c.width,- Self::Workspace(c) => c.width,- Self::SplitContainer(c) => c.width(),- Self::Window(c) => c.width(),- _ => 0,- }- }+ // /// Width of the container. Implementation varies by container type.+ // pub fn width(&self) -> u32 {+ // match self.value {+ // Self::Monitor(c) => c.width,+ // Self::Workspace(c) => c.width,+ // Self::SplitContainer(c) => c.width(),+ // Self::Window(c) => c.width(),+ // _ => 0,+ // }+ // }- /// X-coordinate of the container. Implementation varies by container type.- pub fn x(&self) -> u32 {- match self.value {- Self::Monitor(c) => c.x,- Self::Workspace(c) => c.x,- Self::SplitContainer(c) => c.x(),- Self::Window(c) => c.x(),- _ => 0,- }- }+ // /// X-coordinate of the container. Implementation varies by container type.+ // pub fn x(&self) -> u32 {+ // match self.value {+ // Self::Monitor(c) => c.x,+ // Self::Workspace(c) => c.x,+ // Self::SplitContainer(c) => c.x(),+ // Self::Window(c) => c.x(),+ // _ => 0,+ // }+ // }- /// Y-coordinate of the container. Implementation varies by container type.- pub fn y(&self) -> u32 {- match self.value {- Self::Monitor(c) => c.y,- Self::Workspace(c) => c.y,- Self::SplitContainer(c) => c.y(),- Self::Window(c) => c.y(),- _ => 0,- }- }+ // /// Y-coordinate of the container. Implementation varies by container type.+ // pub fn y(&self) -> u32 {+ // match self.value {+ // Self::Monitor(c) => c.y,+ // Self::Workspace(c) => c.y,+ // Self::SplitContainer(c) => c.y(),+ // Self::Window(c) => c.y(),+ // _ => 0,+ // }+ // }- /// Whether the container can be tiled.- pub fn can_tile(&self) -> bool {- match self.value {- Self::Window(c) => c.state == WindowState::Tiling,- _ => true,- }- }+ // /// Whether the container can be tiled.+ // pub fn can_tile(&self) -> bool {+ // match self.value {+ // Self::Window(c) => c.state == WindowState::Tiling,+ // _ => true,+ // }+ // }/// Unique identifier for the container.fn id(&self) -> Uuid {diff --git a/packages/wm/src/monitors/monitor.rs b/packages/wm/src/monitors/monitor.rsindex 583c17e0..fec6531c 100644--- a/packages/wm/src/monitors/monitor.rs+++ b/packages/wm/src/monitors/monitor.rs@@ -14,7 +14,7 @@ pub struct Monitor {}impl Monitor {- pub fn from_native(native_monitor: NativeMonitor) -> Self {+ pub fn new(native_monitor: NativeMonitor) -> Self {Self {inner: InnerContainer::new(ContainerType::Monitor),device_name: native_monitor.device_name,diff --git a/packages/wm/src/wm_event.rs b/packages/wm/src/wm_event.rsindex b6846cca..84967d5d 100644--- a/packages/wm/src/wm_event.rs+++ b/packages/wm/src/wm_event.rs@@ -5,53 +5,65 @@ use crate::{containers::Container,};+#[derive(Debug)]pub struct BindingModeChangedEvent {pub new_binding_mode: String,}+#[derive(Debug)]pub struct FocusChangedEvent {pub focused_container: Container,}+#[derive(Debug)]pub struct FocusedContainerMovedEvent {pub focused_container: Container,}+#[derive(Debug)]pub struct MonitorAddedEvent {pub added_monitor: Container,}+#[derive(Debug)]pub struct MonitorRemovedEvent {pub removed_id: Uuid,pub removed_device_name: String,}+#[derive(Debug)]pub struct NativeFocusSyncedEvent {pub focused_container: Container,}+#[derive(Debug)]pub struct TilingDirectionChangedEvent {pub new_tiling_direction: TilingDirection,}+#[derive(Debug)]pub struct WindowManagedEvent {pub managed_window: Container,}+#[derive(Debug)]pub struct WindowUnmanagedEvent {pub unmanaged_id: Uuid,pub unmanaged_handle: WindowHandle,}+#[derive(Debug)]pub struct WorkspaceActivatedEvent {pub activated_workspace: Container,}+#[derive(Debug)]pub struct WorkspaceDeactivatedEvent {pub deactivated_id: Uuid,pub deactivated_name: String,}+#[derive(Debug)]pub struct WorkingAreaResizedEvent {pub affected_monitor: Container,}diff --git a/packages/wm/src/wm_state.rs b/packages/wm/src/wm_state.rsindex 52a09d38..18a65d16 100644--- a/packages/wm/src/wm_state.rs+++ b/packages/wm/src/wm_state.rs@@ -7,10 +7,11 @@ use std::{use anyhow::Result;use tokio::sync::{mpsc::UnboundedSender, Mutex};+use tracing::warn;use uuid::Uuid;use crate::{- common::FocusMode,+ common::{platform::NativeMonitor, FocusMode},containers::{Container, ContainerType, RootContainer},monitors::Monitor,user_config::{BindingModeConfig, UserConfig},@@ -58,8 +59,9 @@ impl WmState {}pub fn add_monitor(&mut self) {- // self.root_container.add_monitor(monitor_id);- let monitor = Monitor::new(String::from("aaa"), 0, 0, 0, 0);+ let monitor =+ Monitor::new(NativeMonitor::new(String::from("aaa"), 0, 0, 0, 0));+self.root_container.inner@@ -69,7 +71,11 @@ impl WmState {}pub fn emit_event(&self, event: WmEvent) -> Result<()> {- self.event_tx.send(event)+ if let Err(err) = self.event_tx.send(event) {+ warn!("Failed to send event: {}", err);+ }++ Ok(())}// Get the currently focused container. This can either be a `Window` or