From 56881e30914ba13d1f87b7a6f31724756b019581 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Wed, 18 Nov 2026 13:51:00 -0800 Subject: [PATCH] fix(computer-use): observe an app's floating and panel-level windows --- apps/desktop/native/computer-use/ComputerUse.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/desktop/native/computer-use/ComputerUse.swift b/apps/desktop/native/computer-use/ComputerUse.swift index 3c3fc161b8a..d969705077a 100644 --- a/apps/desktop/native/computer-use/ComputerUse.swift +++ b/apps/desktop/native/computer-use/ComputerUse.swift @@ -252,9 +252,16 @@ func appFor(_ bundleId: String?, launch: Bool = false) async throws -> NSRunning func requireAccessibility() throws { guard AXIsProcessTrusted() else { throw ComputerError("accessibility_permission_required", "Enable Accessibility for Mothership in System Settings, then retry.") } } +/// The app's window-list entries at document, floating and panel levels. Calendar's event inspector is a +/// panel-level window, so it must be observable; the Dock level and above (menus, status items, +/// overlays) holds no app window. func windowsFor(_ pid: pid_t) -> [[String: Any]] { guard let entries = CGWindowListCopyWindowInfo([.optionAll, .excludeDesktopElements], kCGNullWindowID) as? [[String: Any]] else { return [] } - return entries.filter { ($0[kCGWindowOwnerPID as String] as? NSNumber)?.int32Value == pid && ($0[kCGWindowLayer as String] as? Int) == 0 } + let dockLevel = Int(CGWindowLevelForKey(.dockWindow)) + return entries.filter { entry in + guard (entry[kCGWindowOwnerPID as String] as? NSNumber)?.int32Value == pid, let layer = entry[kCGWindowLayer as String] as? Int else { return false } + return layer >= 0 && layer < dockLevel + } } /// Whether the app has a window an observation can list: an Accessibility window whose frame matches /// one of its window-list entries, the match `get_app_state` uses. A minimized window counts, since it