From 9b6b86cdea0174294b993bdd73aa8a7b852e8a90 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Wed, 31 Dec 2025 18:40:34 -0800 Subject: [PATCH] fix(wm): send manual move/resize end events on mouse release The Acessibility API does not reliably fire AXWindowMoved and AXWindowResized notifications after the mouse button is released, causing drag-to-swap and drag-to-resize operations to fail. This sends manual MoveEnd and ResizeEnd events from the input event listener when LeftMouseUp is detected, ensuring these operations complete reliably. Resizing windows while dragging doesn't really work and has been noted in the known-issues.md file. --- docs/known-issues.md | 1 + komorebi/src/input_event_listener.rs | 35 +++++++++++++++++++++++----- komorebi/src/window_manager_event.rs | 9 +++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/docs/known-issues.md b/docs/known-issues.md index da251eb0..3ef209f9 100644 --- a/docs/known-issues.md +++ b/docs/known-issues.md @@ -4,3 +4,4 @@ state (probably shouldn't) * Application hiding isn't supported (and probably won't be) and breaks the state (probably shouldn't) +* Resizing windows by dragging with animations on is a train wreck; don't do it diff --git a/komorebi/src/input_event_listener.rs b/komorebi/src/input_event_listener.rs index ac4a06de..3d6fbb78 100644 --- a/komorebi/src/input_event_listener.rs +++ b/komorebi/src/input_event_listener.rs @@ -44,14 +44,37 @@ extern "C-unwind" fn callback( element.pid(NonNull::from_mut(&mut pid)); } - if pid != 0 - && let Some(event) = WindowManagerEvent::from_system_notification( + if pid != 0 { + let window_id = AccessibilityApi::window_id(&element).ok(); + + // Send MoveEnd to handle pending drag-to-swap operations + // macOS doesn't reliably fire AXWindowMoved after mouse release + if let Some(event) = WindowManagerEvent::from_system_notification( + SystemNotification::Manual(ManualNotification::MoveEnd), + pid, + window_id, + ) { + window_manager_event_listener::send_notification(event); + } + + // Send ResizeEnd to handle pending resize operations + // macOS doesn't reliably fire AXWindowResized after mouse release + if let Some(event) = WindowManagerEvent::from_system_notification( + SystemNotification::Manual(ManualNotification::ResizeEnd), + pid, + window_id, + ) { + window_manager_event_listener::send_notification(event); + } + + // Handle tab dragging to create new windows + if let Some(event) = WindowManagerEvent::from_system_notification( SystemNotification::Manual(ManualNotification::ShowOnInputEvent), pid, - AccessibilityApi::window_id(&element).ok(), - ) - { - window_manager_event_listener::send_notification(event); + window_id, + ) { + window_manager_event_listener::send_notification(event); + } } } diff --git a/komorebi/src/window_manager_event.rs b/komorebi/src/window_manager_event.rs index 72ec784b..7109f04c 100644 --- a/komorebi/src/window_manager_event.rs +++ b/komorebi/src/window_manager_event.rs @@ -24,6 +24,8 @@ pub enum ManualNotification { ShowOnFocusChangeWindowlessAppRestored, Manage, Unmanage, + MoveEnd, + ResizeEnd, } #[derive(Debug, Copy, Clone, Serialize, Deserialize, Display)] @@ -95,6 +97,13 @@ impl WindowManagerEvent { .map(|window_id| WindowManagerEvent::Manage(notification, process_id, window_id)), SystemNotification::Manual(ManualNotification::Unmanage) => window_id .map(|window_id| WindowManagerEvent::Unmanage(notification, process_id, window_id)), + SystemNotification::Manual(ManualNotification::MoveEnd) => window_id + .map(|window_id| WindowManagerEvent::MoveEnd(notification, process_id, window_id)), + SystemNotification::Manual(ManualNotification::ResizeEnd) => { + window_id.map(|window_id| { + WindowManagerEvent::ResizeEnd(notification, process_id, window_id) + }) + } SystemNotification::Accessibility(AccessibilityNotification::AXWindowMoved) => { if MacosApi::left_mouse_button_is_pressed() { window_id.map(|window_id| {