From e24835a4ae45ca2707b08224f43b23ef49a31e42 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 25 Nov 2023 18:33:09 -0800 Subject: [PATCH] fix(animations): update mouse follows focus This commit ensures that the UpdateFocusedWindowBorder WindowManagerEvent which is handled in process_event is used to position the mouse correctly on the moved window once the animation has been completed. A pending clippy lint in animation.rs has also been addressed. --- komorebi/src/animation.rs | 3 +-- komorebi/src/process_event.rs | 8 ++++++-- komorebi/src/window.rs | 15 ++++++++++----- komorebi/src/window_manager_event.rs | 8 ++++---- komorebi/src/workspace.rs | 12 ++++++------ 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/komorebi/src/animation.rs b/komorebi/src/animation.rs index 61302e5c..e2cdf0a6 100644 --- a/komorebi/src/animation.rs +++ b/komorebi/src/animation.rs @@ -437,10 +437,9 @@ impl Animation { let max_duration = Duration::from_secs(1); let spent_duration = Instant::now(); - // TODO: Come back to this clippy lint while self.in_progress { if spent_duration.elapsed() >= max_duration { - break; + self.in_progress = false; } std::thread::sleep(Duration::from_millis(16)); diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index 58a8e4a6..ddba5405 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -516,7 +516,7 @@ impl WindowManager { | WindowManagerEvent::MouseCapture(..) | WindowManagerEvent::Cloak(..) | WindowManagerEvent::Uncloak(..) - | WindowManagerEvent::SetFocusedBorderWindow(..) => {} + | WindowManagerEvent::UpdateFocusedWindowBorder(..) => {} }; if *self.focused_workspace()?.tile() && BORDER_ENABLED.load(Ordering::SeqCst) { @@ -531,7 +531,7 @@ impl WindowManager { | WindowManagerEvent::FocusChange(_, window) | WindowManagerEvent::Hide(_, window) | WindowManagerEvent::Minimize(_, window) - | WindowManagerEvent::SetFocusedBorderWindow(window) => { + | WindowManagerEvent::UpdateFocusedWindowBorder(window) => { let border = Border::from(BORDER_HWND.load(Ordering::SeqCst)); let mut target_window = None; let mut target_window_is_monocle = false; @@ -597,6 +597,10 @@ impl WindowManager { WindowsApi::invalidate_border_rect()?; border.set_position(target_window, &self.invisible_borders, activate)?; + if matches!(event, WindowManagerEvent::UpdateFocusedWindowBorder(_)) { + window.focus(self.mouse_follows_focus)?; + } + if activate { BORDER_HIDDEN.store(false, Ordering::SeqCst); } diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index b64f9f3a..ad173eae 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -158,14 +158,19 @@ impl Window { if progress < 1.0 { // using MoveWindow because it runs faster than SetWindowPos // so animation have more fps and feel smoother - WindowsApi::move_window(hwnd, &new_rect, true) + WindowsApi::move_window(hwnd, &new_rect, true)?; } else { WindowsApi::position_window(hwnd, &new_rect, top)?; - Ok(WINEVENT_CALLBACK_CHANNEL - .lock() - .0 - .send(WindowManagerEvent::SetFocusedBorderWindow(self_copied))?) + + if WindowsApi::foreground_window()? == self_copied.hwnd { + WINEVENT_CALLBACK_CHANNEL + .lock() + .0 + .send(WindowManagerEvent::UpdateFocusedWindowBorder(self_copied))?; + } } + + Ok(()) }) }); diff --git a/komorebi/src/window_manager_event.rs b/komorebi/src/window_manager_event.rs index fa5af6f5..d311fb67 100644 --- a/komorebi/src/window_manager_event.rs +++ b/komorebi/src/window_manager_event.rs @@ -27,7 +27,7 @@ pub enum WindowManagerEvent { Unmanage(Window), Raise(Window), DisplayChange(Window), - SetFocusedBorderWindow(Window), + UpdateFocusedWindowBorder(Window), } impl Display for WindowManagerEvent { @@ -78,8 +78,8 @@ impl Display for WindowManagerEvent { Self::DisplayChange(window) => { write!(f, "DisplayChange (Window: {window})") } - Self::SetFocusedBorderWindow(window) => { - write!(f, "SetFocusedBorderWindow (Window: {window})") + Self::UpdateFocusedWindowBorder(window) => { + write!(f, "UpdateFocusedBorderWindow (Window: {window})") } } } @@ -102,7 +102,7 @@ impl WindowManagerEvent { | Self::Manage(window) | Self::DisplayChange(window) | Self::Unmanage(window) - | Self::SetFocusedBorderWindow(window) => window, + | Self::UpdateFocusedWindowBorder(window) => window, } } diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 748dfff7..6deb5e0a 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -248,6 +248,12 @@ impl Workspace { } if *self.tile() { + if ANIMATE_ENABLED.load(Ordering::SeqCst) { + let border = Border::from(BORDER_HWND.load(Ordering::SeqCst)); + border.hide()?; + BORDER_HIDDEN.store(true, Ordering::SeqCst); + } + if let Some(container) = self.monocle_container_mut() { if let Some(window) = container.focused_window_mut() { adjusted_work_area.add_padding(container_padding); @@ -280,12 +286,6 @@ impl Workspace { window.add_title_bar()?; } - if ANIMATE_ENABLED.load(Ordering::SeqCst) { - let border = Border::from(BORDER_HWND.load(Ordering::SeqCst)); - border.hide()?; - BORDER_HIDDEN.store(true, Ordering::SeqCst); - } - window.set_position(layout, invisible_borders, false)?; } }