From 84f74fc5a643173d4ab7849851088ba206ae2b1b Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Tue, 9 Aug 2022 10:41:56 -0700 Subject: [PATCH] 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 --- komorebi/src/process_command.rs | 24 ++++++++++++++---------- komorebi/src/process_event.rs | 7 ++++--- komorebi/src/window_manager.rs | 2 +- komorebi/src/windows_api.rs | 4 ++-- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 11d71bfa..3c348633 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -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 { SocketMessage::Promote => self.promote_container_to_front()?, SocketMessage::FocusWindow(direction) => { @@ -782,16 +796,6 @@ impl WindowManager { let border = Border::from(BORDER_HWND.load(Ordering::SeqCst)); 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 => { let is_paused = self.is_paused; let border = Border::from(BORDER_HWND.load(Ordering::SeqCst)); diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index d386833f..e5470bed 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -481,9 +481,10 @@ impl WindowManager { border.hide()?; BORDER_HIDDEN.store(true, Ordering::SeqCst); } - WindowManagerEvent::MoveResizeEnd(_, window) - | WindowManagerEvent::Show(_, window) - | WindowManagerEvent::FocusChange(_, window) => { + WindowManagerEvent::MoveResizeEnd(_, _) + | WindowManagerEvent::Show(_, _) + | WindowManagerEvent::FocusChange(_, _) => { + let window = self.focused_window()?; let mut rect = WindowsApi::window_rect(window.hwnd())?; rect.top -= self.invisible_borders.bottom; rect.bottom += self.invisible_borders.bottom; diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 1adbe4ea..706c50c4 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -1911,7 +1911,7 @@ impl WindowManager { monitor.focus_workspace(idx)?; monitor.load_focused_workspace(mouse_follows_focus)?; - self.update_focused_workspace(mouse_follows_focus) + self.update_focused_workspace(false) } #[tracing::instrument(skip(self))] diff --git a/komorebi/src/windows_api.rs b/komorebi/src/windows_api.rs index 606a4d1b..28596fcd 100644 --- a/komorebi/src/windows_api.rs +++ b/komorebi/src/windows_api.rs @@ -93,7 +93,7 @@ use windows::Win32::UI::WindowsAndMessaging::SW_HIDE; use windows::Win32::UI::WindowsAndMessaging::SW_MAXIMIZE; use windows::Win32::UI::WindowsAndMessaging::SW_MINIMIZE; 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_UPDATE_FLAGS; use windows::Win32::UI::WindowsAndMessaging::WINDOW_LONG_PTR_INDEX; @@ -332,7 +332,7 @@ impl WindowsApi { } pub fn restore_window(hwnd: HWND) { - Self::show_window(hwnd, SW_RESTORE); + Self::show_window(hwnd, SW_SHOWNOACTIVATE); } pub fn unmaximize_window(hwnd: HWND) {