From 0b7d5a89b7bb3a38a3e3b2f2f495a5b58dee748d Mon Sep 17 00:00:00 2001 From: alex-ds13 <145657253+alex-ds13@users.noreply.github.com> Date: Thu, 10 Oct 2024 15:48:23 +0100 Subject: [PATCH] fix(wm): check exhaustively for ws emptiness This commit creates a new function for the workspaces to check if they are empty or not. This function properly accounts for maximized windows, monocle windows and floating windows. This should fix the cases where the WM was checking if the workspace was empty to focus the desktop in order to loose focus from previously focused window. Previously it wasn't checking for floating windows so it cause continues focus flickering when there were only floating windows on the workspace. --- komorebi/src/window_manager.rs | 2 +- komorebi/src/workspace.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 4631ea7c..949434df 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -852,7 +852,7 @@ impl WindowManager { } } } else { - if self.focused_workspace()?.containers().is_empty() { + if self.focused_workspace()?.is_empty() { let desktop_window = Window::from(WindowsApi::desktop_window()?); match WindowsApi::raise_and_focus_window(desktop_window.hwnd) { diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index a7392159..18f1d5e1 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -597,6 +597,13 @@ impl Workspace { Ok(false) } + pub fn is_empty(&self) -> bool { + self.containers().is_empty() + && self.maximized_window().is_none() + && self.monocle_container().is_none() + && self.floating_windows().is_empty() + } + pub fn contains_window(&self, hwnd: isize) -> bool { for container in self.containers() { if container.contains_window(hwnd) {