Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
fix(cua-driver): list untitled X11 windows the window manager manages (#5341)
injaneity57a01e6fb4cb
diff --git a/libs/cua-driver/rust/crates/platform-linux/src/pointer_shape.rs b/libs/cua-driver/rust/crates/platform-linux/src/pointer_shape.rsindex caccb20704..2e02bcb78b 100644--- a/libs/cua-driver/rust/crates/platform-linux/src/pointer_shape.rs+++ b/libs/cua-driver/rust/crates/platform-linux/src/pointer_shape.rs@@ -127,7 +127,7 @@ impl LinuxPointerShape {fn x11_top_level_at(&self, x: f64, y: f64) -> Option<TopLevel> {self.with_x11(|conn, root| {- let windows = crate::x11::get_window_list(conn, root).ok()?;+ let (windows, _) = crate::x11::get_window_list(conn, root).ok()?;let atom = |n: &str| crate::x11::get_atom(conn, n).ok();let frame_extents = atom("_NET_FRAME_EXTENTS");let wm_state = atom("_NET_WM_STATE");diff --git a/libs/cua-driver/rust/crates/platform-linux/src/x11/mod.rs b/libs/cua-driver/rust/crates/platform-linux/src/x11/mod.rsindex d73693d876..a1bdf0b73e 100644--- a/libs/cua-driver/rust/crates/platform-linux/src/x11/mod.rs+++ b/libs/cua-driver/rust/crates/platform-linux/src/x11/mod.rs@@ -94,7 +94,7 @@ fn list_windows_inner(filter_pid: Option<u32>) -> Result<Vec<WindowInfo>> {let root = screen.root;// Get _NET_CLIENT_LIST_STACKING (or fallback to _NET_CLIENT_LIST).- let windows = get_window_list(&conn, root)?;+ let (windows, source) = get_window_list(&conn, root)?;let owners = OwnerResolver::new(&conn);let mut result = Vec::new();@@ -107,7 +107,7 @@ fn list_windows_inner(filter_pid: Option<u32>) -> Result<Vec<WindowInfo>> {}let title = get_window_title(&conn, xid).unwrap_or_default();- if title.trim().is_empty() {+ if !window_is_listable(source, &title) {continue;}let app_name = get_window_class(&conn, xid)@@ -150,7 +150,25 @@ fn list_windows_inner(filter_pid: Option<u32>) -> Result<Vec<WindowInfo>> {Ok(result)}-pub(crate) fn get_window_list(conn: &RustConnection, root: Window) -> Result<Vec<Window>> {+#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub(crate) enum WindowSource {+ ClientList,+ RootChildren,+}++/// A window the window manager manages is listed even without a title: GTK+/// message dialogs (a LibreOffice or GIMP confirmation) are untitled, and one+/// is often the modal window holding the focus. Without a window manager the+/// title is the only hint that a mapped root child is an application window+/// rather than a popup or tooltip.+fn window_is_listable(source: WindowSource, title: &str) -> bool {+ source == WindowSource::ClientList || !title.trim().is_empty()+}++pub(crate) fn get_window_list(+ conn: &RustConnection,+ root: Window,+) -> Result<(Vec<Window>, WindowSource)> {let atom_names = ["_NET_CLIENT_LIST_STACKING", "_NET_CLIENT_LIST"];for name in &atom_names {if let Ok(atom) = get_atom(conn, name) {@@ -163,7 +181,7 @@ pub(crate) fn get_window_list(conn: &RustConnection, root: Window) -> Result<Vec.map(|iter| iter.collect()).unwrap_or_default();if client_list_property(reply.type_, windows.as_slice()).is_some() {- return Ok(windows);+ return Ok((windows, WindowSource::ClientList));}}}@@ -173,7 +191,7 @@ pub(crate) fn get_window_list(conn: &RustConnection, root: Window) -> Result<Vec// that case only expose mapped root children; unmapped Electron children// can otherwise be reported before a late-starting WM reparents them.let tree = conn.query_tree(root)?.reply()?;- Ok(tree+ let windows = tree.children.into_iter().filter(|window| {@@ -183,7 +201,8 @@ pub(crate) fn get_window_list(conn: &RustConnection, root: Window) -> Result<Vec.map(|attributes| fallback_window_is_listable(attributes.map_state)).unwrap_or(false)})- .collect())+ .collect();+ Ok((windows, WindowSource::RootChildren))}fn client_list_property(property_type: Atom, windows: &[Window]) -> Option<&[Window]> {@@ -743,6 +762,17 @@ mod tests {assert!(!window_owner_matches(None, 42));}+ #[test]+ fn untitled_windows_are_listed_only_when_the_window_manager_manages_them() {+ assert!(window_is_listable(WindowSource::ClientList, ""));+ assert!(window_is_listable(WindowSource::ClientList, "Save Changes"));+ assert!(window_is_listable(+ WindowSource::RootChildren,+ "Save Changes"+ ));+ assert!(!window_is_listable(WindowSource::RootChildren, " "));+ }+#[test]fn query_tree_fallback_only_lists_viewable_windows() {assert!(fallback_window_is_listable(MapState::VIEWABLE));