From 26811018e065715097dacd1a7de3f5aec653e5a1 Mon Sep 17 00:00:00 2001 From: VallierDev <24893073+VallierDev@users.noreply.github.com> Date: Mon, 2 Nov 2026 18:23:23 +0800 Subject: [PATCH] fix(clipboard): name the Unicode text offer predefined_13 for Windows viewers A CF_UNICODETEXT name made the Windows viewer register a custom clipboard format instead of using id 13, so Linux text never reached the standard Unicode format. Fixes #151. Co-Authored-By: Claude Opus 5.5 --- src/clipboard_rich.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/clipboard_rich.rs b/src/clipboard_rich.rs index 48b2527..51ef94a 100644 --- a/src/clipboard_rich.rs +++ b/src/clipboard_rich.rs @@ -17,6 +17,9 @@ impl TextFormat { } fn id(self)->u64{match self{Self::Windows=>UNICODE_TEXT,Self::Mac=>0}} fn name(self)->&'static str{match self{Self::Windows=>"CF_UNICODETEXT",Self::Mac=>MAC_TEXT}} + /// Name in a format-list offer. Official Windows peers name predefined formats `predefined_`; a plain + /// `CF_UNICODETEXT` makes the Windows viewer register a custom format instead of id 13 (issue #151). + fn offer_name(self)->&'static str{match self{Self::Windows=>WINDOWS_OFFER_NAME,Self::Mac=>MAC_TEXT}} fn encode(self,text:&str)->Vec{match self{Self::Windows=>encode_windows(text),Self::Mac=>text.as_bytes().to_vec()}} fn decode(self,data:&[u8])->Result{ match self{ @@ -31,6 +34,7 @@ impl TextFormat { } } } +const WINDOWS_OFFER_NAME:&str="predefined_13"; const BLOCK_BYTES:usize=0x20000; const MAX_BYTES:usize=MAX_TEXT*2+2; pub struct ResultMessages {pub messages:Vec<(u32,Vec)>,pub text:Option} @@ -96,7 +100,7 @@ impl State{ if text.contains('\0')||encode_windows(&text).len()>MAX_BYTES{return Err("clipboard encoded text exceeds limit");} self.local=Some(text); let mut list=Vec::new(); - for kind in formats {let mut format=Vec::new();int(1,kind.id(),&mut format);string(2,kind.name(),&mut format);nested(1,&format,&mut list);} + for kind in formats {let mut format=Vec::new();int(1,kind.id(),&mut format);string(2,kind.offer_name(),&mut format);nested(1,&format,&mut list);} Ok(request(id,1,&list)) } pub fn request(&mut self,rpc:&[u8],next:&mut impl FnMut()->u64)->Result{ @@ -210,7 +214,11 @@ mod tests{ let data=bytes(bytes(bytes(&out.messages[1].1,9).unwrap().unwrap(),3).unwrap().unwrap(),3).unwrap().unwrap(); assert_eq!(data,b"hi"); // Host-side offers are unchanged: CF_UNICODETEXT only. - assert_eq!(format_ids(&State::default().offer(1,"hi".into()).unwrap()),vec![13]); + let host_offer=State::default().offer(1,"hi".into()).unwrap(); + assert_eq!(format_ids(&host_offer),vec![13]); + let list=bytes(bytes(&host_offer,9).unwrap().unwrap(),1).unwrap().unwrap(); + let format=bytes(list,1).unwrap().unwrap(); + assert_eq!(text_field(format,2),Ok(WINDOWS_OFFER_NAME)); } #[test] fn desktop_clipboard_negotiates_and_buffers_unicode_until_confirmation(){