GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
fix: finished focus_follows_cursor (hopefully)
holby8ab2bec8e455
diff --git a/packages/wm/src/common/events/handle_mouse_move.rs b/packages/wm/src/common/events/handle_mouse_move.rsindex 7b457259..e3d75536 100644--- a/packages/wm/src/common/events/handle_mouse_move.rs+++ b/packages/wm/src/common/events/handle_mouse_move.rs@@ -13,21 +13,16 @@ pub fn handle_mouse_move(if !config.value.general.focus_follows_cursor {return Ok(());}-+let mut window_under_cursor =Platform::window_from_point(&mouse_move_event.point).unwrap();- // walk the window tree to find the top-level window- while let Ok(parent) = Platform::get_parent(&window_under_cursor) {- window_under_cursor = parent;- }+ let root_window = Platform::get_root_ancestor(&window_under_cursor)?;- // prevent spam focusing the same window by checking the target window against the currently focused window- if let Some(window) = state.window_from_native(&window_under_cursor) {- let currently_focused_container = state.focused_container().unwrap();- let tiling_window =- currently_focused_container.as_tiling_window().unwrap();- if (tiling_window.id() != window.id()) {+ // prevent spam focusing the same window+ // by checking the window under cursor against the WM's currently focused window+ if let Some(window) = state.window_from_native(&root_window) {+ if (state.focused_container() != Some(window.as_container())) {set_focused_descendant(window.as_container(), None);state.has_pending_focus_sync = true;redraw(state)?;diff --git a/packages/wm/src/common/platform/platform.rs b/packages/wm/src/common/platform/platform.rsindex c2656dd1..36c73ed8 100644--- a/packages/wm/src/common/platform/platform.rs+++ b/packages/wm/src/common/platform/platform.rs@@ -13,17 +13,18 @@ use windows::Win32::UI::Shell::{SHELLEXECUTEINFOW,};+use windows::Win32::UI::WindowsAndMessaging::GA_ROOT;use windows::Win32::UI::{HiDpi::{SetProcessDpiAwarenessContext,DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2,},WindowsAndMessaging::{- CreateWindowExW, DestroyWindow, DispatchMessageW, GetDesktopWindow,- GetForegroundWindow, GetMessageW, GetParent, RegisterClassW,- SetCursorPos, TranslateMessage, WindowFromPoint, CS_HREDRAW,- CS_VREDRAW, CW_USEDEFAULT, MSG, SW_NORMAL, WNDCLASSW, WNDPROC,- WS_OVERLAPPEDWINDOW,+ CreateWindowExW, DestroyWindow, DispatchMessageW, GetAncestor,+ GetDesktopWindow, GetForegroundWindow, GetMessageW, GetParent,+ RegisterClassW, SetCursorPos, TranslateMessage, WindowFromPoint,+ CS_HREDRAW, CS_VREDRAW, CW_USEDEFAULT, MSG, SW_NORMAL, WNDCLASSW,+ WNDPROC, WS_OVERLAPPEDWINDOW,},};@@ -114,17 +115,24 @@ impl Platform {pub fn new_single_instance() -> anyhow::Result<SingleInstance> {SingleInstance::new()}-- // Gets the parent window of the specified window.- pub fn get_parent(++ // Gets the root window of the specified window.+ pub fn get_root_ancestor(window: &NativeWindow,) -> anyhow::Result<NativeWindow> {+ let handle = unsafe { GetAncestor(window.handle, GA_ROOT) };+ Ok(NativeWindow::new(handle))+ }++ // Gets the parent window of the specified window.+ pub fn get_parent(window: &NativeWindow) -> Option<NativeWindow> {let handle = unsafe { GetParent(window.handle) };- // if zero pointer is returned, it means the window has no parent.if handle == HWND(0) {- bail!("Window has no parent.");+ // if a zero pointer is returned, it means the window has no parent.+ None+ } else {+ Some(NativeWindow::new(handle))}- Ok(NativeWindow::new(handle))}/// Sets the cursor position to the specified coordinates.