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.
This commit is contained in:
LGUG2Z
2023-11-25 18:33:09 -08:00
parent 50b12431fa
commit e24835a4ae
5 changed files with 27 additions and 19 deletions
+1 -2
View File
@@ -437,10 +437,9 @@ impl Animation {
let max_duration = Duration::from_secs(1); let max_duration = Duration::from_secs(1);
let spent_duration = Instant::now(); let spent_duration = Instant::now();
// TODO: Come back to this clippy lint
while self.in_progress { while self.in_progress {
if spent_duration.elapsed() >= max_duration { if spent_duration.elapsed() >= max_duration {
break; self.in_progress = false;
} }
std::thread::sleep(Duration::from_millis(16)); std::thread::sleep(Duration::from_millis(16));
+6 -2
View File
@@ -516,7 +516,7 @@ impl WindowManager {
| WindowManagerEvent::MouseCapture(..) | WindowManagerEvent::MouseCapture(..)
| WindowManagerEvent::Cloak(..) | WindowManagerEvent::Cloak(..)
| WindowManagerEvent::Uncloak(..) | WindowManagerEvent::Uncloak(..)
| WindowManagerEvent::SetFocusedBorderWindow(..) => {} | WindowManagerEvent::UpdateFocusedWindowBorder(..) => {}
}; };
if *self.focused_workspace()?.tile() && BORDER_ENABLED.load(Ordering::SeqCst) { if *self.focused_workspace()?.tile() && BORDER_ENABLED.load(Ordering::SeqCst) {
@@ -531,7 +531,7 @@ impl WindowManager {
| WindowManagerEvent::FocusChange(_, window) | WindowManagerEvent::FocusChange(_, window)
| WindowManagerEvent::Hide(_, window) | WindowManagerEvent::Hide(_, window)
| WindowManagerEvent::Minimize(_, window) | WindowManagerEvent::Minimize(_, window)
| WindowManagerEvent::SetFocusedBorderWindow(window) => { | WindowManagerEvent::UpdateFocusedWindowBorder(window) => {
let border = Border::from(BORDER_HWND.load(Ordering::SeqCst)); let border = Border::from(BORDER_HWND.load(Ordering::SeqCst));
let mut target_window = None; let mut target_window = None;
let mut target_window_is_monocle = false; let mut target_window_is_monocle = false;
@@ -597,6 +597,10 @@ impl WindowManager {
WindowsApi::invalidate_border_rect()?; WindowsApi::invalidate_border_rect()?;
border.set_position(target_window, &self.invisible_borders, activate)?; border.set_position(target_window, &self.invisible_borders, activate)?;
if matches!(event, WindowManagerEvent::UpdateFocusedWindowBorder(_)) {
window.focus(self.mouse_follows_focus)?;
}
if activate { if activate {
BORDER_HIDDEN.store(false, Ordering::SeqCst); BORDER_HIDDEN.store(false, Ordering::SeqCst);
} }
+10 -5
View File
@@ -158,14 +158,19 @@ impl Window {
if progress < 1.0 { if progress < 1.0 {
// using MoveWindow because it runs faster than SetWindowPos // using MoveWindow because it runs faster than SetWindowPos
// so animation have more fps and feel smoother // so animation have more fps and feel smoother
WindowsApi::move_window(hwnd, &new_rect, true) WindowsApi::move_window(hwnd, &new_rect, true)?;
} else { } else {
WindowsApi::position_window(hwnd, &new_rect, top)?; WindowsApi::position_window(hwnd, &new_rect, top)?;
Ok(WINEVENT_CALLBACK_CHANNEL
.lock() if WindowsApi::foreground_window()? == self_copied.hwnd {
.0 WINEVENT_CALLBACK_CHANNEL
.send(WindowManagerEvent::SetFocusedBorderWindow(self_copied))?) .lock()
.0
.send(WindowManagerEvent::UpdateFocusedWindowBorder(self_copied))?;
}
} }
Ok(())
}) })
}); });
+4 -4
View File
@@ -27,7 +27,7 @@ pub enum WindowManagerEvent {
Unmanage(Window), Unmanage(Window),
Raise(Window), Raise(Window),
DisplayChange(Window), DisplayChange(Window),
SetFocusedBorderWindow(Window), UpdateFocusedWindowBorder(Window),
} }
impl Display for WindowManagerEvent { impl Display for WindowManagerEvent {
@@ -78,8 +78,8 @@ impl Display for WindowManagerEvent {
Self::DisplayChange(window) => { Self::DisplayChange(window) => {
write!(f, "DisplayChange (Window: {window})") write!(f, "DisplayChange (Window: {window})")
} }
Self::SetFocusedBorderWindow(window) => { Self::UpdateFocusedWindowBorder(window) => {
write!(f, "SetFocusedBorderWindow (Window: {window})") write!(f, "UpdateFocusedBorderWindow (Window: {window})")
} }
} }
} }
@@ -102,7 +102,7 @@ impl WindowManagerEvent {
| Self::Manage(window) | Self::Manage(window)
| Self::DisplayChange(window) | Self::DisplayChange(window)
| Self::Unmanage(window) | Self::Unmanage(window)
| Self::SetFocusedBorderWindow(window) => window, | Self::UpdateFocusedWindowBorder(window) => window,
} }
} }
+6 -6
View File
@@ -248,6 +248,12 @@ impl Workspace {
} }
if *self.tile() { 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(container) = self.monocle_container_mut() {
if let Some(window) = container.focused_window_mut() { if let Some(window) = container.focused_window_mut() {
adjusted_work_area.add_padding(container_padding); adjusted_work_area.add_padding(container_padding);
@@ -280,12 +286,6 @@ impl Workspace {
window.add_title_bar()?; 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)?; window.set_position(layout, invisible_borders, false)?;
} }
} }