GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: disable mouse hook if `focus_follows_mouse` is disabled
Lars Bergera4321762bdd7
diff --git a/packages/wm/src/common/platform/event_window.rs b/packages/wm/src/common/platform/event_window.rsindex 99975956..67ded643 100644--- a/packages/wm/src/common/platform/event_window.rs+++ b/packages/wm/src/common/platform/event_window.rs@@ -44,7 +44,7 @@ impl EventWindow {) -> Self {let (abort_tx, abort_rx) = oneshot::channel();- let window_thread = thread::spawn(|| unsafe {+ let window_thread = thread::spawn(move || unsafe {// Initialize the thread-local sender for platform events.PLATFORM_EVENT_TX.with(|cell| cell.set(event_tx.clone()))@@ -55,7 +55,7 @@ impl EventWindow {// Start hooks for listening to platform events.KeyboardHook::start(options.keybindings, event_tx.clone())?;WinEventHook::start(event_tx.clone())?;- MouseHook::start(event_tx)?;+ MouseHook::start(options.enable_mouse_events, event_tx)?;// Create a hidden window with a message loop on the current thread.Platform::create_message_loop(abort_rx, Some(event_window_proc))?;diff --git a/packages/wm/src/common/platform/mouse_hook.rs b/packages/wm/src/common/platform/mouse_hook.rsindex 5025cd88..c9f2b840 100644--- a/packages/wm/src/common/platform/mouse_hook.rs+++ b/packages/wm/src/common/platform/mouse_hook.rs@@ -30,7 +30,7 @@ pub struct MouseHook {event_tx: mpsc::UnboundedSender<PlatformEvent>,/// Handle to the mouse hook.- hook: HHOOK,+ hook: Option<HHOOK>,/// Whether left-click is currently pressed.is_l_mouse_down: bool,@@ -47,10 +47,18 @@ impl MouseHook {////// Assumes that a message loop is currently running.pub fn start(+ enabled: bool,event_tx: mpsc::UnboundedSender<PlatformEvent>,) -> Result<Arc<Mutex<MouseHook>>> {- let hook = unsafe {- SetWindowsHookExW(WH_MOUSE_LL, Some(mouse_hook_proc), None, 0)?+ let hook = match enabled {+ false => None,+ true => {+ let hook = unsafe {+ SetWindowsHookExW(WH_MOUSE_LL, Some(mouse_hook_proc), None, 0)+ }?;++ Some(hook)+ }};let mouse_hook = Arc::new(Mutex::new(Self {@@ -117,7 +125,10 @@ impl MouseHook {/// Stops the low-level mouse hook.pub fn stop(&mut self) -> anyhow::Result<()> {- unsafe { UnhookWindowsHookEx(self.hook) }?;+ if let Some(hook) = self.hook.take() {+ unsafe { UnhookWindowsHookEx(hook) }?;+ }+Ok(())}}