Skip to content

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

feat: pass down user config to event listener

Lars Berger9b8a6bf29d9a
diff --git a/packages/wm/src/common/direction.rs b/packages/wm/src/common/direction.rs
index 0c0d9453..051f3880 100644
--- a/packages/wm/src/common/direction.rs
+++ b/packages/wm/src/common/direction.rs
@@ -1,6 +1,6 @@
use anyhow::{bail, Result};
-#[derive(Debug)]
+#[derive(Clone, Debug)]
pub enum Direction {
Left,
Right,
diff --git a/packages/wm/src/common/platform/event_listener.rs b/packages/wm/src/common/platform/event_listener.rs
index 8c10e42d..892cb929 100644
--- a/packages/wm/src/common/platform/event_listener.rs
+++ b/packages/wm/src/common/platform/event_listener.rs
@@ -27,7 +27,6 @@ pub enum PlatformEvent {
}
pub struct EventListener {
- config: Arc<Mutex<UserConfig>>,
pub event_rx: UnboundedReceiver<PlatformEvent>,
event_window: EventWindow,
}
@@ -36,16 +35,24 @@ impl EventListener {
/// Starts listening for platform events.
pub async fn start(config: Arc<Mutex<UserConfig>>) -> Result<Self> {
let (event_tx, event_rx) = mpsc::unbounded_channel();
- let event_window = EventWindow::new(event_tx);
+ let config = config.lock().await;
+
+ let event_window = EventWindow::new(
+ event_tx,
+ config.keybindings.clone(),
+ config.general.focus_follows_cursor,
+ );
Ok(Self {
- config,
event_rx,
event_window,
})
}
- pub fn update(&self) {
- todo!()
+ pub fn update(&mut self, config: &UserConfig) {
+ self.event_window.update(
+ config.keybindings.clone(),
+ config.general.focus_follows_cursor,
+ );
}
}
diff --git a/packages/wm/src/common/platform/event_window.rs b/packages/wm/src/common/platform/event_window.rs
index c887acdd..97e558d4 100644
--- a/packages/wm/src/common/platform/event_window.rs
+++ b/packages/wm/src/common/platform/event_window.rs
@@ -30,6 +30,8 @@ use windows::{
},
};
+use crate::user_config::KeybindingConfig;
+
use super::{NativeWindow, PlatformEvent};
thread_local! {
@@ -156,7 +158,11 @@ pub struct EventWindow {
}
impl EventWindow {
- pub fn new(event_tx: UnboundedSender<PlatformEvent>) -> Self {
+ pub fn new(
+ event_tx: UnboundedSender<PlatformEvent>,
+ keybindings: Vec<KeybindingConfig>,
+ enable_mouse_listener: bool,
+ ) -> Self {
let (abort_tx, abort_rx) = oneshot::channel();
let window_thread = thread::spawn(|| unsafe {
@@ -183,6 +189,14 @@ impl EventWindow {
}
}
+ pub fn update(
+ &mut self,
+ keybindings: Vec<KeybindingConfig>,
+ enable_mouse_listener: bool,
+ ) {
+ todo!()
+ }
+
/// Creates several window event hooks via `SetWinEventHook`.
fn hook_win_events() -> Result<Vec<HWINEVENTHOOK>> {
let event_ranges = [
diff --git a/packages/wm/src/common/tiling_direction.rs b/packages/wm/src/common/tiling_direction.rs
index 3cea6aea..9bf90628 100644
--- a/packages/wm/src/common/tiling_direction.rs
+++ b/packages/wm/src/common/tiling_direction.rs
@@ -2,7 +2,7 @@ use anyhow::{bail, Result};
use super::Direction;
-#[derive(Debug)]
+#[derive(Clone, Debug)]
pub enum TilingDirection {
Vertical,
Horizontal,
diff --git a/packages/wm/src/main.rs b/packages/wm/src/main.rs
index c2c962c5..c4058596 100644
--- a/packages/wm/src/main.rs
+++ b/packages/wm/src/main.rs
@@ -87,7 +87,7 @@ async fn start_wm(config_path: Option<String>) -> Result<()> {
},
Some(config) = config_reader.changes_rx.recv() => {
info!("Received user config update: {:?}", config);
- event_listener.update();
+ event_listener.update(&config);
},
}
}
diff --git a/packages/wm/src/user_config.rs b/packages/wm/src/user_config.rs
index 46c98f12..cd9f251b 100644
--- a/packages/wm/src/user_config.rs
+++ b/packages/wm/src/user_config.rs
@@ -12,7 +12,7 @@ use crate::{
wm_command::WmCommand,
};
-#[derive(Debug, Deserialize)]
+#[derive(Clone, Debug, Deserialize)]
pub struct KeybindingConfig {
/// Keyboard shortcut to trigger the keybinding.
pub bindings: Vec<String>,
@@ -21,7 +21,7 @@ pub struct KeybindingConfig {
pub commands: Vec<WmCommand>,
}
-#[derive(Debug, Deserialize)]
+#[derive(Clone, Debug, Deserialize)]
pub struct BindingModeConfig {
/// Name of the binding mode.
pub name: String,
@@ -33,7 +33,7 @@ pub struct BindingModeConfig {
pub keybindings: Vec<KeybindingConfig>,
}
-#[derive(Debug, Deserialize)]
+#[derive(Clone, Debug, Deserialize)]
pub struct GapsConfig {
/// Gap between adjacent windows.
pub inner_gap: LengthValue,
@@ -42,7 +42,7 @@ pub struct GapsConfig {
pub outer_gap: RectDelta,
}
-#[derive(Debug, Deserialize)]
+#[derive(Clone, Debug, Deserialize)]
pub struct GeneralConfig {
/// Whether to show floating windows as always on top.
pub show_floating_on_top: bool,
@@ -67,7 +67,7 @@ pub struct GeneralConfig {
pub center_new_floating_windows: bool,
}
-#[derive(Debug, Deserialize)]
+#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum WindowAnimations {
Enabled,
@@ -75,7 +75,7 @@ pub enum WindowAnimations {
Unchanged,
}
-#[derive(Debug, Deserialize)]
+#[derive(Clone, Debug, Deserialize)]
pub struct FocusBorder {
/// Whether to use a custom border color.
pub enabled: bool,
@@ -84,7 +84,7 @@ pub struct FocusBorder {
pub color: String,
}
-#[derive(Debug, Deserialize)]
+#[derive(Clone, Debug, Deserialize)]
pub struct FocusBordersConfig {
/// Border of the focused window.
pub active: FocusBorder,
@@ -93,7 +93,7 @@ pub struct FocusBordersConfig {
pub inactive: FocusBorder,
}
-#[derive(Debug, Deserialize)]
+#[derive(Clone, Debug, Deserialize)]
pub struct WindowRuleConfig {
pub match_process_name: Option<String>,
pub match_class_name: Option<String>,
@@ -101,7 +101,7 @@ pub struct WindowRuleConfig {
pub commands: Vec<WmCommand>,
}
-#[derive(Debug, Deserialize)]
+#[derive(Clone, Debug, Deserialize)]
pub struct WorkspaceConfig {
pub name: String,
pub display_name: Option<String>,
@@ -109,7 +109,7 @@ pub struct WorkspaceConfig {
pub keep_alive: Option<bool>,
}
-#[derive(Debug, Deserialize)]
+#[derive(Clone, Debug, Deserialize)]
pub struct UserConfig {
pub binding_modes: Vec<BindingModeConfig>,
pub focus_borders: FocusBordersConfig,
diff --git a/packages/wm/src/wm_command.rs b/packages/wm/src/wm_command.rs
index d160f657..f7e06045 100644
--- a/packages/wm/src/wm_command.rs
+++ b/packages/wm/src/wm_command.rs
@@ -1,9 +1,9 @@
-use anyhow::{bail, Result};
+use anyhow::Result;
use serde::{Deserialize, Deserializer};
use crate::common::{Direction, LengthUnit, TilingDirection};
-#[derive(Debug)]
+#[derive(Clone, Debug)]
pub enum WmCommand {
CloseWindow,
DisableBindingMode(String),