Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(cua-driver): surface system overlay windows in list_windows and get_window_state (#1452)

Pavel Klymenko5b3915f2de42
diff --git a/libs/cua-driver/Sources/CuaDriverCore/AppState/AppState.swift b/libs/cua-driver/Sources/CuaDriverCore/AppState/AppState.swift
index 65b4cbfd71..2768563130 100644
--- a/libs/cua-driver/Sources/CuaDriverCore/AppState/AppState.swift
+++ b/libs/cua-driver/Sources/CuaDriverCore/AppState/AppState.swift
@@ -265,10 +265,17 @@ public actor AppStateEngine {
var nextIndex = 0
var markdown = ""
+ let layer0WindowIds: Set<CGWindowID> = Set(
+ WindowEnumerator.allWindows()
+ .filter { $0.layer == 0 }
+ .map { CGWindowID($0.id) }
+ )
+
renderTree(
root,
depth: 0,
targetWindowId: windowId,
+ layer0WindowIds: layer0WindowIds,
elements: &elements,
nextIndex: &nextIndex,
output: &markdown
@@ -510,6 +517,7 @@ public actor AppStateEngine {
_ element: AXUIElement,
depth: Int,
targetWindowId: UInt32?,
+ layer0WindowIds: Set<CGWindowID> = [],
elements: inout [Int: AXUIElement],
nextIndex: inout Int,
output: inout String
@@ -595,7 +603,8 @@ public actor AppStateEngine {
// windows whose CGWindowID we can't read.
return true
}
- return cgWindowId == targetWid
+ if cgWindowId == targetWid { return true }
+ return !layer0WindowIds.contains(cgWindowId)
}
}
@@ -604,6 +613,7 @@ public actor AppStateEngine {
child,
depth: depth + 1,
targetWindowId: targetWindowId,
+ layer0WindowIds: layer0WindowIds,
elements: &elements,
nextIndex: &nextIndex,
output: &output
diff --git a/libs/cua-driver/Sources/CuaDriverServer/Tools/ListWindowsTool.swift b/libs/cua-driver/Sources/CuaDriverServer/Tools/ListWindowsTool.swift
index e8b6e95527..63f71601b6 100644
--- a/libs/cua-driver/Sources/CuaDriverServer/Tools/ListWindowsTool.swift
+++ b/libs/cua-driver/Sources/CuaDriverServer/Tools/ListWindowsTool.swift
@@ -98,9 +98,10 @@ public enum ListWindowsTool {
: WindowEnumerator.allWindows()
let windows = raw
- .filter { $0.layer == 0 }
.filter { info in
- guard let pid = pidFilter else { return true }
+ guard let pid = pidFilter else {
+ return info.layer == 0
+ }
return info.pid == pid
}