From 6204a88792f36c64d1f9027dd51e1bf0613b0dca Mon Sep 17 00:00:00 2001 From: max Date: Tue, 8 Sep 2026 23:37:54 +0200 Subject: [PATCH] feat(window_manager): use OpenInputDesktop in find_window_by_match and exclude Catser overlay Ensures desktop window enumeration accesses the user's interactive desktop station across multiple monitors and ignores Catser's own overlay window. --- catser/window_manager.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/catser/window_manager.py b/catser/window_manager.py index 4c4585d..80afc4d 100644 --- a/catser/window_manager.py +++ b/catser/window_manager.py @@ -174,7 +174,9 @@ class WindowManager: process_predicate: Optional[Callable[[str], bool]] = None, ) -> Optional[WindowInfo]: """ - Enumerates top-level desktop windows to find the first matching window. + Enumerates top-level desktop windows to find the first matching visible window. + Uses the user's interactive input desktop to ensure windows across all monitors + are discovered even if the calling thread has a different default desktop. """ found_hwnd = None @@ -189,6 +191,10 @@ class WindowManager: if not title: return True + # Never target Catser's own overlay window + if "catser overlay" in title.lower(): + return True + if title_predicate and title_predicate(title): found_hwnd = hwnd return False # Stop enumeration @@ -201,7 +207,12 @@ class WindowManager: return True - user32.EnumWindows(WNDENUMPROC(enum_proc), 0) + h_input_desk = user32.OpenInputDesktop(0, False, 0x01FF) + if h_input_desk: + user32.EnumDesktopWindows(h_input_desk, WNDENUMPROC(enum_proc), 0) + user32.CloseDesktop(h_input_desk) + else: + user32.EnumWindows(WNDENUMPROC(enum_proc), 0) if found_hwnd: return cls.get_window_info(found_hwnd)