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): resolve launch_app to the app window, not a launcher splash (#5342)
injaneity1d114c21f95f
diff --git a/libs/cua-driver/rust/crates/platform-linux/src/tools/impl_.rs b/libs/cua-driver/rust/crates/platform-linux/src/tools/impl_.rsindex 8b45428caf..3be700798b 100644--- a/libs/cua-driver/rust/crates/platform-linux/src/tools/impl_.rs+++ b/libs/cua-driver/rust/crates/platform-linux/src/tools/impl_.rs@@ -2326,31 +2326,10 @@ fn resolve_launched_windows(let started = std::time::Instant::now();loop {let all = crate::wayland::list_windows_dispatch(None);- let own: Vec<_> = all- .iter()- .filter(|w| w.pid == Some(launcher_pid))- .cloned()- .collect();- if !own.is_empty() {- return LaunchedWindows {- pid: Some(launcher_pid),- windows: own,- handed_off: false,- };- }- let fresh: Vec<_> = all- .iter()- .filter(|w| !before.contains(&w.xid) && w.pid.is_some())- .filter(|w| window_matches_launch(w, query))- .cloned()- .collect();- if let Some(pid) = fresh.first().and_then(|w| w.pid) {- let windows = fresh.into_iter().filter(|w| w.pid == Some(pid)).collect();- return LaunchedWindows {- pid: Some(pid),- windows,- handed_off: true,- };+ if let Some(launched) = settle_launch(&all, launcher_pid, query, before, |w| {+ crate::x11::window_is_splash(w.xid)+ }) {+ return launched;}let launcher_exited = process_exited(launcher_pid);let budget = if launcher_exited {@@ -2369,6 +2348,39 @@ fn resolve_launched_windows(}}+fn settle_launch(+ all: &[crate::x11::WindowInfo],+ launcher_pid: u32,+ query: &str,+ before: &std::collections::HashSet<u64>,+ is_splash: impl Fn(&crate::x11::WindowInfo) -> bool,+) -> Option<LaunchedWindows> {+ let own: Vec<_> = all+ .iter()+ .filter(|w| w.pid == Some(launcher_pid) && !is_splash(w))+ .cloned()+ .collect();+ if !own.is_empty() {+ return Some(LaunchedWindows {+ pid: Some(launcher_pid),+ windows: own,+ handed_off: false,+ });+ }+ let fresh: Vec<_> = all+ .iter()+ .filter(|w| !before.contains(&w.xid) && w.pid.is_some())+ .filter(|w| window_matches_launch(w, query) && !is_splash(w))+ .cloned()+ .collect();+ let pid = fresh.first()?.pid?;+ Some(LaunchedWindows {+ pid: Some(pid),+ windows: fresh.into_iter().filter(|w| w.pid == Some(pid)).collect(),+ handed_off: true,+ })+}+#[cfg(test)]mod launch_resolution_tests;diff --git a/libs/cua-driver/rust/crates/platform-linux/src/tools/impl_/launch_resolution_tests.rs b/libs/cua-driver/rust/crates/platform-linux/src/tools/impl_/launch_resolution_tests.rsindex 472e922f8f..614c4f1028 100644--- a/libs/cua-driver/rust/crates/platform-linux/src/tools/impl_/launch_resolution_tests.rs+++ b/libs/cua-driver/rust/crates/platform-linux/src/tools/impl_/launch_resolution_tests.rs@@ -49,6 +49,35 @@ fn launch_queries_match_window_classes() {assert!(!window_matches_launch(&window(""), "nautilus"));}+fn owned(xid: u64, pid: u32, class: &str) -> crate::x11::WindowInfo {+ crate::x11::WindowInfo {+ xid,+ pid: Some(pid),+ ..window(class)+ }+}++#[test]+fn a_launcher_splash_waits_for_the_app_window() {+ let splash = owned(10, 377, "libreoffice");+ let calc = owned(20, 398, "libreoffice-calc");+ let none = std::collections::HashSet::new();+ let is_splash = |w: &crate::x11::WindowInfo| w.xid == 10;++ assert!(settle_launch(&[splash.clone()], 377, "libreoffice", &none, is_splash).is_none());++ let launched = settle_launch(&[splash, calc], 377, "libreoffice", &none, is_splash).unwrap();+ assert_eq!(launched.pid, Some(398));+ assert_eq!(+ launched.windows.iter().map(|w| w.xid).collect::<Vec<_>>(),+ [20]+ );++ let gimp = owned(30, 377, "gimp");+ let launched = settle_launch(&[gimp], 377, "gimp", &none, is_splash).unwrap();+ assert_eq!((launched.pid, launched.handed_off), (Some(377), false));+}+#[test]fn a_missing_process_counts_as_exited() {assert!(process_exited(u32::MAX - 1));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 55420ba732..d73693d876 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@@ -504,6 +504,28 @@ pub fn window_is_modal(xid: u64) -> bool {.is_some_and(|atoms| atoms.contains(&modal_atom))}+/// `_NET_WM_WINDOW_TYPE` carries `_NET_WM_WINDOW_TYPE_SPLASH`: a startup+/// screen, often drawn by a launcher process that never owns the app window.+pub fn window_is_splash(xid: u64) -> bool {+ let Ok(xid) = u32::try_from(xid) else {+ return false;+ };+ let Ok((conn, _)) = RustConnection::connect(None) else {+ return false;+ };+ let (Ok(type_atom), Ok(splash_atom)) = (+ get_atom(&conn, "_NET_WM_WINDOW_TYPE"),+ get_atom(&conn, "_NET_WM_WINDOW_TYPE_SPLASH"),+ ) else {+ return false;+ };+ conn.get_property(false, xid, type_atom, AtomEnum::ATOM, 0, 64)+ .ok()+ .and_then(|cookie| cookie.reply().ok())+ .and_then(|reply| reply.value32().map(|atoms| atoms.collect::<Vec<_>>()))+ .is_some_and(|atoms| atoms.contains(&splash_atom))+}+/// True while `xid` exists on the server and is viewable.pub fn window_is_viewable(xid: u64) -> bool {window_info(xid).is_some_and(|w| w.is_on_screen)