diff --git a/crates/cursor-capture/src/position.rs b/crates/cursor-capture/src/position.rs index fe537d46eb0..d26d10c09d8 100644 --- a/crates/cursor-capture/src/position.rs +++ b/crates/cursor-capture/src/position.rs @@ -10,13 +10,11 @@ pub struct RawCursorPosition { impl RawCursorPosition { pub fn get() -> Self { - let device_state = DeviceState::new(); - let position = device_state.get_mouse().coords; + Self::from_coords(DeviceState::new().get_mouse().coords) + } - Self { - x: position.0, - y: position.1, - } + pub fn from_coords((x, y): (i32, i32)) -> Self { + Self { x, y } } pub fn relative_to_display(&self, display: Display) -> Option { diff --git a/crates/recording/src/cursor.rs b/crates/recording/src/cursor.rs index e108fe1111f..02b2b7c6e2d 100644 --- a/crates/recording/src/cursor.rs +++ b/crates/recording/src/cursor.rs @@ -509,7 +509,8 @@ pub fn spawn_cursor_recorder( let mut last_mouse_state = device_state.get_mouse(); let mut last_keys: Vec = device_state.get_keys(); - let mut last_position = cap_cursor_capture::RawCursorPosition::get(); + let mut last_position = + cap_cursor_capture::RawCursorPosition::from_coords(last_mouse_state.coords); std::fs::create_dir_all(&cursors_dir).unwrap(); @@ -544,15 +545,16 @@ pub fn spawn_cursor_recorder( } let Some(epoch) = input_epoch(start_gate.as_ref(), start_time) else { - last_position = cap_cursor_capture::RawCursorPosition::get(); last_mouse_state = device_state.get_mouse(); + last_position = + cap_cursor_capture::RawCursorPosition::from_coords(last_mouse_state.coords); last_keys = device_state.get_keys(); continue; }; let elapsed = epoch.elapsed().as_secs_f64() * 1000.0; let mouse_state = device_state.get_mouse(); - let position = cap_cursor_capture::RawCursorPosition::get(); + let position = cap_cursor_capture::RawCursorPosition::from_coords(mouse_state.coords); // The first sample after the gate opens is always recorded so the // cursor has a known position at the recording's time zero. let position_changed = position != last_position || std::mem::take(&mut awaiting_start);