From fe8dbca2043e26dc67512798ee14d93043fdf5d7 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 31 Oct 2025 19:16:53 -0700 Subject: [PATCH] fix(wm): expand hack from 4d25d4e for chrome This commit expands the hack introduced in 4d25d4e which deals with inconsistent window titles returned by apps from different macOS APIs. The same issue that was happening with Activity Monitor was also happening with Google Chrome, so this hack has been updated to a more general "contains" check. --- komorebi/src/application.rs | 6 +++--- komorebi/src/macos_api.rs | 1 + komorebi/src/workspace.rs | 7 ++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/komorebi/src/application.rs b/komorebi/src/application.rs index d7b33071..f34b3b61 100644 --- a/komorebi/src/application.rs +++ b/komorebi/src/application.rs @@ -189,9 +189,9 @@ impl Application { if let Some(window_title) = window.title() && (window_title.eq(title) - // TODO: find a better way to deal with these hacks - || (self.name().unwrap_or_default() == "Activity Monitor" - && window_title.starts_with(title))) + // a hack for handling already-launched apps with inconsistent titles when + // komorebi launches, such as Activity Monitor, Google Chrome, and counting... + || window_title.contains(title)) { target = Some(window); } diff --git a/komorebi/src/macos_api.rs b/komorebi/src/macos_api.rs index c58221c3..dfe13e08 100644 --- a/komorebi/src/macos_api.rs +++ b/komorebi/src/macos_api.rs @@ -371,6 +371,7 @@ impl MacosApi { )?) } + // #[track_caller] // use this to with std::panic::Location::caller() to debug failures #[tracing::instrument(skip_all)] pub fn window_rect(element: &AXUIElement) -> Result { let mut position_receiver = std::ptr::null(); diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index c9b22f38..79449a82 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -1171,9 +1171,10 @@ impl Workspace { layout.add_padding(border_width); for window in container.windows_mut() { - let current_percentage = work_area.percentage_within_horizontal_bounds( - &Rect::from(MacosApi::window_rect(&window.element)?), - ); + let current_rect = + MacosApi::window_rect(&window.element).unwrap_or_default(); + let current_percentage = work_area + .percentage_within_horizontal_bounds(&Rect::from(current_rect)); let proposed_percentage = work_area.percentage_within_horizontal_bounds(layout);