GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: partially implement updating event listener on binding mode changes
Lars Bergerb43562c7328b
diff --git a/packages/wm/src/common/platform/event_listener.rs b/packages/wm/src/common/platform/event_listener.rsindex 1529cf17..18bc941c 100644--- a/packages/wm/src/common/platform/event_listener.rs+++ b/packages/wm/src/common/platform/event_listener.rs@@ -6,7 +6,9 @@ use tokio::sync::{Mutex,};-use crate::user_config::{KeybindingConfig, UserConfig};+use crate::user_config::{+ BindingModeConfig, KeybindingConfig, UserConfig,+};use super::{EventWindow, NativeWindow};@@ -51,11 +53,20 @@ impl EventListener {})}- /// Updates the event listener with the latest user config.- pub fn update(&mut self, config: &UserConfig) {- self.event_window.update(- config.value.keybindings.clone(),- config.value.general.focus_follows_cursor,- );+ /// Updates the event listener with the latest user config and the+ /// currently active binding modes.+ pub fn update(+ &mut self,+ config: &UserConfig,+ binding_modes: &Vec<BindingModeConfig>,+ ) {+ // TODO: Modify keybindings based on active binding modes.+ self+ .event_window+ .update_keybindings(config.value.keybindings.clone());++ self+ .event_window+ .enable_mouse_listener(config.value.general.focus_follows_cursor);}}diff --git a/packages/wm/src/common/platform/event_window.rs b/packages/wm/src/common/platform/event_window.rsindex 97e558d4..cbe2d395 100644--- a/packages/wm/src/common/platform/event_window.rs+++ b/packages/wm/src/common/platform/event_window.rs@@ -4,7 +4,7 @@ use std::{};use anyhow::{bail, Result};-use tokio::sync::{mpsc::UnboundedSender, oneshot};+use tokio::sync::{mpsc, oneshot};use tracing::warn;use windows::{core::w,@@ -35,7 +35,7 @@ use crate::user_config::KeybindingConfig;use super::{NativeWindow, PlatformEvent};thread_local! {- static HOOK_EVENT_TX: OnceCell<UnboundedSender<PlatformEvent>> = OnceCell::new();+ static HOOK_EVENT_TX: OnceCell<mpsc::UnboundedSender<PlatformEvent>> = OnceCell::new();}/// Callback passed to `SetWinEventHook` to handle window events.@@ -100,8 +100,8 @@ extern "system" fn event_hook_proc(/// Window procedure for the event window.///-/// This function handles messages for the event window, and forwards-/// display change events through an MPSC channel for the WM to process.+/// Handles messages for the event window, and forwards display change+/// events through an MPSC channel for the WM to process.pub extern "system" fn event_window_proc(handle: HWND,message: u32,@@ -126,11 +126,12 @@ pub extern "system" fn event_window_proc(})}-/// Handle display change messages and emit the corresponding event.+/// Handles display change messages and emits the corresponding platform+/// event through an MPSC channel.fn handle_display_change_msg(message: u32,wparam: WPARAM,- event_tx: &UnboundedSender<PlatformEvent>,+ event_tx: &mpsc::UnboundedSender<PlatformEvent>,) -> LRESULT {let should_emit_event = match message {WM_SETTINGCHANGE => {@@ -159,7 +160,7 @@ pub struct EventWindow {impl EventWindow {pub fn new(- event_tx: UnboundedSender<PlatformEvent>,+ event_tx: mpsc::UnboundedSender<PlatformEvent>,keybindings: Vec<KeybindingConfig>,enable_mouse_listener: bool,) -> Self {@@ -189,14 +190,17 @@ impl EventWindow {}}- pub fn update(+ pub fn update_keybindings(&mut self,keybindings: Vec<KeybindingConfig>,- enable_mouse_listener: bool,) {todo!()}+ pub fn enable_mouse_listener(&mut self, is_enabled: 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/platform/windows_api.rs b/packages/wm/src/common/platform/windows_api.rsdeleted file mode 100644index e69de29b..00000000diff --git a/packages/wm/src/main.rs b/packages/wm/src/main.rsindex 76593331..36b50914 100644--- a/packages/wm/src/main.rs+++ b/packages/wm/src/main.rs@@ -11,7 +11,7 @@ use ipc_server::IpcServer;use user_config::UserConfig;use wm::WindowManager;-use crate::app_command::AppCommand;+use crate::{app_command::AppCommand, wm_event::WmEvent};mod app_command;mod common;@@ -71,7 +71,6 @@ async fn start_wm(config_path: Option<PathBuf>) -> Result<()> {let mut event_listener = Platform::new_event_listener(&config).await?;loop {- let wm_state = wm.state.clone();let mut config = config.lock().await;tokio::select! {@@ -79,21 +78,26 @@ async fn start_wm(config_path: Option<PathBuf>) -> Result<()> {debug!("Received platform event: {:?}", event);wm.process_event(event, config.deref_mut()).await;},- Some(wm_event) = wm.event_rx.recv() => {- 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);- ipc_server.process_message(ipc_message, wm_state).await+ ipc_server.process_message(ipc_message, wm.state.clone()).await;},Some(wm_command) = ipc_server.wm_command_rx.recv() => {info!("Received WM command via IPC: {:?}", wm_command);- let _ = wm.process_command(wm_command, config.deref_mut()).await;+ wm.process_command(wm_command, config.deref_mut()).await;},Some(_) = config.changes_rx.recv() => {info!("Received user config update: {:?}", config);- event_listener.update(&config);+ event_listener.update(&config, &Vec::new());+ },+ Some(wm_event) = wm.event_rx.recv() => {+ info!("Received WM event: {:?}", wm_event);++ if let WmEvent::BindingModesChanged { active_binding_modes } = &wm_event {+ event_listener.update(&config, active_binding_modes);+ }++ ipc_server.process_event(wm_event).await;},}}diff --git a/packages/wm/src/wm_event.rs b/packages/wm/src/wm_event.rsindex ea2922cb..7497c3d5 100644--- a/packages/wm/src/wm_event.rs+++ b/packages/wm/src/wm_event.rs@@ -4,13 +4,14 @@ use crate::{common::{platform::WindowHandle, TilingDirection},containers::{Container, WindowContainer},monitors::Monitor,+ user_config::BindingModeConfig,workspaces::Workspace,};#[derive(Debug)]pub enum WmEvent {- BindingModeChanged {- new_binding_mode: String,+ BindingModesChanged {+ active_binding_modes: Vec<BindingModeConfig>,},FocusChanged {focused_container: Container,