Skip to content

Commit b9f8cac

Browse files
committed
fix(desktop): refuse input to windows whose identity is ambiguous
Window-list entries match their Accessibility windows only by bounds; when two windows share bounds neither gets an identity, so input aimed at either is refused instead of possibly reaching the other.
1 parent bc55309 commit b9f8cac

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎apps/desktop/native/computer-use/ComputerUse.swift‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,11 @@ final class Driver {
558558
let windows = windowsFor(app.processIdentifier).prefix(100).compactMap { entry -> [String: Any]? in
559559
guard let id = entry[kCGWindowNumber as String] as? NSNumber, let bounds = entry[kCGWindowBounds as String] as? [String: Any], let rect = CGRect(dictionaryRepresentation: bounds as CFDictionary), rect.width > 0, rect.height > 0, axWindowFrames.contains(rect) else { return nil }
560560
snapshot.windowFrames[id.stringValue] = rect
561-
snapshot.windowElements[id.stringValue] = axWindows.first { elementRect($0) == rect }
561+
// Public APIs match a window-list entry to its Accessibility window only by bounds; when
562+
// two windows share bounds that match is ambiguous, so neither gets an identity and
563+
// input aimed at either is refused.
564+
let matches = axWindows.filter { elementRect($0) == rect }
565+
if matches.count == 1 { snapshot.windowElements[id.stringValue] = matches[0] }
562566
var result: [String: Any] = ["windowId": id.stringValue, "title": entry[kCGWindowName as String] as? String ?? ""]
563567
if let title = result["title"] as? String { result["title"] = String(title.prefix(4096)) }
564568
result.merge(rectJSON(rect)) { _, new in new }; return result

0 commit comments

Comments
 (0)