Skip to content

Commit 3b996af

Browse files
Merge pull request #2621 from celeroncoder/perf/cursor-reuse-mouse-sample
perf(recording): take the cursor position from the recorder's mouse sample
2 parents 6cf8477 + f829b8c commit 3b996af

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

‎crates/cursor-capture/src/position.rs‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ pub struct RawCursorPosition {
1010

1111
impl RawCursorPosition {
1212
pub fn get() -> Self {
13-
let device_state = DeviceState::new();
14-
let position = device_state.get_mouse().coords;
13+
Self::from_coords(DeviceState::new().get_mouse().coords)
14+
}
1515

16-
Self {
17-
x: position.0,
18-
y: position.1,
19-
}
16+
pub fn from_coords((x, y): (i32, i32)) -> Self {
17+
Self { x, y }
2018
}
2119

2220
pub fn relative_to_display(&self, display: Display) -> Option<RelativeCursorPosition> {

‎crates/recording/src/cursor.rs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,8 @@ pub fn spawn_cursor_recorder(
509509
let mut last_mouse_state = device_state.get_mouse();
510510
let mut last_keys: Vec<device_query::Keycode> = device_state.get_keys();
511511

512-
let mut last_position = cap_cursor_capture::RawCursorPosition::get();
512+
let mut last_position =
513+
cap_cursor_capture::RawCursorPosition::from_coords(last_mouse_state.coords);
513514

514515
std::fs::create_dir_all(&cursors_dir).unwrap();
515516

@@ -544,15 +545,16 @@ pub fn spawn_cursor_recorder(
544545
}
545546

546547
let Some(epoch) = input_epoch(start_gate.as_ref(), start_time) else {
547-
last_position = cap_cursor_capture::RawCursorPosition::get();
548548
last_mouse_state = device_state.get_mouse();
549+
last_position =
550+
cap_cursor_capture::RawCursorPosition::from_coords(last_mouse_state.coords);
549551
last_keys = device_state.get_keys();
550552
continue;
551553
};
552554
let elapsed = epoch.elapsed().as_secs_f64() * 1000.0;
553555
let mouse_state = device_state.get_mouse();
554556

555-
let position = cap_cursor_capture::RawCursorPosition::get();
557+
let position = cap_cursor_capture::RawCursorPosition::from_coords(mouse_state.coords);
556558
// The first sample after the gate opens is always recorded so the
557559
// cursor has a known position at the recording's time zero.
558560
let position_changed = position != last_position || std::mem::take(&mut awaiting_start);

0 commit comments

Comments
 (0)