perf(wm): reduce border jank on ws switch

This commit introduces a few changes to reduce border jank, especially
when switching workspaces:

- The border is hidden before the windows start to reorganize when a
  workspace switching command is received instead of after
- Avoid unncessary window.focus() call when switching workspace
- Use WindowManager.focused_window() instead of the window received from
  the WindowManagerEvent when updating or setting the active border
  position as it more accurately matches user expectations when
  switching back to a workspace to find the focused window being the one
  that you left when you switched away
This commit is contained in:
LGUG2Z
2022-08-09 10:41:56 -07:00
parent 01b2c52460
commit 84f74fc5a6
4 changed files with 21 additions and 16 deletions

View File

@@ -90,6 +90,20 @@ impl WindowManager {
} }
} }
match message {
SocketMessage::CycleFocusMonitor(_)
| SocketMessage::CycleFocusWorkspace(_)
| SocketMessage::FocusMonitorNumber(_)
| SocketMessage::FocusMonitorWorkspaceNumber(_, _)
| SocketMessage::FocusWorkspaceNumber(_) => {
if self.focused_workspace()?.visible_windows().is_empty() {
let border = Border::from(BORDER_HWND.load(Ordering::SeqCst));
border.hide()?;
}
}
_ => {}
};
match message { match message {
SocketMessage::Promote => self.promote_container_to_front()?, SocketMessage::Promote => self.promote_container_to_front()?,
SocketMessage::FocusWindow(direction) => { SocketMessage::FocusWindow(direction) => {
@@ -782,16 +796,6 @@ impl WindowManager {
let border = Border::from(BORDER_HWND.load(Ordering::SeqCst)); let border = Border::from(BORDER_HWND.load(Ordering::SeqCst));
border.set_position(foreground_window, &self.invisible_borders, false)?; border.set_position(foreground_window, &self.invisible_borders, false)?;
} }
SocketMessage::CycleFocusMonitor(_)
| SocketMessage::CycleFocusWorkspace(_)
| SocketMessage::FocusMonitorNumber(_)
| SocketMessage::FocusMonitorWorkspaceNumber(_, _)
| SocketMessage::FocusWorkspaceNumber(_) => {
if self.focused_workspace()?.visible_windows().is_empty() {
let border = Border::from(BORDER_HWND.load(Ordering::SeqCst));
border.hide()?;
}
}
SocketMessage::TogglePause => { SocketMessage::TogglePause => {
let is_paused = self.is_paused; let is_paused = self.is_paused;
let border = Border::from(BORDER_HWND.load(Ordering::SeqCst)); let border = Border::from(BORDER_HWND.load(Ordering::SeqCst));

View File

@@ -481,9 +481,10 @@ impl WindowManager {
border.hide()?; border.hide()?;
BORDER_HIDDEN.store(true, Ordering::SeqCst); BORDER_HIDDEN.store(true, Ordering::SeqCst);
} }
WindowManagerEvent::MoveResizeEnd(_, window) WindowManagerEvent::MoveResizeEnd(_, _)
| WindowManagerEvent::Show(_, window) | WindowManagerEvent::Show(_, _)
| WindowManagerEvent::FocusChange(_, window) => { | WindowManagerEvent::FocusChange(_, _) => {
let window = self.focused_window()?;
let mut rect = WindowsApi::window_rect(window.hwnd())?; let mut rect = WindowsApi::window_rect(window.hwnd())?;
rect.top -= self.invisible_borders.bottom; rect.top -= self.invisible_borders.bottom;
rect.bottom += self.invisible_borders.bottom; rect.bottom += self.invisible_borders.bottom;

View File

@@ -1911,7 +1911,7 @@ impl WindowManager {
monitor.focus_workspace(idx)?; monitor.focus_workspace(idx)?;
monitor.load_focused_workspace(mouse_follows_focus)?; monitor.load_focused_workspace(mouse_follows_focus)?;
self.update_focused_workspace(mouse_follows_focus) self.update_focused_workspace(false)
} }
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]

View File

@@ -93,7 +93,7 @@ use windows::Win32::UI::WindowsAndMessaging::SW_HIDE;
use windows::Win32::UI::WindowsAndMessaging::SW_MAXIMIZE; use windows::Win32::UI::WindowsAndMessaging::SW_MAXIMIZE;
use windows::Win32::UI::WindowsAndMessaging::SW_MINIMIZE; use windows::Win32::UI::WindowsAndMessaging::SW_MINIMIZE;
use windows::Win32::UI::WindowsAndMessaging::SW_NORMAL; use windows::Win32::UI::WindowsAndMessaging::SW_NORMAL;
use windows::Win32::UI::WindowsAndMessaging::SW_RESTORE; use windows::Win32::UI::WindowsAndMessaging::SW_SHOWNOACTIVATE;
use windows::Win32::UI::WindowsAndMessaging::SYSTEM_PARAMETERS_INFO_ACTION; use windows::Win32::UI::WindowsAndMessaging::SYSTEM_PARAMETERS_INFO_ACTION;
use windows::Win32::UI::WindowsAndMessaging::SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS; use windows::Win32::UI::WindowsAndMessaging::SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS;
use windows::Win32::UI::WindowsAndMessaging::WINDOW_LONG_PTR_INDEX; use windows::Win32::UI::WindowsAndMessaging::WINDOW_LONG_PTR_INDEX;
@@ -332,7 +332,7 @@ impl WindowsApi {
} }
pub fn restore_window(hwnd: HWND) { pub fn restore_window(hwnd: HWND) {
Self::show_window(hwnd, SW_RESTORE); Self::show_window(hwnd, SW_SHOWNOACTIVATE);
} }
pub fn unmaximize_window(hwnd: HWND) { pub fn unmaximize_window(hwnd: HWND) {