From 311e37c8a2a9f212ebbc784cc26d1187f4547bb6 Mon Sep 17 00:00:00 2001 From: James Tucker Date: Sat, 13 Apr 2024 17:29:42 -0700 Subject: [PATCH] fix(wm): reduce errors from non-window events As we have been working down some bugs from earlier changes, we introduced some additional error conditions in the logs. Now that the new focus approach is available, switching the stackbar to that means we can avoid needing to pass down ForceUpdate and FocusChange events for non-windows, which removes many of these cases. In addition we do a check in should_manage that the target object is actually a window, ignoring the event if it is not. --- komorebi/src/process_event.rs | 9 +-------- komorebi/src/stackbar.rs | 12 +++--------- komorebi/src/window.rs | 5 ++++- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index 12f146de1..5d714117a 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -92,14 +92,7 @@ impl WindowManager { // All event handlers below this point should only be processed if the event is // related to a window that should be managed by the WindowManager. - if !should_manage - && !matches!( - event, - WindowManagerEvent::DisplayChange(_) - | WindowManagerEvent::ForceUpdate(_) - | WindowManagerEvent::FocusChange(_, _) - ) - { + if !should_manage && !matches!(event, WindowManagerEvent::DisplayChange(_)) { return Ok(()); } diff --git a/komorebi/src/stackbar.rs b/komorebi/src/stackbar.rs index eaff13380..33caa7f6a 100644 --- a/komorebi/src/stackbar.rs +++ b/komorebi/src/stackbar.rs @@ -55,9 +55,6 @@ use komorebi_core::Rect; use crate::window::Window; use crate::windows_api::WindowsApi; -use crate::winevent::WinEvent; -use crate::winevent_listener; -use crate::WindowManagerEvent; use crate::DEFAULT_CONTAINER_PADDING; use crate::STACKBAR_FOCUSED_TEXT_COLOUR; use crate::STACKBAR_TAB_BACKGROUND_COLOUR; @@ -116,12 +113,9 @@ impl Stackbar { if x >= left && x <= right && y >= top && y <= bottom { let window = Window { hwnd: *win_hwnd }; - let event_sender = winevent_listener::event_tx(); - let _ = event_sender.send(WindowManagerEvent::FocusChange( - WinEvent::ObjectFocus, - window, - )); - let _ = event_sender.send(WindowManagerEvent::ForceUpdate(window)); + if let Err(err) = window.focus(false) { + tracing::error!("Stackbar focus error: HWND:{} {}", *win_hwnd, err); + } } } } diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index 55b296346..5857ae891 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -315,7 +315,10 @@ impl Window { #[tracing::instrument(fields(exe, title))] pub fn should_manage(self, event: Option) -> Result { - #[allow(clippy::question_mark)] + if !self.is_window() { + return Ok(false); + } + if self.title().is_err() { return Ok(false); }