Skip to content

Computer use CLI for AI agents

fix(windows): stop scaling the overlay's coordinates twice (#343)

Chris Tate9b1a43464ee5
diff --git a/crates/windows/src/system/cursor_overlay/mod.rs b/crates/windows/src/system/cursor_overlay/mod.rs
index 4bad5c662..977b3dc49 100644
--- a/crates/windows/src/system/cursor_overlay/mod.rs
+++ b/crates/windows/src/system/cursor_overlay/mod.rs
@@ -17,7 +17,6 @@ pub(crate) mod child;
pub(crate) mod dib;
#[cfg(target_os = "windows")]
pub(crate) mod discover;
-#[cfg(target_os = "windows")]
pub(crate) mod display_probe;
pub(crate) mod fade;
pub(crate) mod framing;
diff --git a/crates/windows/src/system/cursor_overlay/monitors.rs b/crates/windows/src/system/cursor_overlay/monitors.rs
index 622fa1cdb..8c285761f 100644
--- a/crates/windows/src/system/cursor_overlay/monitors.rs
+++ b/crates/windows/src/system/cursor_overlay/monitors.rs
@@ -1,10 +1,13 @@
-//! Which monitor a point belongs to, and where on it the overlay draws.
+//! Which monitor a point belongs to, and where the overlay rests.
//!
//! Pure functions over a supplied monitor list, which is the whole point:
//! A29-6 records this host as one monitor at one scale, so a mixed-DPI or
//! multi-monitor arrangement cannot be observed here. Keeping the selection
-//! and the mapping free of Win32 is what lets a test present an arrangement
-//! the desktop cannot.
+//! free of Win32 is what lets a test present an arrangement the desktop
+//! cannot.
+//!
+//! Points arrive in physical pixels, because the CLI and the renderer are both
+//! per-monitor DPI aware, so the overlay draws at them without scaling.
//!
//! The list is crate-local rather than core's `DisplayInfo`, and that is a
//! decision rather than an oversight. `DisplayInfo` carries id, bounds,
@@ -60,18 +63,6 @@ pub(crate) fn resting_point(monitors: &[OverlayMonitor]) -> Option<Point> {
})
}
-/// A logical point mapped to the physical pixel it names on its own monitor.
-///
-/// The virtual screen origin is not necessarily zero — a monitor placed left
-/// of or above the primary has negative coordinates — so the scale is applied
-/// to the offset within the monitor rather than to the raw coordinate.
-pub(crate) fn to_physical(monitor: &OverlayMonitor, point: &Point) -> Point {
- Point {
- x: monitor.bounds.x + (point.x - monitor.bounds.x) * monitor.scale,
- y: monitor.bounds.y + (point.y - monitor.bounds.y) * monitor.scale,
- }
-}
-
fn contains(bounds: &Rect, point: &Point) -> bool {
point.x >= bounds.x
&& point.x < bounds.x + bounds.width
diff --git a/crates/windows/src/system/cursor_overlay/monitors_tests.rs b/crates/windows/src/system/cursor_overlay/monitors_tests.rs
index a7d8d96cc..d8ae47a11 100644
--- a/crates/windows/src/system/cursor_overlay/monitors_tests.rs
+++ b/crates/windows/src/system/cursor_overlay/monitors_tests.rs
@@ -1,4 +1,4 @@
-use super::{OverlayMonitor, monitor_for_point, resting_point, to_physical};
+use super::{OverlayMonitor, monitor_for_point, resting_point};
use agent_desktop_core::{Point, Rect};
/// Takes the bounds as a `Rect` rather than four loose numbers, so a
@@ -61,10 +61,9 @@ fn a_point_inside_the_primary_selects_the_primary() {
}
/// A monitor left of or above the primary has negative coordinates, so a
-/// mapping that assumed a zero origin would put the cursor on the wrong
-/// screen entirely.
+/// selection that assumed a zero origin would pick the wrong screen entirely.
#[test]
-fn a_monitor_at_a_negative_origin_is_selected_and_mapped_correctly() {
+fn a_monitor_at_a_negative_origin_is_selected() {
let monitors = vec![
monitor(bounds(0.0, 0.0, 1920.0, 1080.0), 1.0, true),
monitor(bounds(-1280.0, -200.0, 1280.0, 800.0), 2.0, false),
@@ -72,10 +71,6 @@ fn a_monitor_at_a_negative_origin_is_selected_and_mapped_correctly() {
let selected = monitor_for_point(&monitors, &Point { x: -600.0, y: 0.0 }).expect("selects");
assert_eq!(selected, &monitors[1]);
-
- let physical = to_physical(selected, &Point { x: -600.0, y: 0.0 });
- assert_eq!(physical.x, -1280.0 + (-600.0 - -1280.0) * 2.0);
- assert_eq!(physical.y, -200.0 + (0.0 - -200.0) * 2.0);
}
/// A point between two non-adjacent monitors belongs to neither. Answering
@@ -100,27 +95,6 @@ fn a_point_in_the_gap_selects_the_nearest_monitor_deterministically() {
);
}
-#[test]
-fn a_scaled_monitor_maps_a_logical_point_to_its_physical_pixel() {
- let monitors = scaled_pair();
- let scaled = &monitors[1];
- let logical = Point {
- x: 2000.0,
- y: 100.0,
- };
-
- let physical = to_physical(scaled, &logical);
- assert_eq!(physical.x, 1920.0 + 80.0 * 1.5);
- assert_eq!(physical.y, 0.0 + 100.0 * 1.5);
-
- let unscaled = to_physical(&monitors[0], &logical);
- assert_eq!(
- unscaled, logical,
- "an unscaled monitor maps a point to itself, so the scaling above belongs to the \
- monitor rather than to the function"
- );
-}
-
#[test]
fn the_resting_point_is_the_primary_work_areas_midpoint() {
let monitors = scaled_pair();
diff --git a/crates/windows/src/system/cursor_overlay/surface_host.rs b/crates/windows/src/system/cursor_overlay/surface_host.rs
index 365181105..e4d2147cc 100644
--- a/crates/windows/src/system/cursor_overlay/surface_host.rs
+++ b/crates/windows/src/system/cursor_overlay/surface_host.rs
@@ -266,14 +266,10 @@ impl SurfaceHost {
fade::dim_region(&mut composed.surface, &card, self.card_opacity());
}
fade::dim_surface(&mut composed.surface, overlay_opacity);
- let placement = monitors::monitor_for_point(self.topology.monitors(), &composed.origin)
- .map_or(composed.origin.clone(), |monitor| {
- monitors::to_physical(monitor, &composed.origin)
- });
self.window.raise();
let _ = self.window.present(
- placement.x as i32,
- placement.y as i32,
+ composed.origin.x as i32,
+ composed.origin.y as i32,
composed.surface.width,
composed.surface.height,
&composed.surface.pixels,
diff --git a/skills/agent-desktop-windows/references/shell-and-overlay.md b/skills/agent-desktop-windows/references/shell-and-overlay.md
index d110b752e..d84e00af1 100644
--- a/skills/agent-desktop-windows/references/shell-and-overlay.md
+++ b/skills/agent-desktop-windows/references/shell-and-overlay.md
@@ -118,8 +118,9 @@ agent-desktop cursor-overlay disable
draws the card. Each `enable` and each action replaces the card text.
- **It fades out after 6 s with no instruction** and comes straight back on the
next command.
-- **Mixed-DPI and multi-monitor mapping is unit-tested only.** It is not
- verified on a live scaled or multi-monitor desktop.
+- **It draws in physical pixels**, the space element bounds are reported in,
+ so it is not scaled again for the monitor's DPI. Multi-monitor placement is
+ unit-tested only and not verified on a live multi-monitor desktop.
- **A harness job object takes the overlay with it.** A job with
`JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE`, which CI runners and some agent
harnesses use, ends the detached renderer when the job closes. A vanished