GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
WIP: semi-functional focus_follows_cursor
holby45c4c3f34a15
diff --git a/packages/wm/src/common/platform/platform.rs b/packages/wm/src/common/platform/platform.rsindex fa1ac0b8..1261faad 100644--- a/packages/wm/src/common/platform/platform.rs+++ b/packages/wm/src/common/platform/platform.rs@@ -1,10 +1,12 @@use std::path::Path;use std::sync::Arc;+use crate::common::Point;use anyhow::{bail, Context};use tokio::sync::{oneshot, Mutex};use tracing::warn;use windows::core::{w, PCWSTR};+use windows::Win32::Foundation::POINT;use windows::Win32::System::Environment::ExpandEnvironmentStringsW;use windows::Win32::UI::Shell::{ShellExecuteExW, SEE_MASK_NOASYNC, SEE_MASK_NOCLOSEPROCESS,@@ -12,8 +14,9 @@ use windows::Win32::UI::Shell::{};use windows::Win32::UI::WindowsAndMessaging::{CreateWindowExW, DestroyWindow, DispatchMessageW, GetMessageW,- RegisterClassW, SetCursorPos, TranslateMessage, CS_HREDRAW, CS_VREDRAW,- CW_USEDEFAULT, MSG, SW_NORMAL, WNDCLASSW, WNDPROC, WS_OVERLAPPEDWINDOW,+ RegisterClassW, SetCursorPos, TranslateMessage, WindowFromPoint,+ CS_HREDRAW, CS_VREDRAW, CW_USEDEFAULT, MSG, SW_NORMAL, WNDCLASSW,+ WNDPROC, WS_OVERLAPPEDWINDOW,};use windows::Win32::UI::{HiDpi::{@@ -123,6 +126,15 @@ impl Platform {Ok(())}+ pub fn window_from_point(point: &Point) -> anyhow::Result<NativeWindow> {+ let point = POINT {+ x: point.x,+ y: point.y,+ };+ let handle = unsafe { WindowFromPoint(point) };+ Ok(NativeWindow::new(handle))+ }+/// Sets the cursor position to the specified coordinates.pub fn set_cursor_pos(x: i32, y: i32) -> anyhow::Result<()> {unsafe {diff --git a/packages/wm/src/wm.rs b/packages/wm/src/wm.rsindex 881013e4..d2f895c7 100644--- a/packages/wm/src/wm.rs+++ b/packages/wm/src/wm.rs@@ -7,6 +7,7 @@ use tokio::sync::{};use uuid::Uuid;+use crate::containers::commands::set_focused_descendant;use crate::{app_command::InvokeCommand,common::{@@ -18,7 +19,7 @@ use crate::{handle_window_minimized, handle_window_moved_or_resized,handle_window_shown,},- platform::PlatformEvent,+ platform::{Platform, PlatformEvent},},containers::{commands::redraw, traits::CommonGetters},user_config::UserConfig,@@ -67,7 +68,25 @@ impl WindowManager {PlatformEvent::DisplaySettingsChanged => {handle_display_settings_changed(&mut state, config)}- PlatformEvent::MouseMove(_) => Ok(()),+ PlatformEvent::MouseMove(event) => Ok({+ if config.value.general.focus_follows_cursor {+ let native_window =+ Platform::window_from_point(&event.point).unwrap();++ if let Some(window) = state.window_from_native(&native_window) {+ let currently_focused_container =+ state.focused_container().unwrap();+ let tiling_window =+ currently_focused_container.as_tiling_window().unwrap();+ if (tiling_window.id() != window.id()) {+ set_focused_descendant(window.as_container(), None);+ state.has_pending_focus_sync = true;+ redraw(&mut state)?;+ sync_native_focus(&mut state)?;+ }+ }+ }+ }),PlatformEvent::WindowDestroyed(window) => {handle_window_destroyed(window, &mut state)}