Skip to content

Commit

Permalink
fix(animations): update mouse follows focus
Browse files Browse the repository at this point in the history
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
  • Loading branch information
LGUG2Z committed Nov 26, 2023
1 parent 3eef45e commit 23d673e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
8 changes: 6 additions & 2 deletions komorebi/src/process_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
15 changes: 10 additions & 5 deletions komorebi/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
})
});

Expand Down
8 changes: 4 additions & 4 deletions komorebi/src/window_manager_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub enum WindowManagerEvent {
Unmanage(Window),
Raise(Window),
DisplayChange(Window),
SetFocusedBorderWindow(Window),
UpdateFocusedWindowBorder(Window),
}

impl Display for WindowManagerEvent {
Expand Down Expand Up @@ -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})")
}
}
}
Expand All @@ -102,7 +102,7 @@ impl WindowManagerEvent {
| Self::Manage(window)
| Self::DisplayChange(window)
| Self::Unmanage(window)
| Self::SetFocusedBorderWindow(window) => window,
| Self::UpdateFocusedWindowBorder(window) => window,
}
}

Expand Down
12 changes: 6 additions & 6 deletions komorebi/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)?;
}
}
Expand Down

0 comments on commit 23d673e

Please sign in to comment.