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

View File

@@ -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));

View File

@@ -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);
}

View File

@@ -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(())
})
});

View File

@@ -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,
}
}

View File

@@ -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)?;
}
}