From 8d74ff0e57765f4fab7a4a4ada32f4c38811c5c2 Mon Sep 17 00:00:00 2001 From: Minh Nguyen Date: Fri, 6 Nov 2026 16:11:02 +0700 Subject: [PATCH] fix(windows): write the clipboard owner marker first (#16695) The Windows clipboard setter empties the clipboard and writes each format in order, stopping at the first one that fails. With the marker written last, a failure after an earlier format succeeded could leave unmarked content on the clipboard. RustDesk could then read it back as a fresh local copy and return it, causing the controller to empty its clipboard again. For applications such as Excel, that destroys the application's copy state. Write the marker first on Windows so a partial write stays identifiable as RustDesk-owned. Other platforms keep appending it, so their payload order is unchanged. This covers a format failure before the marker is written, not a marker that is written but later missing or unreadable. Refs #16291 --- src/clipboard.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/clipboard.rs b/src/clipboard.rs index 9a1bd6058..78136a852 100644 --- a/src/clipboard.rs +++ b/src/clipboard.rs @@ -281,10 +281,16 @@ fn do_update_clipboard_(mut to_update_data: Vec, side: ClipboardS #[cfg(not(target_os = "android"))] fn append_owner_marker(mut data: Vec, side: ClipboardSide) -> Vec { - data.push(ClipboardData::Special(( + let marker = ClipboardData::Special(( RUSTDESK_CLIPBOARD_OWNER_FORMAT.to_owned(), side.get_owner_data(), - ))); + )); + // The Windows setter stops at the first format it fails to write, so a marker placed + // last can be skipped, leaving content RustDesk no longer recognizes as its own. + #[cfg(target_os = "windows")] + data.insert(0, marker); + #[cfg(not(target_os = "windows"))] + data.push(marker); data }