Skip to main content

basic/
basic.rs

1use std::time::Duration;
2
3use agent_seat_linux::{ComputerUse, LaunchConfig, PointerButton};
4
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let mut arguments = std::env::args_os().skip(1);
7    let program = arguments
8        .next()
9        .unwrap_or_else(|| "gnome-calculator".into());
10    let harness = ComputerUse::builder()
11        .native_timeout(Duration::from_secs(8))
12        .fallback_timeout(Duration::from_secs(30))
13        .bridge_geometry(1280, 800)
14        .build()?;
15    let mut app = harness.launch(LaunchConfig::new(program).args(arguments))?;
16
17    let frame = app.capture()?;
18    println!(
19        "controlled pid={} transport={:?} frame={}x{}",
20        app.pid(),
21        app.transport(),
22        frame.width,
23        frame.height
24    );
25    frame.image.save("agent-seat-frame.png")?;
26
27    // Harmlessly focus the center of the captured app to prove pointer input.
28    app.click(
29        f64::from(frame.width) / 2.0,
30        f64::from(frame.height) / 2.0,
31        PointerButton::Left,
32        1,
33    )?;
34
35    app.stop();
36    Ok(())
37}