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)