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): track cursor placement explicitly

injaneity88e6d9facd33
diff --git a/libs/cua-driver/rust/crates/cursor-overlay/examples/export_gallery_frames.rs b/libs/cua-driver/rust/crates/cursor-overlay/examples/export_gallery_frames.rs
index a0cfd49601..7b5735eba6 100644
--- a/libs/cua-driver/rust/crates/cursor-overlay/examples/export_gallery_frames.rs
+++ b/libs/cua-driver/rust/crates/cursor-overlay/examples/export_gallery_frames.rs
@@ -136,6 +136,7 @@ fn export_state(output: &Path, state: GalleryState) {
f64::from(SIZE) / (2.0 * f64::from(PREVIEW_BACKING_SCALE)),
f64::from(SIZE) / (2.0 * f64::from(PREVIEW_BACKING_SCALE)),
);
+ core.placed = true;
core.heading = f64::from(std::f32::consts::FRAC_PI_4);
if let Some(session_label) = state.session_label {
core.apply_command_base(
diff --git a/libs/cua-driver/rust/crates/cursor-overlay/src/render_map.rs b/libs/cua-driver/rust/crates/cursor-overlay/src/render_map.rs
index 6c4fc28095..5f7d29bfb0 100644
--- a/libs/cua-driver/rust/crates/cursor-overlay/src/render_map.rs
+++ b/libs/cua-driver/rust/crates/cursor-overlay/src/render_map.rs
@@ -309,7 +309,7 @@ impl<S: RenderEntry, P> RenderMap<S, P> {
/// following `MoveTo` glides in instead of snapping. Creates the cursor
/// when absent. Returns whether a seed was applied; a no-op for an ended
/// session, a disabled cursor, or one already on screen.
- pub fn seed_start_if_sentinel(
+ pub fn seed_start_if_unplaced(
&mut self,
key: &str,
target_x: f64,
@@ -320,10 +320,11 @@ impl<S: RenderEntry, P> RenderMap<S, P> {
return false;
};
let core = cursor.core_mut();
- if !(core.cfg.enabled && !crate::render_state::is_placed(core.pos)) {
+ if !(core.cfg.enabled && !core.placed) {
return false;
}
core.pos = seed_position(target_x, target_y, frame);
+ core.placed = true;
true
}
@@ -405,6 +406,7 @@ mod tests {
fn placed<'a>(map: &'a mut Map, key: &str) -> &'a mut RenderStateCore {
let core = map.cursor_mut(key).unwrap();
core.pos = (100.0, 100.0);
+ core.placed = true;
core
}
@@ -486,7 +488,7 @@ mod tests {
map.apply_msg(move_msg("sessA", 99.0, 99.0)),
MsgOutcome::Dropped("sessA".to_owned())
);
- assert!(!map.seed_start_if_sentinel("sessA", 60.0, 60.0, None));
+ assert!(!map.seed_start_if_unplaced("sessA", 60.0, 60.0, None));
assert!(!map.cursors.contains_key("sessA"));
// Removing a session that never drew is a harmless tombstone.
@@ -561,10 +563,10 @@ mod tests {
}
#[test]
- fn seed_places_a_sentinel_cursor_on_screen_once() {
+ fn seed_places_an_unplaced_cursor_on_screen_once() {
let mut map = map();
let frame = Some(ScreenFrame::new(0.0, 0.0, 100.0, 100.0));
- assert!(map.seed_start_if_sentinel("sessA", 60.0, 60.0, frame));
+ assert!(map.seed_start_if_unplaced("sessA", 60.0, 60.0, frame));
let pos = map.cursors["sessA"].pos;
assert!(
pos.0 > -50.0 && pos.1 > -50.0,
@@ -576,15 +578,29 @@ mod tests {
);
map.cursors["sessA"].pos = (30.0, 30.0);
- assert!(!map.seed_start_if_sentinel("sessA", 80.0, 80.0, frame));
+ map.cursors["sessA"].placed = true;
+ assert!(!map.seed_start_if_unplaced("sessA", 80.0, 80.0, frame));
assert_eq!(map.cursors["sessA"].pos, (30.0, 30.0));
// A cursor placed on a monitor left of the layout origin is no sentinel.
map.cursors["sessA"].pos = (-2220.0, 980.0);
- assert!(!map.seed_start_if_sentinel("sessA", 80.0, 80.0, frame));
+ map.cursors["sessA"].placed = true;
+ assert!(!map.seed_start_if_unplaced("sessA", 80.0, 80.0, frame));
assert_eq!(map.cursors["sessA"].pos, (-2220.0, 980.0));
map.cursor_mut("disabled").unwrap().cfg.enabled = false;
- assert!(!map.seed_start_if_sentinel("disabled", 80.0, 80.0, frame));
+ assert!(!map.seed_start_if_unplaced("disabled", 80.0, 80.0, frame));
+ }
+
+ #[test]
+ fn negative_frame_seed_establishes_placement_once() {
+ let mut map = map();
+ let frame = Some(ScreenFrame::new(-2000.0, -2000.0, 1000.0, 1000.0));
+ assert!(map.seed_start_if_unplaced("sessA", -1500.0, -1500.0, frame));
+ assert!(map.cursors["sessA"].placed);
+ let pos = map.cursors["sessA"].pos;
+ assert!(pos.0 < 0.0 && pos.1 < 0.0);
+ assert!(!map.seed_start_if_unplaced("sessA", -1400.0, -1400.0, frame));
+ assert_eq!(map.cursors["sessA"].pos, pos);
}
#[test]
diff --git a/libs/cua-driver/rust/crates/cursor-overlay/src/render_state.rs b/libs/cua-driver/rust/crates/cursor-overlay/src/render_state.rs
index 482d1867a0..c938ad9e87 100644
--- a/libs/cua-driver/rust/crates/cursor-overlay/src/render_state.rs
+++ b/libs/cua-driver/rust/crates/cursor-overlay/src/render_state.rs
@@ -103,17 +103,6 @@ impl MinimalChip {
}
}
-/// Position of a cursor that has never been placed. It lies far outside any
-/// compositor layout: layouts reach negative coordinates when a monitor sits
-/// left of or above the primary one, so a small negative sentinel (the old
-/// `(-200, -200)`) is indistinguishable from a real position there.
-pub const UNPLACED_POS: (f64, f64) = (-1.0e9, -1.0e9);
-
-/// Whether `pos` is a real position rather than [`UNPLACED_POS`].
-pub fn is_placed(pos: (f64, f64)) -> bool {
- pos.0 > -1.0e8
-}
-
/// Platform-agnostic render state shared by macOS / Windows / Linux overlays.
///
/// Each platform wraps this in its own struct that adds OS-specific fields
@@ -125,6 +114,8 @@ pub struct RenderStateCore {
pub motion: MotionConfig,
/// Current rendered position in screen / overlay-window coordinates.
pub pos: (f64, f64),
+ /// Whether a positioning command or seed has established a position.
+ pub placed: bool,
/// Visual heading in radians (tip direction = motion_dir + π).
pub heading: f64,
/// Planned move being played; `None` at rest. It stays a little past
@@ -200,9 +191,6 @@ pub struct RenderStateCore {
impl RenderStateCore {
/// Build the core from a launch-time CursorConfig.
- /// `pos` starts at the off-screen sentinel `(-200, -200)` to indicate
- /// "never placed on screen yet" — the click path uses this to detect
- /// first-placement and snap rather than animate.
pub fn new(cfg: CursorConfig) -> Self {
let motion = cfg.motion.clone();
let visual = CursorVisualState {
@@ -227,7 +215,8 @@ impl RenderStateCore {
semantic_cue: false,
theme,
theme_fallback,
- pos: UNPLACED_POS,
+ pos: (0.0, 0.0),
+ placed: false,
heading: std::f64::consts::FRAC_PI_4,
trajectory: None,
motion_t: 0.0,
@@ -342,10 +331,10 @@ impl RenderStateCore {
frame
}
- /// Whether the cursor currently paints pixels: user-visible, placed
- /// (not [`UNPLACED_POS`]), and not fully idle-faded.
+ /// Whether the cursor currently paints pixels: user-visible, placed,
+ /// and not fully idle-faded.
pub fn is_revealed(&self) -> bool {
- self.visible && is_placed(self.pos) && self.idle_alpha >= 0.004
+ self.visible && self.placed && self.idle_alpha >= 0.004
}
/// Whether a revealed cursor keeps changing pixels while it rests.
@@ -413,7 +402,7 @@ impl RenderStateCore {
/// the fade has already started.
pub fn idle_fade_wait(&self) -> Option<std::time::Duration> {
if !self.visible
- || !is_placed(self.pos)
+ || !self.placed
|| self.motion.idle_hide_ms <= 0.0
|| self.trajectory.is_some()
|| self.click_t.is_some()
@@ -771,12 +760,12 @@ impl RenderStateCore {
///
/// `move_to_snap_sentinel` controls macOS-only behaviour: when `true`,
/// `MoveTo` snaps `self.pos` to the offset target if the cursor is
- /// still at [`UNPLACED_POS`]. Windows/Linux
+ /// not yet placed. Windows/Linux
/// pass `false` here.
///
/// `click_pulse_sentinel_only` likewise controls macOS-only behaviour:
/// when `true`, `ClickPulse` only updates `self.pos` if the cursor is
- /// still at the sentinel (the animation already landed it there
+ /// not yet placed (the animation already landed it there
/// otherwise). Windows/Linux pass `false`, which always snaps
/// `self.pos` to the click point.
pub fn apply_command_base(
@@ -795,7 +784,7 @@ impl RenderStateCore {
let reveal_badge = !self.is_revealed();
// macOS-only: if the cursor has never been placed, put it on
// the target so the move starts on-screen.
- if move_to_snap_sentinel && !is_placed(self.pos) {
+ if move_to_snap_sentinel && !self.placed {
self.pos = crate::anchor_for_pointer(x, y, end_heading_radians);
self.heading = end_heading_radians;
}
@@ -824,6 +813,7 @@ impl RenderStateCore {
self.visual.begin(CursorAction::Navigate, delivery, target);
self.semantic_cue = false;
}
+ self.placed = true;
self.idle_secs = 0.0;
self.idle_alpha = 1.0;
if reveal_badge {
@@ -851,6 +841,7 @@ impl RenderStateCore {
self.visual.begin(CursorAction::Navigate, delivery, target);
self.semantic_cue = false;
}
+ self.placed = true;
self.idle_secs = 0.0;
self.idle_alpha = 1.0;
if reveal_badge {
@@ -870,7 +861,7 @@ impl RenderStateCore {
let end = traj.end();
self.motion_t < traj.duration() && (end.x - x).hypot(end.y - y) <= 2.0
});
- if (!click_pulse_sentinel_only || !is_placed(self.pos)) && !settling_here {
+ if (!click_pulse_sentinel_only || !self.placed) && !settling_here {
self.pos = crate::anchor_for_pointer(x, y, self.heading);
}
self.click_t = Some(0.0);
@@ -885,6 +876,7 @@ impl RenderStateCore {
self.visual.begin(CursorAction::Click, delivery, target);
self.semantic_cue = false;
}
+ self.placed = true;
self.idle_secs = 0.0;
self.idle_alpha = 1.0;
if reveal_badge {
@@ -1380,6 +1372,66 @@ mod glide_duration_tests {
use super::*;
use crate::{CursorConfig, MotionStyle};
+ #[test]
+ fn unplaced_coordinates_do_not_reveal_or_schedule_idle_fade() {
+ for pos in [(0.0, 0.0), (-200.0, -200.0), (-1.0e9, -1.0e9)] {
+ let mut core = RenderStateCore::new(CursorConfig::default());
+ core.pos = pos;
+ assert!(!core.is_revealed());
+ assert!(core.idle_fade_wait().is_none());
+ }
+ }
+
+ #[test]
+ fn positioning_establishes_placement_independent_of_coordinates() {
+ for macos in [false, true] {
+ for pos in [(-200.0, -200.0), (-1.0e9, -1.0e9)] {
+ for command in [
+ OverlayCommand::SnapTo {
+ x: pos.0,
+ y: pos.1,
+ heading_radians: None,
+ },
+ OverlayCommand::MoveTo {
+ x: pos.0,
+ y: pos.1,
+ end_heading_radians: 0.0,
+ target: None,
+ },
+ OverlayCommand::ClickPulse { x: pos.0, y: pos.1 },
+ ] {
+ let mut core = RenderStateCore::new(CursorConfig::default());
+ core.apply_command_base(command, macos, macos);
+ assert!(core.placed);
+ assert!(core.is_revealed());
+ core.apply_command_base(
+ OverlayCommand::SnapTo {
+ x: pos.0,
+ y: pos.1,
+ heading_radians: None,
+ },
+ macos,
+ macos,
+ );
+ core.apply_command_base(
+ OverlayCommand::MoveTo {
+ x: 50.0,
+ y: 50.0,
+ end_heading_radians: 0.0,
+ target: None,
+ },
+ macos,
+ macos,
+ );
+ assert_eq!(core.pos, pos);
+ assert!(core.trajectory.is_some());
+ core.apply_command_base(OverlayCommand::SetEnabled(false), macos, macos);
+ assert!(core.placed);
+ }
+ }
+ }
+ }
+
/// Run a move of `dist_pts` until it arrives and return how many seconds
/// it took.
fn arrival_secs(style: MotionStyle, glide_ms: f64, dist_pts: f64) -> f64 {
@@ -1391,6 +1443,7 @@ mod glide_duration_tests {
// effectively straight path of length ~dist_pts.
core.heading = std::f64::consts::PI;
core.pos = crate::anchor_for_pointer(0.0, 0.0, core.heading);
+ core.placed = true;
core.apply_command_base(
OverlayCommand::MoveTo {
x: dist_pts,
@@ -1437,6 +1490,7 @@ mod glide_duration_tests {
let mut core = RenderStateCore::new(CursorConfig::default());
core.motion.style = MotionStyle::SpringSettle;
core.pos = (100.0, 100.0);
+ core.placed = true;
core.apply_command_base(
OverlayCommand::MoveTo {
x: 700.0,
@@ -1473,6 +1527,7 @@ mod glide_duration_tests {
let mut core = RenderStateCore::new(CursorConfig::default());
core.motion.style = MotionStyle::CometSwoop;
core.pos = (100.0, 100.0);
+ core.placed = true;
core.apply_command_base(
OverlayCommand::MoveTo {
x: 900.0,
@@ -1515,6 +1570,7 @@ mod glide_duration_tests {
let mut core = RenderStateCore::new(CursorConfig::default());
core.motion.style = MotionStyle::CometSwoop;
core.pos = (100.0, 100.0);
+ core.placed = true;
core.apply_command_base(
OverlayCommand::MoveTo {
x: 900.0,
@@ -1552,6 +1608,7 @@ mod glide_duration_tests {
let mut core = RenderStateCore::new(CursorConfig::default());
core.motion.style = MotionStyle::CometSwoop;
core.pos = (100.0, 100.0);
+ core.placed = true;
core.apply_command_base(
OverlayCommand::MoveTo {
x: 900.0,
@@ -2024,6 +2081,7 @@ mod session_badge_and_action_tests {
fn hardware_pointer_hover_reveals_only_while_over_cursor() {
let mut core = RenderStateCore::new(CursorConfig::default());
core.pos = (300.0, 240.0);
+ core.placed = true;
core.apply_command_base(
OverlayCommand::SetSessionLabel("Research".into()),
false,
@@ -2049,6 +2107,7 @@ mod session_badge_and_action_tests {
for action in [CursorAction::Text, CursorAction::Click] {
let mut core = RenderStateCore::new(CursorConfig::default());
core.pos = (20.0, 20.0);
+ core.placed = true;
core.apply_command_base(
OverlayCommand::BeginAction {
action,
@@ -2097,6 +2156,7 @@ mod session_badge_and_action_tests {
fn modifiers_live_in_the_badge_then_fade_after_action_completion() {
let mut core = verbose_core();
core.pos = (200.0, 200.0);
+ core.placed = true;
core.apply_command_base(
OverlayCommand::BeginAction {
action: CursorAction::Click,
@@ -2200,6 +2260,7 @@ mod backing_scale_tests {
// idle-fade so the arrow paints at full alpha regardless of timing.
let centre = logical_size as f64 / 2.0;
core.pos = (centre, centre);
+ core.placed = true;
core.idle_alpha = 1.0;
core.visible = true;
@@ -2216,6 +2277,7 @@ mod backing_scale_tests {
fn cursor_pinned_to_an_off_workspace_window_paints_nothing() {
let mut core = RenderStateCore::new(CursorConfig::default());
core.pos = (32.0, 32.0);
+ core.placed = true;
core.idle_alpha = 1.0;
core.visible = true;
core.pinned_target_off_workspace = true;
@@ -2859,6 +2921,7 @@ mod motion_equivalence_tests {
};
core.effects_capable = capable;
core.pos = (100.0, 100.0);
+ core.placed = true;
let mut h = Bits::new();
let mut arrivals = 0;
let script: [(usize, OverlayCommand); 4] = [
diff --git a/libs/cua-driver/rust/crates/platform-linux/src/overlay.rs b/libs/cua-driver/rust/crates/platform-linux/src/overlay.rs
index 4e86686ab8..b4f504d711 100644
--- a/libs/cua-driver/rust/crates/platform-linux/src/overlay.rs
+++ b/libs/cua-driver/rust/crates/platform-linux/src/overlay.rs
@@ -594,20 +594,17 @@ pub fn is_visible_for_session(key: &str) -> bool {
.unwrap_or(false)
}
-pub fn current_position() -> (f64, f64) {
+pub fn current_position() -> Option<(f64, f64)> {
current_position_for("default")
}
-pub fn current_position_for(key: &str) -> (f64, f64) {
- RENDER
- .lock()
- .ok()
- .and_then(|g| {
- g.as_ref()
- .and_then(|m| m.cursors.get(key))
- .map(|rs| rs.core.pos)
- })
- .unwrap_or(cursor_overlay::render_state::UNPLACED_POS)
+pub fn current_position_for(key: &str) -> Option<(f64, f64)> {
+ RENDER.lock().ok().and_then(|g| {
+ g.as_ref()
+ .and_then(|m| m.cursors.get(key))
+ .filter(|rs| rs.core.placed)
+ .map(|rs| rs.core.pos)
+ })
}
pub fn current_motion_for(key: &str) -> cursor_overlay::MotionConfig {
@@ -639,7 +636,7 @@ pub fn current_theme_state_for(
Some((id, version, profile, fallback, state.core.visual.clone()))
}
-fn seed_start_if_sentinel(key: &CursorKey, target_x: f64, target_y: f64) -> bool {
+fn seed_start_if_unplaced(key: &CursorKey, target_x: f64, target_y: f64) -> bool {
let mut guard = RENDER.lock().unwrap();
let Some(map) = guard.as_mut() else {
return false;
@@ -650,7 +647,7 @@ fn seed_start_if_sentinel(key: &CursorKey, target_x: f64, target_y: f64) -> bool
f64::from(map.platform.scr_w),
f64::from(map.platform.scr_h),
);
- map.seed_start_if_sentinel(key, target_x, target_y, Some(frame))
+ map.seed_start_if_unplaced(key, target_x, target_y, Some(frame))
}
pub async fn animate_cursor_to(x: f64, y: f64) {
@@ -673,14 +670,14 @@ pub async fn animate_cursor_to_target_for(
if !draws_cursor(&key) {
return;
}
- seed_start_if_sentinel(&key, x, y);
+ seed_start_if_unplaced(&key, x, y);
let should_animate = {
let guard = RENDER.lock().unwrap();
matches!(
guard.as_ref().and_then(|m| m.cursors.get(&key)),
Some(rs) if rs.core.cfg.enabled
&& rs.core.visible
- && cursor_overlay::render_state::is_placed(rs.core.pos)
+ && rs.core.placed
)
};
if !should_animate {
@@ -3248,7 +3245,7 @@ mod tests {
fn wait_for_cursor_move_from(x: f64, y: f64, phase: &str) -> anyhow::Result<()> {
let deadline = Instant::now() + Duration::from_secs(3);
while Instant::now() < deadline {
- let position = current_position();
+ let position = current_position().expect("placed cursor");
if (position.0 - x).hypot(position.1 - y) > 32.0 {
eprintln!(
"{phase}: cursor moved from ({x}, {y}) to ({}, {})",
@@ -3258,7 +3255,7 @@ mod tests {
}
std::thread::sleep(Duration::from_millis(10));
}
- let position = current_position();
+ let position = current_position().expect("placed cursor");
anyhow::bail!(
"cursor position remained ({}, {}) near ({x}, {y}) during {phase}",
position.0,
@@ -3858,6 +3855,7 @@ mod tests {
rs.core.cfg.enabled = true;
rs.core.visible = true;
rs.core.pos = (10.0, 10.0);
+ rs.core.placed = true;
}
ARRIVAL_DEGRADED.store(false, std::sync::atomic::Ordering::Relaxed);
let started = tokio::time::Instant::now();
@@ -3948,6 +3946,7 @@ mod tests {
let mut map = default_render_map();
let cursor = map.cursors.get_mut("default").unwrap();
cursor.core.pos = (10.0, 10.0);
+ cursor.core.placed = true;
cursor.core.motion.idle_hide_ms = 500.0;
let (_tx, rx) = std::sync::mpsc::channel();
@@ -4120,6 +4119,7 @@ mod tests {
map.platform.scr_w = 1920;
map.platform.scr_h = 2160;
map.cursors.get_mut("default").unwrap().core.pos = (100.0, 2000.0);
+ map.cursors.get_mut("default").unwrap().core.placed = true;
assert_eq!(render_x11_tiles(&map).len(), 1);
update_render_map_geometry(&mut map, 1920, 1080);
@@ -4134,11 +4134,23 @@ mod tests {
assert!(!render_map_needs_z_order_tick(&map));
}
+ #[test]
+ fn placement_controls_frames_independently_of_coordinates() {
+ let mut map = default_render_map();
+ let core = &mut map.cursors.get_mut("default").unwrap().core;
+ core.pos = (-1.0e9, -1.0e9);
+ core.placed = true;
+ assert!(map.needs_frame_tick());
+ map.cursors.get_mut("default").unwrap().core.placed = false;
+ assert!(!map.needs_frame_tick());
+ }
+
#[test]
fn disabling_settled_cursor_clears_once_then_parks() {
let mut map = default_render_map();
let cursor = map.cursors.get_mut("default").unwrap();
cursor.core.pos = (100.0, 100.0);
+ cursor.core.placed = true;
cursor.core.motion.idle_hide_ms = 0.0;
cursor.core.visual.reduced_motion = cursor_overlay::ReducedMotion::On;
let (_tx, rx) = std::sync::mpsc::channel();
@@ -4174,6 +4186,7 @@ mod tests {
// The public animate path seeds a newly created cursor near its target
// before sending MoveTo; mirror that valid on-screen starting state.
cursor.core.pos = (100.0, 100.0);
+ cursor.core.placed = true;
// Longer than the move plus its 1.6 s navigate cue, so the opaque
// delay is still running once every animation has finished.
cursor.core.motion.idle_hide_ms = 2500.0;
@@ -4212,6 +4225,7 @@ mod tests {
{
let cursor = map.cursors.get_mut("default").unwrap();
cursor.core.pos = (10.0, 10.0);
+ cursor.core.placed = true;
cursor.core.motion.idle_hide_ms = 500.0;
}
let other = map.state_for_key("other");
@@ -4252,10 +4266,12 @@ mod tests {
{
let cursor = map.cursors.get_mut("default").unwrap();
cursor.core.pos = (10.0, 10.0);
+ cursor.core.placed = true;
cursor.core.motion.idle_hide_ms = 500.0;
}
let mut other = map.state_for_key("other");
other.core.pos = (20.0, 20.0);
+ other.core.placed = true;
map.cursors.insert("other".to_owned(), other);
// Model a command arriving after recv_timeout returned Timeout but
@@ -4288,6 +4304,7 @@ mod tests {
let mut map = default_render_map();
let cursor = map.cursors.get_mut("default").unwrap();
cursor.core.pos = (20.0, 20.0);
+ cursor.core.placed = true;
let (tx, rx) = std::sync::mpsc::channel();
tx.send(OverlayMsg::Cmd(KeyedOverlayCommand {
@@ -4314,6 +4331,7 @@ mod tests {
{
let cursor = map.cursors.get_mut("default").unwrap();
cursor.core.pos = (20.0, 20.0);
+ cursor.core.placed = true;
cursor.apply_command(OverlayCommand::MoveTo {
x: 80.0,
y: 80.0,
@@ -4354,6 +4372,7 @@ mod tests {
{
let cursor = map.cursors.get_mut("default").unwrap();
cursor.core.pos = (100.0, 100.0);
+ cursor.core.placed = true;
cursor.core.motion.idle_hide_ms = 500.0;
cursor.core.visual.reduced_motion = cursor_overlay::ReducedMotion::On;
@@ -4400,6 +4419,7 @@ mod tests {
map.platform.scr_h = 2160;
let cursor = map.cursors.get_mut("default").unwrap();
cursor.core.pos = (4000.0, 1000.0);
+ cursor.core.placed = true;
let tiles = render_x11_tiles(&map);
@@ -4418,6 +4438,7 @@ mod tests {
map.platform.scr_h = 2160;
let cursor = map.cursors.get_mut("default").unwrap();
cursor.core.pos = (4000.0, 1000.0);
+ cursor.core.placed = true;
cursor.core.badge_mode_override = Some(cursor_overlay::BadgeMode::Verbose);
cursor.apply_command(OverlayCommand::SetSessionLabel("research-run".to_owned()));
@@ -4438,6 +4459,7 @@ mod tests {
map.platform.scr_h = 2160;
let cursor = map.cursors.get_mut("default").unwrap();
cursor.core.pos = (4000.0, 1000.0);
+ cursor.core.placed = true;
cursor.core.badge_mode_override = Some(cursor_overlay::BadgeMode::Verbose);
cursor.apply_command(OverlayCommand::BeginAction {
action: CursorAction::Click,
@@ -4459,6 +4481,7 @@ mod tests {
map.platform.scr_h = 2160;
let cursor = map.cursors.get_mut("default").unwrap();
cursor.core.pos = (4000.0, 1000.0);
+ cursor.core.placed = true;
cursor.core.badge_mode_override = Some(cursor_overlay::BadgeMode::Minimal);
cursor.apply_command(OverlayCommand::SetSessionLabel("research-run".to_owned()));
cursor.apply_command(OverlayCommand::BeginAction {
@@ -4480,6 +4503,7 @@ mod tests {
map.platform.scr_h = 1080;
let cursor = map.cursors.get_mut("default").unwrap();
cursor.core.pos = (10.0, 12.0);
+ cursor.core.placed = true;
let tiles = render_x11_tiles(&map);
assert_eq!(tiles.len(), 1);
@@ -4504,6 +4528,7 @@ mod tests {
map.platform.scr_h = 1080;
let cursor = map.cursors.get_mut("default").unwrap();
cursor.core.pos = (1000.0, 500.0);
+ cursor.core.placed = true;
// A comet trail stretching back up-left of the cursor.
let trail = cursor_tile_bounds_with_effects(
@@ -4578,8 +4603,10 @@ mod tests {
map.platform.scr_w = 7680;
map.platform.scr_h = 2160;
map.cursors.get_mut("default").unwrap().core.pos = (100.0, 100.0);
+ map.cursors.get_mut("default").unwrap().core.placed = true;
let mut other = map.state_for_key("other");
other.core.pos = (7400.0, 1800.0);
+ other.core.placed = true;
map.cursors.insert("other".to_owned(), other);
let tiles = render_x11_tiles(&map);
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_.rs
index ea13b893eb..cfd397439c 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
@@ -5662,7 +5662,7 @@ async fn overlay_glide_to_target_for(cursor_id: &str, sx: f64, sy: f64, target:
return;
}
let pos = crate::overlay::current_position_for(cursor_id);
- if pos.0 < 0.0 && pos.1 < 0.0 {
+ if pos.is_none() {
crate::overlay::send_command_for(
cursor_id.to_owned(),
cursor_overlay::OverlayCommand::ClickPulse { x: sx, y: sy },
diff --git a/libs/cua-driver/rust/crates/platform-linux/src/wayland/overlay.rs b/libs/cua-driver/rust/crates/platform-linux/src/wayland/overlay.rs
index 1fe4cdf77b..d720fa8807 100644
--- a/libs/cua-driver/rust/crates/platform-linux/src/wayland/overlay.rs
+++ b/libs/cua-driver/rust/crates/platform-linux/src/wayland/overlay.rs
@@ -373,7 +373,7 @@ fn apply_keyed_command(
_ => None,
};
if let Some((target_x, target_y)) = seed_target {
- render.seed_start_if_sentinel(&key, target_x, target_y, frame);
+ render.seed_start_if_unplaced(&key, target_x, target_y, frame);
}
let disabling = matches!(&cmd, OverlayCommand::SetEnabled(false));
@@ -872,7 +872,7 @@ fn tick_all_cores(cores: &mut CursorMap<RenderStateCore>, dt: f64) -> Vec<Cursor
/// gated on a shown, placed cursor: a hidden cursor's motion is quiesced by
/// [`quiesce_hidden`] and never repaints a layer surface.
fn needs_frame_tick(core: &RenderStateCore) -> bool {
- core.visible && cursor_overlay::render_state::is_placed(core.pos) && core.needs_frame_tick()
+ core.visible && core.placed && core.needs_frame_tick()
}
fn quiesce_hidden(core: &mut RenderStateCore) {
@@ -1400,6 +1400,7 @@ mod tests {
fn positioned_core() -> RenderStateCore {
let mut core = RenderStateCore::new(CursorConfig::default());
core.pos = (100.0, 100.0);
+ core.placed = true;
core.motion.idle_hide_ms = 1_000.0;
core
}
@@ -1519,6 +1520,7 @@ mod tests {
];
let mut core = positioned_core();
core.pos = (400.0, 300.0);
+ core.placed = true;
let cores = CursorMap::from([("session".to_owned(), core)]);
assert_eq!(select_output(&layouts, 400.0, 300.0).unwrap().id, 4);
@@ -1548,6 +1550,7 @@ mod tests {
];
let mut core = positioned_core();
core.pos = (-2220.0, 980.0);
+ core.placed = true;
let cores = CursorMap::from([("session".to_owned(), core)]);
assert_eq!(visible_cores_for_output(&cores, &layouts, 3).len(), 1);
assert!(visible_cores_for_output(&cores, &layouts, 4).is_empty());
@@ -1726,6 +1729,11 @@ mod tests {
fn stable_visible_overlay_keeps_frame_cadence_for_resting_motion() {
let mut core = positioned_core();
core.idle_secs = 0.25;
+ core.pos = (-1.0e9, -1.0e9);
+ assert!(needs_frame_tick(&core));
+ core.placed = false;
+ assert!(!needs_frame_tick(&core));
+ core.placed = true;
assert!(core.has_resting_motion());
let mut cores = CursorMap::from([("cursor-a".to_owned(), core)]);
assert_eq!(next_wait(&cores, false, false), WlWait::Frame);
@@ -1916,7 +1924,7 @@ mod tests {
));
let core = state.render.cursors.get("session-a").unwrap();
assert_eq!(core.session_label.as_deref(), Some("Synthetic session"));
- assert!(!cursor_overlay::render_state::is_placed(core.pos));
+ assert!(!core.placed);
assert!(state.outputs.is_empty());
assert!(matches!(
rx.try_recv(),
@@ -2046,7 +2054,11 @@ mod tests {
&layouts,
&HashSet::new(),
&initialized(&layouts),
- render.cursors.values().map(|core| core.pos),
+ render
+ .cursors
+ .values()
+ .filter(|core| core.placed)
+ .map(|core| core.pos),
);
assert_eq!(painted, HashSet::from([1, 2]));
assert_eq!(targets, vec![FrameTarget { id: 1 }, FrameTarget { id: 2 }]);
@@ -2066,7 +2078,11 @@ mod tests {
&layouts,
&painted,
&initialized(&layouts),
- render.cursors.values().map(|core| core.pos),
+ render
+ .cursors
+ .values()
+ .filter(|core| core.placed)
+ .map(|core| core.pos),
);
assert_eq!(selected, HashSet::from([2]));
assert_eq!(targets, vec![FrameTarget { id: 1 }, FrameTarget { id: 2 }]);
diff --git a/libs/cua-driver/rust/crates/platform-macos/src/cursor/overlay.rs b/libs/cua-driver/rust/crates/platform-macos/src/cursor/overlay.rs
index b3fb832086..a2482aaa74 100644
--- a/libs/cua-driver/rust/crates/platform-macos/src/cursor/overlay.rs
+++ b/libs/cua-driver/rust/crates/platform-macos/src/cursor/overlay.rs
@@ -150,6 +150,7 @@ fn cursor_may_paint(state: &RenderState) -> bool {
state.focus_rect.is_some()
|| (state.core.cfg.enabled
&& state.core.visible
+ && state.core.placed
&& state.core.idle_alpha > 0.0
&& on_main_screen(state.core.pos))
}
@@ -370,11 +371,11 @@ pub fn current_theme_state(
/// the sentinel and only `ClickPulse` snapped a static arrow, which is easy to
/// miss. See the AX-no-glide report.
///
-/// No-op when the cursor is already placed (`is_placed`) or absent. The
+/// No-op when the cursor is already placed or absent. The
/// seed is clamped to the main screen frame so it never starts off-display.
/// Returns true if a seed was applied (i.e. the cursor was at the sentinel and
/// is now primed to glide).
-fn seed_start_if_sentinel(key: &CursorKey, target_x: f64, target_y: f64) -> bool {
+fn seed_start_if_unplaced(key: &CursorKey, target_x: f64, target_y: f64) -> bool {
let mut guard = RENDER.lock().unwrap();
let Some(map) = guard.as_mut() else {
return false;
@@ -383,7 +384,7 @@ fn seed_start_if_sentinel(key: &CursorKey, target_x: f64, target_y: f64) -> bool
// keeps the start point off negative coordinates.
let MacScreen { win_w, win_h, .. } = map.platform;
let frame = (win_w > 0.0 && win_h > 0.0).then(|| ScreenFrame::new(0.0, 0.0, win_w, win_h));
- map.seed_start_if_sentinel(key, target_x, target_y, frame)
+ map.seed_start_if_unplaced(key, target_x, target_y, frame)
}
/// Animate the overlay cursor to `(x, y)` and suspend until the Dubins path
@@ -392,7 +393,7 @@ fn seed_start_if_sentinel(key: &CursorKey, target_x: f64, target_y: f64) -> bool
/// Mirrors Swift's `AgentCursor.shared.animateAndWait(to:)`.
/// Returns immediately (no animation) only when the overlay is disabled for
/// this cursor. A brand-new cursor still at the off-screen sentinel is first
-/// seeded on-screen via [`seed_start_if_sentinel`] so its FIRST action glides
+/// seeded on-screen via [`seed_start_if_unplaced`] so its FIRST action glides
/// in (it previously snapped silently via `ClickPulse`, invisible on a pure-AX
/// run).
pub async fn animate_cursor_to(key: CursorKey, x: f64, y: f64) {
@@ -409,9 +410,9 @@ pub async fn animate_cursor_to_target(key: CursorKey, x: f64, y: f64, target: Op
return;
}
// Seed a sentinel cursor on-screen so the MoveTo below glides instead of
- // being short-circuited. After this the cursor is placed (`is_placed`), so the
+ // being short-circuited. After this the cursor is placed, so the
// should-animate check passes on the first action just like later ones.
- seed_start_if_sentinel(&key, x, y);
+ seed_start_if_unplaced(&key, x, y);
// Check whether animation should run for THIS cursor. A disabled cursor
// never animates; an absent cursor (seed found nothing to prime) is skipped.
@@ -419,7 +420,7 @@ pub async fn animate_cursor_to_target(key: CursorKey, x: f64, y: f64, target: Op
let guard = RENDER.lock().unwrap();
matches!(
guard.as_ref().and_then(|m| m.cursors.get(&key)),
- Some(rs) if rs.core.cfg.enabled && cursor_overlay::render_state::is_placed(rs.core.pos)
+ Some(rs) if rs.core.cfg.enabled && rs.core.placed
)
};
if !should_animate {
@@ -1096,6 +1097,7 @@ fn hardware_cursor_position() -> Option<(f64, f64)> {
fn cursor_is_externally_visible(state: &RenderState) -> bool {
state.core.cfg.enabled
&& state.core.visible
+ && state.core.placed
&& on_main_screen(state.core.pos)
&& state.core.idle_alpha >= 0.004
}
@@ -1522,7 +1524,7 @@ mod tests {
fn placed<'a>(map: &'a mut RenderMap, key: &str) -> &'a mut RenderState {
let frame = Some(ScreenFrame::new(0.0, 0.0, 100.0, 100.0));
- assert!(map.seed_start_if_sentinel(key, 60.0, 60.0, frame));
+ assert!(map.seed_start_if_unplaced(key, 60.0, 60.0, frame));
map.cursors.get_mut(key).unwrap()
}
@@ -1558,6 +1560,10 @@ mod tests {
placed(&mut map, "sessA");
assert!(cursor_is_externally_visible(&map.cursors["sessA"]));
+ map.cursors.get_mut("sessA").unwrap().core.placed = false;
+ assert!(!cursor_may_paint(&map.cursors["sessA"]));
+ assert!(!cursor_is_externally_visible(&map.cursors["sessA"]));
+ map.cursors.get_mut("sessA").unwrap().core.placed = true;
map.cursors.get_mut("sessA").unwrap().core.cfg.enabled = false;
assert!(!cursor_is_externally_visible(&map.cursors["sessA"]));
diff --git a/libs/cua-driver/rust/crates/platform-windows/src/overlay.rs b/libs/cua-driver/rust/crates/platform-windows/src/overlay.rs
index 7a2378e6a0..e9c677e83c 100644
--- a/libs/cua-driver/rust/crates/platform-windows/src/overlay.rs
+++ b/libs/cua-driver/rust/crates/platform-windows/src/overlay.rs
@@ -360,19 +360,14 @@ pub fn current_theme_state(
Some((id, version, profile, fallback, state.core.visual.clone()))
}
-/// Current screen position of the cursor for `key` (the off-screen sentinel
-/// `(-200, -200)` if it has never been placed). A session with no own cursor
-/// yet reports the sentinel so the click path treats it as first-placement.
-pub fn current_position(key: &str) -> (f64, f64) {
- RENDER
- .lock()
- .ok()
- .and_then(|g| {
- g.as_ref()
- .and_then(|m| m.cursors.get(key))
- .map(|rs| rs.core.pos)
- })
- .unwrap_or(cursor_overlay::render_state::UNPLACED_POS)
+/// Current screen position, or `None` for an absent or unplaced cursor.
+pub fn current_position(key: &str) -> Option<(f64, f64)> {
+ RENDER.lock().ok().and_then(|g| {
+ g.as_ref()
+ .and_then(|m| m.cursors.get(key))
+ .filter(|rs| rs.core.placed)
+ .map(|rs| rs.core.pos)
+ })
}
/// Seed a brand-new (sentinel-positioned) cursor at an on-screen start point
@@ -380,13 +375,13 @@ pub fn current_position(key: &str) -> (f64, f64) {
/// `MoveTo` glides INTO the target instead of silently snapping. No-op when the
/// cursor is already on-screen or its session already ended. Returns true if a
/// seed was applied. Mirrors `platform_macos::cursor::overlay::seed_start_*`.
-fn seed_start_if_sentinel(key: &CursorKey, target_x: f64, target_y: f64) -> bool {
+fn seed_start_if_unplaced(key: &CursorKey, target_x: f64, target_y: f64) -> bool {
let mut guard = RENDER.lock().unwrap();
let Some(map) = guard.as_mut() else {
return false;
};
let frame = map.platform.frame();
- map.seed_start_if_sentinel(key, target_x, target_y, frame)
+ map.seed_start_if_unplaced(key, target_x, target_y, frame)
}
/// Animate the overlay cursor for `key` to `(x, y)` and suspend until the
@@ -398,7 +393,7 @@ fn seed_start_if_sentinel(key: &CursorKey, target_x: f64, target_y: f64) -> bool
/// - the cursor for `key` is disabled.
///
/// A brand-new cursor still at the off-screen sentinel is first seeded
-/// on-screen via [`seed_start_if_sentinel`] so its FIRST action glides in.
+/// on-screen via [`seed_start_if_unplaced`] so its FIRST action glides in.
/// Mirrors `platform_macos::cursor::overlay::animate_cursor_to`.
pub async fn animate_cursor_to(key: CursorKey, x: f64, y: f64) {
animate_cursor_to_target(key, x, y, None).await;
@@ -413,13 +408,13 @@ pub async fn animate_cursor_to_target(key: CursorKey, x: f64, y: f64, target: Op
}
// Seed a sentinel cursor on-screen so the MoveTo below glides instead of
// being short-circuited.
- seed_start_if_sentinel(&key, x, y);
+ seed_start_if_unplaced(&key, x, y);
let should_animate = {
let guard = RENDER.lock().unwrap();
matches!(
guard.as_ref().and_then(|m| m.cursors.get(&key)),
- Some(rs) if rs.core.cfg.enabled && cursor_overlay::render_state::is_placed(rs.core.pos)
+ Some(rs) if rs.core.cfg.enabled && rs.core.placed
)
};
if !should_animate {
@@ -529,7 +524,7 @@ impl RenderState {
&& self.core.click_age.is_none()
&& self.core.motion.idle_hide_ms > 0.0
&& self.core.visible
- && cursor_overlay::render_state::is_placed(self.core.pos)
+ && self.core.placed
&& self.core.idle_alpha >= 1.0
}
}
@@ -1718,6 +1713,7 @@ mod tests {
map.platform.virt_h = 1080;
let core = &mut map.cursors.get_mut("default").unwrap().core;
core.pos = (-1000.0, 500.0);
+ core.placed = true;
let (vx, vy, w, h) = (-1920, 0, 3840, 1080);
let cursor_only = cursor_dirty_rect(core, vx, vy, w, h).unwrap();
@@ -1769,7 +1765,7 @@ mod tests {
map.platform.virt_w = 3840;
map.platform.virt_h = 1080;
let frame = map.platform.frame();
- assert!(map.seed_start_if_sentinel("sessA", -1800.0, 500.0, frame));
+ assert!(map.seed_start_if_unplaced("sessA", -1800.0, 500.0, frame));
assert_eq!(map.cursors["sessA"].core.pos, (-1918.0, 360.0));
map.platform.virt_w = 0;
@@ -1795,7 +1791,7 @@ mod tests {
#[test]
fn resting_cursor_keeps_the_active_cadence_for_its_bob() {
let mut map = empty_map();
- map.seed_start_if_sentinel("sessA", 60.0, 60.0, map.platform.frame());
+ map.seed_start_if_unplaced("sessA", 60.0, 60.0, map.platform.frame());
apply_msg(&mut map, move_msg("sessA", 10.0, 10.0));
settle(&mut map);
let rs = &map.cursors["sessA"];
@@ -1808,7 +1804,7 @@ mod tests {
#[test]
fn reduced_motion_countdown_parks_at_idle_cadence_but_fade_ticks() {
let mut map = empty_map();
- map.seed_start_if_sentinel("sessA", 60.0, 60.0, map.platform.frame());
+ map.seed_start_if_unplaced("sessA", 60.0, 60.0, map.platform.frame());
map.cursors
.get_mut("sessA")
.unwrap()
@@ -1831,6 +1827,12 @@ mod tests {
assert_eq!(rs.core.idle_alpha, 1.0);
assert!(!map.needs_frame_tick());
assert!(rs.in_idle_countdown());
+ let rs = map.cursors.get_mut("sessA").unwrap();
+ rs.core.pos = (-200.0, -200.0);
+ assert!(rs.in_idle_countdown());
+ rs.core.placed = false;
+ assert!(!rs.in_idle_countdown());
+ rs.core.placed = true;
// The fade animates pixels, so frame ticks return until alpha ~0.
let rs = map.cursors.get_mut("sessA").unwrap();
diff --git a/libs/cua-driver/rust/crates/platform-windows/src/tools/impl_.rs b/libs/cua-driver/rust/crates/platform-windows/src/tools/impl_.rs
index 65b6b507c8..14e08e7329 100644
--- a/libs/cua-driver/rust/crates/platform-windows/src/tools/impl_.rs
+++ b/libs/cua-driver/rust/crates/platform-windows/src/tools/impl_.rs
@@ -311,7 +311,7 @@ async fn overlay_glide_to_target(key: &str, sx: f64, sy: f64, target: Option<[f6
return;
}
let pos = crate::overlay::current_position(key);
- if pos.0 < 0.0 && pos.1 < 0.0 {
+ if pos.is_none() {
// Snap to target on first use; no animation to wait for.
crate::overlay::send_command(
key.to_owned(),
diff --git a/libs/cua-spacesd/crates/cua-spacesd-desktop/src/lib.rs b/libs/cua-spacesd/crates/cua-spacesd-desktop/src/lib.rs
index e2b8cd2fd0..85ab80741b 100644
--- a/libs/cua-spacesd/crates/cua-spacesd-desktop/src/lib.rs
+++ b/libs/cua-spacesd/crates/cua-spacesd-desktop/src/lib.rs
@@ -1432,7 +1432,7 @@ impl CuaPresenceOverlay {
#[cfg(target_os = "windows")]
{
if platform_windows::overlay::is_enabled(user_key) {
- return Some(platform_windows::overlay::current_position(user_key));
+ return platform_windows::overlay::current_position(user_key);
}
None
}