From 38b0418c3b28550fbb87ac553e00153b30063a05 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 2 Mar 2024 11:15:18 -0800 Subject: [PATCH] fix(subscriptions): emit ws event on empty targets This commit ensures that workspace change events get emitted even when changing to workspaces with no window containers. Previously these were failing due to early returns triggered when the workspace focused did not have a focused container. --- komorebi/src/process_command.rs | 12 ++++++++---- komorebi/src/window_manager.rs | 13 +++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 09f85696..12081758 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -1389,10 +1389,14 @@ impl WindowManager { ); } - let stack = BORDER_COLOUR_STACK.load(Ordering::SeqCst); - if stack != 0 && self.focused_container()?.windows().len() > 1 { - BORDER_COLOUR_CURRENT - .store(stack, Ordering::SeqCst); + // it is not acceptable to fail here; we need to be able to send the event to + // subscribers + if self.focused_container().is_ok() { + let stack = BORDER_COLOUR_STACK.load(Ordering::SeqCst); + if stack != 0 && self.focused_container()?.windows().len() > 1 { + BORDER_COLOUR_CURRENT + .store(stack, Ordering::SeqCst); + } } let border = Border::from(BORDER_HWND.load(Ordering::SeqCst)); diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 72b4e508..0f0a2879 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -852,17 +852,18 @@ impl WindowManager { } } - // if we passed false for follow_focus - if !follow_focus + // if we passed false for follow_focus and there is a container on the workspace + if !follow_focus && self.focused_container_mut().is_ok() { // and we have a stack with >1 windows - && self.focused_container_mut()?.windows().len() > 1 + if self.focused_container_mut()?.windows().len() > 1 // and we don't have a maxed window && self.focused_workspace()?.maximized_window().is_none() // and we don't have a monocle container && self.focused_workspace()?.monocle_container().is_none() - { - if let Ok(window) = self.focused_window_mut() { - window.focus(self.mouse_follows_focus)?; + { + if let Ok(window) = self.focused_window_mut() { + window.focus(self.mouse_follows_focus)?; + } } };