Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat: add config changes channel

Lars Berger075f4c791151
diff --git a/packages/wm/src/common/platform/event_listener.rs b/packages/wm/src/common/platform/event_listener.rs
index b4e7a90b..154e0c42 100644
--- a/packages/wm/src/common/platform/event_listener.rs
+++ b/packages/wm/src/common/platform/event_listener.rs
@@ -1,7 +1,14 @@
+use std::sync::Arc;
+
use anyhow::Result;
-use tokio::sync::mpsc::{self, UnboundedReceiver};
+use tokio::sync::{
+ mpsc::{self, UnboundedReceiver},
+ Mutex,
+};
use wineventhook::{EventFilter, WindowEvent, WindowEventHook};
+use crate::user_config::UserConfig;
+
pub enum PlatformEvent {
DisplaySettingsChanged,
MouseMove,
@@ -17,18 +24,29 @@ pub enum PlatformEvent {
}
pub struct EventListener {
+ config: Arc<Mutex<UserConfig>>,
+ config_changes_rx: UnboundedReceiver<UserConfig>,
pub event_rx: UnboundedReceiver<WindowEvent>,
hook: WindowEventHook,
}
impl EventListener {
/// Start listening for platform events.
- pub async fn start() -> Result<Self> {
+ pub async fn start(
+ config: Arc<Mutex<UserConfig>>,
+ config_changes_rx: UnboundedReceiver<UserConfig>,
+ ) -> Result<Self> {
let (event_tx, event_rx) = mpsc::unbounded_channel();
+
let hook =
WindowEventHook::hook(EventFilter::default(), event_tx).await?;
- Ok(Self { event_rx, hook })
+ Ok(Self {
+ config,
+ config_changes_rx,
+ event_rx,
+ hook,
+ })
}
}
diff --git a/packages/wm/src/main.rs b/packages/wm/src/main.rs
index 57e8fc1c..7934cea8 100644
--- a/packages/wm/src/main.rs
+++ b/packages/wm/src/main.rs
@@ -1,4 +1,4 @@
-use std::env;
+use std::{env, sync::Arc};
use anyhow::{Context, Result};
use clap::Parser;
@@ -6,7 +6,10 @@ use common::platform::EventListener;
use ipc_client::IpcClient;
use ipc_server::IpcServer;
-use tokio::process::Command;
+use tokio::{
+ process::Command,
+ sync::{mpsc, Mutex},
+};
use tracing::info;
use user_config::UserConfig;
use wm::WindowManager;
@@ -48,15 +51,18 @@ async fn main() {
async fn start_wm(config_path: Option<String>) -> Result<()> {
// Parse and validate user config.
- let user_config = UserConfig::read(config_path).await?;
+ let config = Arc::new(Mutex::new(UserConfig::read(config_path).await?));
+ let (config_changes_tx, config_changes_rx) =
+ mpsc::unbounded_channel::<UserConfig>();
- let mut event_listener = EventListener::start().await?;
+ let mut event_listener =
+ EventListener::start(config.clone(), config_changes_rx).await?;
let mut ipc_server = IpcServer::start().await?;
// Start watcher process for restoring hidden windows on crash.
start_watcher_process()?;
- let mut wm = WindowManager::start(user_config).await?;
+ let mut wm = WindowManager::start(config, config_changes_tx).await?;
loop {
let wm_state = wm.state.clone();
diff --git a/packages/wm/src/user_config.rs b/packages/wm/src/user_config.rs
index 919396c4..561dc3b3 100644
--- a/packages/wm/src/user_config.rs
+++ b/packages/wm/src/user_config.rs
@@ -2,7 +2,10 @@ use std::path::PathBuf;
use anyhow::{Context, Result};
use serde::{Deserialize, Deserializer};
-use tokio::fs;
+use tokio::{
+ fs,
+ sync::mpsc::{self, UnboundedReceiver},
+};
use crate::{
common::{LengthValue, RectDelta},
diff --git a/packages/wm/src/wm.rs b/packages/wm/src/wm.rs
index 8995eda6..10e5b7eb 100644
--- a/packages/wm/src/wm.rs
+++ b/packages/wm/src/wm.rs
@@ -1,7 +1,10 @@
use std::sync::Arc;
use anyhow::Result;
-use tokio::sync::mpsc::{self, UnboundedReceiver};
+use tokio::sync::{
+ mpsc::{self, UnboundedReceiver, UnboundedSender},
+ Mutex,
+};
use wineventhook::WindowEvent;
use crate::{
@@ -14,12 +17,15 @@ pub struct WindowManager {
}
impl WindowManager {
- pub async fn start(user_config: UserConfig) -> Result<Self> {
+ pub async fn start(
+ config: Arc<Mutex<UserConfig>>,
+ config_changes_tx: UnboundedSender<UserConfig>,
+ ) -> Result<Self> {
let (event_tx, event_rx) = mpsc::unbounded_channel();
Ok(Self {
event_rx,
- state: Arc::new(WmState::new(user_config)),
+ state: Arc::new(WmState::new(config)),
})
}
diff --git a/packages/wm/src/wm_state.rs b/packages/wm/src/wm_state.rs
index a82f0377..b6f46151 100644
--- a/packages/wm/src/wm_state.rs
+++ b/packages/wm/src/wm_state.rs
@@ -1,4 +1,5 @@
use std::sync::Arc;
+use tokio::sync::Mutex;
use uuid::Uuid;
use crate::{
@@ -23,17 +24,17 @@ pub struct WmState {
active_binding_mode: Option<String>,
/// Parsed user config.
- user_config: UserConfig,
+ config: Arc<Mutex<UserConfig>>,
}
impl WmState {
- pub fn new(user_config: UserConfig) -> Self {
+ pub fn new(config: Arc<Mutex<UserConfig>>) -> Self {
Self {
root_container: RootContainer::new(),
containers_to_redraw: Vec::new(),
has_pending_focus_sync: false,
active_binding_mode: None,
- user_config,
+ config,
}
}