GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
wip
Lars Bergerc3663d1d7c3a
diff --git a/packages/ipc-client/src/lib.rs b/packages/ipc-client/src/lib.rsindex 20f2a2ab..8ed0d3fa 100644--- a/packages/ipc-client/src/lib.rs+++ b/packages/ipc-client/src/lib.rs@@ -7,11 +7,11 @@ pub const DEFAULT_IPC_ADDR: &'static str = "127.0.0.1:6123";pub struct IpcClient {}impl IpcClient {- pub async fn connect() -> Result<()> {+ pub async fn connect() -> Result<Self> {todo!()}- pub async fn send_raw(_message: ArgsOs) -> Result<()> {+ pub async fn send_raw(&self, _message: ArgsOs) -> Result<()> {todo!()}}diff --git a/packages/wm/src/cli.rs b/packages/wm/src/cli.rsindex b079e2ac..4faafac3 100644--- a/packages/wm/src/cli.rs+++ b/packages/wm/src/cli.rs@@ -1,6 +1,3 @@-use std::process;--use anyhow::Result;use clap::{Parser, Subcommand};#[derive(Parser, Debug)]diff --git a/packages/wm/src/containers/container.rs b/packages/wm/src/containers/container.rsindex f733cbc8..e55612bb 100644--- a/packages/wm/src/containers/container.rs+++ b/packages/wm/src/containers/container.rs@@ -1,6 +1,5 @@use std::sync::Arc;-use serde::{Deserialize, Serialize};use uuid::Uuid;use crate::{monitors::Monitor, windows::Window, workspaces::Workspace};@@ -9,7 +8,90 @@ use super::{container_type::ContainerType, RootContainer, SplitContainer,};-#[derive(Debug, Deserialize, Clone, Serialize)]+#[derive(Debug)]+pub enum Container {+ RootContainer(RootContainer),+ Monitor(Monitor),+ Workspace(Workspace),+ SplitContainer(SplitContainer),+ Window(Window),+}++impl Container {+ pub fn inner(&self) -> &InnerContainer {+ match self {+ Self::RootContainer(c) => &c.inner,+ Self::Monitor(c) => &c.inner,+ Self::Workspace(c) => &c.inner,+ Self::SplitContainer(c) => &c.inner,+ Self::Window(c) => &c.inner,+ }+ }++ pub fn inner_mut(&mut self) -> &mut InnerContainer {+ match self {+ Self::RootContainer(c) => &mut c.inner,+ Self::Monitor(c) => &mut c.inner,+ Self::Workspace(c) => &mut c.inner,+ Self::SplitContainer(c) => &mut c.inner,+ Self::Window(c) => &mut c.inner,+ }+ }++ /// Unique identifier for the container.+ fn id(&self) -> Uuid {+ self.inner().id+ }++ pub fn parent(&self) -> Option<Arc<Container>> {+ self.inner().parent+ }++ pub fn set_parent(&mut self, parent: Option<Arc<Container>>) {+ self.inner().parent = parent;+ }++ pub fn children(&self) -> Vec<Arc<Container>> {+ self.inner().children+ }++ pub fn set_children(&self, children: Vec<Arc<Container>>) {+ self.inner().children = children;+ }++ /// Order of which child containers last had focus.+ pub fn child_focus_order(&self) -> Vec<Arc<Container>> {+ self.inner().child_focus_order+ }++ pub fn set_child_focus_order(+ &mut self,+ child_focus_order: Vec<Arc<Container>>,+ ) {+ self.inner().child_focus_order = child_focus_order;+ }++ /// Child container that last had focus.+ pub fn last_focused_child(&self) -> Option<Arc<Container>> {+ self.child_focus_order().get(0).cloned()+ }++ /// Index of this container in parent's child focus order.+ pub fn focus_index(&self) -> u32 {+ match self.inner().parent {+ None => 0,+ Some(p) => p+ .child_focus_order()+ .iter()+ .position(|child| child.id() == self.id())+ .unwrap()+ .try_into()+ .unwrap(),+ }+ }+}++#[derive(Debug)]pub struct InnerContainer {pub id: Uuid,pub parent: Option<Arc<Container>>,@@ -31,15 +113,6 @@ impl InnerContainer {}}-#[derive(Debug)]-pub enum Container {- RootContainer(RootContainer),- Monitor(Monitor),- Workspace(Workspace),- SplitContainer(SplitContainer),- Window(Window),-}-pub trait ContainerVariant {/// Derived container type (eg. `ContainerType::Monitor`).fn r#type(&self) -> ContainerType;diff --git a/packages/wm/src/containers/root_container.rs b/packages/wm/src/containers/root_container.rsindex 24e80f1f..9e3a72bc 100644--- a/packages/wm/src/containers/root_container.rs+++ b/packages/wm/src/containers/root_container.rs@@ -4,7 +4,7 @@ use super::{ContainerVariant, InnerContainer};#[derive(Debug)]pub struct RootContainer {- inner: InnerContainer,+ pub inner: InnerContainer,width: u32,height: u32,x: u32,diff --git a/packages/wm/src/containers/split_container.rs b/packages/wm/src/containers/split_container.rsindex 8f109613..6a4d74bb 100644--- a/packages/wm/src/containers/split_container.rs+++ b/packages/wm/src/containers/split_container.rs@@ -4,7 +4,7 @@ use super::{ContainerVariant, InnerContainer};#[derive(Debug)]pub struct SplitContainer {- inner: InnerContainer,+ pub inner: InnerContainer,width: u32,height: u32,x: u32,diff --git a/packages/wm/src/ipc_server.rs b/packages/wm/src/ipc_server.rsindex 5fe2c2dd..dbed46d4 100644--- a/packages/wm/src/ipc_server.rs+++ b/packages/wm/src/ipc_server.rs@@ -8,8 +8,9 @@ use tokio::{use tokio_tungstenite::accept_async;use tracing::info;-use crate::wm_state::WmState;+use crate::{wm_event::WmEvent, wm_state::WmState};+#[derive(Debug)]pub enum IpcMessage {Monitors,Windows,@@ -19,19 +20,13 @@ pub enum IpcMessage {pub struct IpcServer {message_tx: UnboundedSender<IpcMessage>,- message_rx: UnboundedReceiver<IpcMessage>,+ pub message_rx: UnboundedReceiver<IpcMessage>,}impl IpcServer {- pub fn new() -> Self {- let (message_tx, mut message_rx) = mpsc::unbounded_channel::<i32>();- Self {- message_tx,- message_rx,- }- }+ pub async fn start() -> Result<Self> {+ let (message_tx, message_rx) = mpsc::unbounded_channel::<IpcMessage>();- pub async fn start(&self) -> Result<()> {let server = TcpListener::bind(DEFAULT_IPC_ADDR).await?;while let Ok((stream, _)) = server.accept().await {@@ -46,7 +41,10 @@ impl IpcServer {}}- Ok(())+ Ok(Self {+ message_tx,+ message_rx,+ })}pub async fn stop(&self) {@@ -60,4 +58,8 @@ impl IpcServer {) {todo!()}++ pub async fn process_event(&mut self, event: WmEvent) {+ todo!()+ }}diff --git a/packages/wm/src/main.rs b/packages/wm/src/main.rsindex 44ba045b..9b1bae70 100644--- a/packages/wm/src/main.rs+++ b/packages/wm/src/main.rs@@ -36,44 +36,49 @@ async fn main() {}_ => {let args = std::env::args_os();- IpcClient::new().send_raw(args).unwrap()+ IpcClient::connect()+ .await+ .unwrap()+ .send_raw(args)+ .await+ .unwrap()}}}-async fn start_wm(config_path: Option<&str>) {+async fn start_wm(config_path: Option<String>) -> Result<()> {// Parse and validate user config.- let user_config = UserConfig::read(config_path).await;+ let user_config = UserConfig::read(config_path).await?;- let event_listener = EventListener::new().start().await;- let ipc_server = IpcServer::new().start().await;+ let mut event_listener = EventListener::start().await?;+ let mut ipc_server = IpcServer::start().await?;// Start watcher process for restoring hidden windows on crash.start_watcher_process()?;- let wm = WindowManager::new(user_config).start().await;+ let mut wm = WindowManager::start(user_config).await?;loop {tokio::select! {Some(event) = event_listener.event_rx.recv() => {- info!("Received platform event: {}", event);+ info!("Received platform event: {:?}", event);wm.process_event(event).await},Some(wm_event) = wm.event_rx.recv() => {- info!("Received WM event: {}", wm_event);+ info!("Received WM event: {:?}", wm_event);ipc_server.process_event(wm_event).await},Some(ipc_message) = ipc_server.message_rx.recv() => {- info!("Received IPC message: {}", ipc_message);+ info!("Received IPC message: {:?}", ipc_message);ipc_server.process_message(ipc_message, wm.state).await},}}}-async fn start_watcher_process() -> Result<Command> {+fn start_watcher_process() -> Result<Command> {let watcher_path = env::var_os("CARGO_BIN_FILE_WATCHER").context("Failed to resolve path to watcher process.")?;- Command::new(watcher_path);+ Ok(Command::new(watcher_path))}diff --git a/packages/wm/src/monitors/monitor.rs b/packages/wm/src/monitors/monitor.rsindex 0057e3b8..ae2724ea 100644--- a/packages/wm/src/monitors/monitor.rs+++ b/packages/wm/src/monitors/monitor.rs@@ -2,7 +2,7 @@ use crate::containers::{ContainerType, ContainerVariant, InnerContainer};#[derive(Debug)]pub struct Monitor {- inner: InnerContainer,+ pub inner: InnerContainer,device_name: String,width: u32,height: u32,diff --git a/packages/wm/src/user_config.rs b/packages/wm/src/user_config.rsindex fc6df728..919396c4 100644--- a/packages/wm/src/user_config.rs+++ b/packages/wm/src/user_config.rs@@ -1,5 +1,6 @@use std::path::PathBuf;+use anyhow::{Context, Result};use serde::{Deserialize, Deserializer};use tokio::fs;@@ -119,10 +120,10 @@ const SAMPLE_CONFIG: &str =include_str!("../../../resources/sample-config.yaml");impl UserConfig {- pub async fn read(config_path: Option<&str>) -> Self {+ pub async fn read(config_path: Option<String>) -> Result<Self> {let default_config_path = home::home_dir().context("Unable to get home directory.")?- .resolve(".glzr/glazewm/config.yaml");+ .join(".glzr/glazewm/config.yaml");let config_path = match config_path {Some(val) => PathBuf::from(val),@@ -143,9 +144,11 @@ impl UserConfig {}let config_str = fs::read_to_string(&config_path)- .context("Unable to read config file.");+ .await+ .context("Unable to read config file.")?;- serde_yaml::from_str(config_str)+ let parsed_config = serde_yaml::from_str(&config_str)?;+ Ok(parsed_config)}fn create_from_sample() -> Self {diff --git a/packages/wm/src/windows/window.rs b/packages/wm/src/windows/window.rsindex a75b507f..cab515aa 100644--- a/packages/wm/src/windows/window.rs+++ b/packages/wm/src/windows/window.rs@@ -2,7 +2,7 @@ use crate::containers::{ContainerType, ContainerVariant, InnerContainer};#[derive(Debug)]pub struct Window {- inner: InnerContainer,+ pub inner: InnerContainer,width: u32,height: u32,x: u32,diff --git a/packages/wm/src/wm.rs b/packages/wm/src/wm.rsindex a644c9a1..c3956e62 100644--- a/packages/wm/src/wm.rs+++ b/packages/wm/src/wm.rs@@ -1,23 +1,27 @@+use anyhow::Result;+use tokio::sync::mpsc::{self, UnboundedReceiver};use wineventhook::WindowEvent;-use crate::{user_config::UserConfig, wm_state::WmState};+use crate::{+ user_config::UserConfig, wm_event::WmEvent, wm_state::WmState,+};pub struct WindowManager {- state: WmState,+ pub event_rx: UnboundedReceiver<WmEvent>,+ pub state: WmState,}impl WindowManager {- pub fn new(user_config: UserConfig) -> Self {- Self {- state: WmState::new(user_config),- }- }+ pub async fn start(user_config: UserConfig) -> Result<Self> {+ let (event_tx, event_rx) = mpsc::unbounded_channel();- pub fn init(&mut self) {- todo!()+ Ok(Self {+ event_rx,+ state: WmState::new(user_config),+ })}- pub fn process_event(event: WindowEvent) {+ pub async fn process_event(&mut self, event: WindowEvent) {todo!()}}diff --git a/packages/wm/src/wm_event.rs b/packages/wm/src/wm_event.rsindex 81d3ffb2..f58849a7 100644--- a/packages/wm/src/wm_event.rs+++ b/packages/wm/src/wm_event.rs@@ -1,4 +1,3 @@-use serde::{Deserialize, Serialize};use uuid::Uuid;use crate::{@@ -6,8 +5,7 @@ use crate::{containers::Container,};-#[derive(Debug, Deserialize, Clone, Serialize)]-#[serde(tag = "type", rename_all = "snake_case")]+#[derive(Debug)]pub enum WmEvent {BindingModeChanged {new_binding_mode: String,diff --git a/packages/wm/src/wm_state.rs b/packages/wm/src/wm_state.rsindex b74ee4c9..81880c7c 100644--- a/packages/wm/src/wm_state.rs+++ b/packages/wm/src/wm_state.rs@@ -39,27 +39,27 @@ impl WmState {/// Get the currently focused container. This can either be a `Window` or/// a `Workspace` without any descendant windows.- pub fn focused_container(&self) -> Arc<Container> {- self- .root_container- .last_focused_descendant()- .unwrap()- .clone()- }+ // pub fn focused_container(&self) -> Arc<Container> {+ // self+ // .root_container+ // .last_focused_descendant()+ // .unwrap()+ // .clone()+ // }- /// Whether a tiling or floating container is currently focused.- pub fn focus_mode(&self) -> FocusMode {- match self.focused_container().r#type() {- ContainerType::FloatingWindow => FocusMode::Floating,- _ => FocusMode::Tiling,- }- }+ // /// Whether a tiling or floating container is currently focused.+ // pub fn focus_mode(&self) -> FocusMode {+ // match self.focused_container().r#type() {+ // ContainerType::FloatingWindow => FocusMode::Floating,+ // _ => FocusMode::Tiling,+ // }+ // }- pub fn container_by_id(&self, id: Uuid) -> Option<Arc<Container>> {- self- .root_container- .self_and_descendants()- .into_iter()- .find(|container| container.id() == id)- }+ // pub fn container_by_id(&self, id: Uuid) -> Option<Arc<Container>> {+ // self+ // .root_container+ // .self_and_descendants()+ // .into_iter()+ // .find(|container| container.id() == id)+ // }}diff --git a/packages/wm/src/workspaces/workspace.rs b/packages/wm/src/workspaces/workspace.rsindex cce1b515..761a9271 100644--- a/packages/wm/src/workspaces/workspace.rs+++ b/packages/wm/src/workspaces/workspace.rs@@ -5,7 +5,7 @@ use crate::{#[derive(Debug)]pub struct Workspace {- inner: InnerContainer,+ pub inner: InnerContainer,name: String,display_name: String,keep_alive: bool,