From c0351e317860d96cf30e173ecba32f10f588c669 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Fri, 25 Sep 2026 10:11:52 +0800 Subject: [PATCH] cursor: capture the macOS cursor shown without checking the seed around it Every macOS seed change is now captured, pixel by pixel, and a seed that moved during that capture failed it; the service then logged an error and slept a second, so the controller's cursor lagged while it changed. The check guarded nothing: the shape is named by its content, not the seed, and a change after get_cursor read the seed moves it on, so the next poll captures it anyway. Resetting the seed on a failed check was not needed for the same reason. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EZ49AbZJYfm8NTp5yDPMab --- src/platform/macos.rs | 13 ++----------- src/platform/mod.rs | 11 ++++------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 62832dac3..4386e07ee 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -586,13 +586,8 @@ pub fn get_cursor_data(hcursor: u64) -> ResultType { // https://github.com/stweil/OSXvnc/blob/master/OSXvnc-server/mousecursor.c fn unsafe_get_cursor_data(hcursor: u64) -> ResultType { unsafe { - // Captured only while the cursor is the change `hcursor` names. One that changed again is - // left for get_cursor to report again, or the change would be lost. - let changed = || CGSCurrentCursorSeed() as u32 as u64 != hcursor; - if changed() { - LATEST_SEED = 0; - bail!("cursor changed"); - } + // The cursor shown is captured even if it changed after get_cursor read the seed: the + // content names the shape, and that change moved the seed on, so the next poll captures it. let c: id = msg_send![class!(NSCursor), currentSystemCursor]; if c == nil { bail!("Failed to call [NSCursor currentSystemCursor]"); @@ -636,10 +631,6 @@ fn unsafe_get_cursor_data(hcursor: u64) -> ResultType { colors.push((a * 255.) as _); } } - if changed() { - LATEST_SEED = 0; - bail!("cursor changed"); - } Ok(CursorData { id: hcursor, colors: colors.into(), diff --git a/src/platform/mod.rs b/src/platform/mod.rs index a92dc3677..2e6061664 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -228,16 +228,13 @@ mod tests { #[cfg(target_os = "macos")] macos::is_process_trusted(false); } - // macOS reports a change of cursor, and a capture that finds the cursor changed again - // leaves the change to be reported once more, not lost. + // A macOS capture takes the cursor shown, whatever seed it is asked for. #[cfg(target_os = "macos")] { macos::reset_input_cache(); - let change = get_cursor().unwrap().expect("a change after a reset"); - assert_eq!(get_cursor().unwrap(), None, "nothing changed since"); - assert!(get_cursor_data(change).is_ok()); - assert!(get_cursor_data(change.wrapping_add(1)).is_err()); - assert!(get_cursor().unwrap().is_some(), "the change is reported again"); + if let Some(change) = get_cursor().unwrap() { + assert!(get_cursor_data(change.wrapping_add(1)).is_ok()); + } } } #[test]