mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 08:50:40 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7e52a098b | ||
|
|
94ff1f1c02 | ||
|
|
aafc17e626 |
No files matched your search
Generated
+1
-1
@@ -2741,7 +2741,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "uu-remote-linux"
|
||||
version = "0.2.4"
|
||||
version = "0.2.5"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64 0.22.1",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "uu-remote-linux"
|
||||
version = "0.2.4"
|
||||
version = "0.2.5"
|
||||
edition = "2021"
|
||||
default-run = "uuremote-server"
|
||||
authors = ["uu-remote-linux contributors"]
|
||||
|
||||
@@ -475,6 +475,8 @@ static void build_window(void) {
|
||||
static void *ui_main(void *arg) {
|
||||
(void)arg;
|
||||
int ok = gtk_init_check(NULL, NULL);
|
||||
// The CSS hard-codes a light palette; a dark system theme would turn unstyled text white on white (#43).
|
||||
if (ok) g_object_set(gtk_settings_get_default(), "gtk-theme-name", "Adwaita", "gtk-application-prefer-dark-theme", FALSE, NULL);
|
||||
if (ok) build_window();
|
||||
pthread_mutex_lock(&init_lock);
|
||||
init_state = ok ? 1 : -1;
|
||||
|
||||
@@ -474,6 +474,8 @@ static gboolean show_window(gpointer d) {
|
||||
static void *ui_thread(void *d) {
|
||||
(void)d;
|
||||
if (!gtk_init_check(NULL, NULL)) { pthread_mutex_lock(&init_lock); init_state = -1; pthread_cond_signal(&init_cond); pthread_mutex_unlock(&init_lock); return NULL; }
|
||||
// Light palette in CSS; keep a dark system theme from making unstyled text white on white (#43).
|
||||
g_object_set(gtk_settings_get_default(), "gtk-theme-name", "Adwaita", "gtk-application-prefer-dark-theme", FALSE, NULL);
|
||||
show_window(NULL); gtk_main(); return NULL;
|
||||
}
|
||||
/* Hidden windows retain their widgets so queued idle callbacks stay valid. */
|
||||
|
||||
@@ -590,6 +590,8 @@ static gboolean on_delete(GtkWidget *w, GdkEvent *e, gpointer d) { (void)w; (voi
|
||||
static void *run(void *arg) {
|
||||
(void)arg;
|
||||
int ok = gtk_init_check(NULL, NULL);
|
||||
// The CSS hard-codes a light palette; a dark system theme would turn unstyled text white on white (#43).
|
||||
if (ok) g_object_set(gtk_settings_get_default(), "gtk-theme-name", "Adwaita", "gtk-application-prefer-dark-theme", FALSE, NULL);
|
||||
if (ok) {
|
||||
GtkCssProvider *css = gtk_css_provider_new();
|
||||
gtk_css_provider_load_from_data(css, CSS, -1, NULL);
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
窗口颜色修复;控制端可接收官方 Mac 被控端的剪贴板。/ Window colors fixed; viewer receives the official Mac host's clipboard.
|
||||
|
||||
### 修复 / Fixed
|
||||
- **深色系统主题下窗口文字看不见**(#43):协助窗口、控制端启动窗口和工具窗口使用固定浅色背景,但部分文字跟随系统深色主题变成了白色。
|
||||
现在这些窗口固定使用浅色主题。已在虚拟机中设置深色偏好后截图确认。
|
||||
GTK windows now stay on the light theme, so text is readable under dark system themes.
|
||||
- **控制端 ↔ 官方 Mac 被控端剪贴板**:Mac 被控端以 `public.utf8-plain-text`(UTF-8)提供文本,而不是 Windows 的 `CF_UNICODETEXT`,
|
||||
之前控制端不会请求,剪贴板始终不同步。现在两种格式都支持;主机端发给官方客户端的格式不变。
|
||||
Mac → 控制端已实机验证;⚠️ 控制端 → Mac 尚未验证。
|
||||
The viewer now handles the Mac host's UTF-8 text format (Mac → viewer verified live; viewer → Mac not yet verified).
|
||||
|
||||
### 已验证 / Verified with the official Mac host(FFmpeg 9.0.2)
|
||||
- 画面 0 解码错误,键盘输入正确,文件上传/下载/列目录 sha256 一致。
|
||||
|
||||
### 已知问题 / Known issues
|
||||
- 剪贴板只在控制端窗口获得焦点时同步;控制端 → 官方 Windows 被控端的剪贴板仍在排查。
|
||||
|
||||
### 下载 / Download
|
||||
`uu-remote-linux-v0.2.5-x86_64-linux.tar.gz`:主机 `uuremote-server`(X11 版)与控制端 `uuremote-viewer`(x86_64,glibc ≥ 2.35;控制端需 SDL2、GTK3、ffmpeg),附带 `contrib/`。
|
||||
|
||||
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
|
||||
+73
-12
@@ -5,11 +5,37 @@ use crate::protocol::{decode_wire,WireValue};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
const UNICODE_TEXT:u64=13;
|
||||
/// The official Mac host offers its pasteboard text as format id 0 named `public.utf8-plain-text` (observed live).
|
||||
const MAC_TEXT:&str="public.utf8-plain-text";
|
||||
#[derive(Clone,Copy,PartialEq,Eq,Debug)]
|
||||
enum TextFormat {Windows,Mac}
|
||||
impl TextFormat {
|
||||
fn of(format:&[u8])->Option<Self>{
|
||||
if number(format,1)==Ok(UNICODE_TEXT){return Some(Self::Windows)}
|
||||
let named=|n|text_field(format,n).is_ok_and(|s|s==MAC_TEXT);
|
||||
(named(2)||named(3)).then_some(Self::Mac)
|
||||
}
|
||||
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}}
|
||||
fn encode(self,text:&str)->Vec<u8>{match self{Self::Windows=>encode_windows(text),Self::Mac=>text.as_bytes().to_vec()}}
|
||||
fn decode(self,data:&[u8])->Result<String,&'static str>{
|
||||
match self{
|
||||
Self::Windows=>decode_windows(data),
|
||||
Self::Mac=>{
|
||||
let data=data.strip_suffix(&[0]).unwrap_or(data);
|
||||
if data.len()>MAX_TEXT{return Err("clipboard text exceeds limit");}
|
||||
let text=std::str::from_utf8(data).map_err(|_|"invalid UTF-8 clipboard text")?;
|
||||
if text.contains('\0'){return Err("embedded NUL in clipboard text");}
|
||||
Ok(text.to_owned())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const BLOCK_BYTES:usize=0x20000;
|
||||
const MAX_BYTES:usize=MAX_TEXT*2+2;
|
||||
pub struct ResultMessages {pub messages:Vec<(u32,Vec<u8>)>,pub text:Option<String>}
|
||||
impl Default for ResultMessages {fn default()->Self{Self{messages:Vec::new(),text:None}}}
|
||||
struct Pending {key:String, count:Option<usize>, blocks:BTreeMap<usize,Vec<u8>>}
|
||||
struct Pending {key:String, format:TextFormat, count:Option<usize>, blocks:BTreeMap<usize,Vec<u8>>}
|
||||
#[derive(Default)]
|
||||
pub struct State {local:Option<String>, pending:Option<Pending>}
|
||||
pub fn format_ids(rpc:&[u8])->Vec<u64>{
|
||||
@@ -62,12 +88,15 @@ fn decode_windows(data:&[u8])->Result<String,&'static str>{
|
||||
if text.len()>MAX_TEXT{return Err("clipboard text exceeds limit");}Ok(text)
|
||||
}
|
||||
impl State{
|
||||
pub fn offer(&mut self,id:u64,text:String)->Result<Vec<u8>,&'static str>{
|
||||
pub fn offer(&mut self,id:u64,text:String)->Result<Vec<u8>,&'static str>{self.offer_formats(id,text,&[TextFormat::Windows])}
|
||||
/// Viewer offers: Windows hosts pick CF_UNICODETEXT, the official Mac host its UTF-8 type.
|
||||
pub fn offer_any_host(&mut self,id:u64,text:String)->Result<Vec<u8>,&'static str>{self.offer_formats(id,text,&[TextFormat::Windows,TextFormat::Mac])}
|
||||
fn offer_formats(&mut self,id:u64,text:String,formats:&[TextFormat])->Result<Vec<u8>,&'static str>{
|
||||
if text.len()>MAX_TEXT{return Err("clipboard text exceeds limit");}
|
||||
if text.contains('\0')||encode_windows(&text).len()>MAX_BYTES{return Err("clipboard encoded text exceeds limit");}
|
||||
self.local=Some(text);
|
||||
let mut format=Vec::new();int(1,UNICODE_TEXT,&mut format);string(2,"CF_UNICODETEXT",&mut format);
|
||||
let mut list=Vec::new();nested(1,&format,&mut list);
|
||||
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);}
|
||||
Ok(request(id,1,&list))
|
||||
}
|
||||
pub fn request(&mut self,rpc:&[u8],next:&mut impl FnMut()->u64)->Result<ResultMessages,&'static str>{
|
||||
@@ -78,22 +107,30 @@ impl State{
|
||||
if let Some(list)=bytes(clip,1)?{
|
||||
out.messages.push((22,response(h,1,&[])));
|
||||
let fields=decode_wire(list).map_err(|_|"invalid clipboard format list")?;
|
||||
let supports_text=fields.iter().filter(|f|f.number==1).any(|f|match f.value{WireValue::Bytes(format)=>number(format,1)==Ok(UNICODE_TEXT),_=>false});
|
||||
let offered:Vec<TextFormat>=fields.iter().filter(|f|f.number==1).filter_map(|f|match f.value{WireValue::Bytes(format)=>TextFormat::of(format),_=>None}).collect();
|
||||
let chosen=if offered.contains(&TextFormat::Windows){Some(TextFormat::Windows)}else{offered.first().copied()};
|
||||
let supports_text=chosen.is_some();
|
||||
self.pending=None;
|
||||
if supports_text{
|
||||
if !supports_text{
|
||||
// Format ids/names only (never data), to learn non-Windows peers' text formats.
|
||||
let formats:Vec<(u64,String)>=fields.iter().filter(|f|f.number==1).filter_map(|f|match f.value{WireValue::Bytes(format)=>Some(format),_=>None})
|
||||
.take(8).map(|format|(number(format,1).unwrap_or(u64::MAX),decode_wire(format).ok().and_then(|x|x.into_iter().find_map(|y|match (y.number,y.value){(n,WireValue::Bytes(s)) if n!=1=>std::str::from_utf8(s).ok().map(|s|s.chars().take(48).collect()),_=>None})).unwrap_or_default())).collect();
|
||||
log::info!("Clipboard offer without a supported text format: formats={formats:?}");
|
||||
}
|
||||
if let Some(format)=chosen{
|
||||
let id=next();
|
||||
let epoch=std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap_or_default().as_secs() as u32;
|
||||
let key=format!("{epoch:08x}-0000-4000-8000-{:012x}",id & 0xffffffffffff);
|
||||
let mut ask=Vec::new();int(1,UNICODE_TEXT,&mut ask);string(2,&key,&mut ask);string(3,"CF_UNICODETEXT",&mut ask);
|
||||
self.pending=Some(Pending{key,count:None,blocks:BTreeMap::new()});
|
||||
let mut ask=Vec::new();int(1,format.id(),&mut ask);string(2,&key,&mut ask);string(3,format.name(),&mut ask);
|
||||
self.pending=Some(Pending{key,format,count:None,blocks:BTreeMap::new()});
|
||||
out.messages.push((21,request(id,2,&ask)));
|
||||
}
|
||||
}else if let Some(ask)=bytes(clip,2)?{
|
||||
let key=text_field(ask,2)?;
|
||||
if key.len()>256||key.is_empty(){return Err("invalid clipboard block key");}
|
||||
let available=number(ask,1)?==UNICODE_TEXT&&self.local.is_some();
|
||||
let mut confirm=Vec::new();int(1,if available{1}else{2},&mut confirm);string(2,key,&mut confirm);
|
||||
let data=if available{Some(encode_windows(self.local.as_ref().unwrap()))}else{None};
|
||||
let format=if number(ask,1)?==UNICODE_TEXT{Some(TextFormat::Windows)}else if text_field(ask,3).is_ok_and(|s|s==MAC_TEXT){Some(TextFormat::Mac)}else{None};
|
||||
let data=format.zip(self.local.as_ref()).map(|(format,text)|format.encode(text));
|
||||
let mut confirm=Vec::new();int(1,if data.is_some(){1}else{2},&mut confirm);string(2,key,&mut confirm);
|
||||
if let Some(data)=&data{int(3,data.chunks(BLOCK_BYTES).len() as u64,&mut confirm);}
|
||||
out.messages.push((22,response(h,2,&confirm)));
|
||||
if let Some(data)=data{
|
||||
@@ -144,13 +181,37 @@ impl State{
|
||||
else if (1..=count).all(|i|pending.blocks.contains_key(&i)){1}
|
||||
else{return Ok(None);};
|
||||
let data:Vec<u8>=(first..first+count).flat_map(|i|pending.blocks[&i].iter().copied()).collect();
|
||||
self.pending=None;decode_windows(&data).map(Some)
|
||||
let format=pending.format;self.pending=None;format.decode(&data).map(Some)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests{
|
||||
use super::*;
|
||||
#[test] fn mac_utf8_text_round_trips_both_directions(){
|
||||
// Mac host offer: format list {1 id 0, 2 "public.utf8-plain-text"} (observed live).
|
||||
let mut mac=Vec::new();int(1,0,&mut mac);string(2,MAC_TEXT,&mut mac);
|
||||
let mut list=Vec::new();nested(1,&mac,&mut list);
|
||||
let mut viewer=State::default();let mut id=200;let mut next=||{id+=1;id};
|
||||
let asked=viewer.request(&request(7,1,&list),&mut next).unwrap();
|
||||
assert_eq!(asked.messages.len(),2);
|
||||
let ask_rpc=&asked.messages[1].1;let clip=bytes(ask_rpc,9).unwrap().unwrap();let ask=bytes(clip,2).unwrap().unwrap();
|
||||
assert_eq!(number(ask,1),Ok(0));assert_eq!(text_field(ask,3),Ok(MAC_TEXT));
|
||||
let key=text_field(ask,2).unwrap().to_owned();
|
||||
let mut confirm=Vec::new();int(1,1,&mut confirm);string(2,&key,&mut confirm);int(3,1,&mut confirm);
|
||||
assert_eq!(viewer.response(&response(header(ask_rpc).unwrap(),2,&confirm)).unwrap(),None);
|
||||
let mut block=Vec::new();string(1,&key,&mut block);int(2,0,&mut block);nested(3,"中文 text\n".as_bytes(),&mut block);
|
||||
assert_eq!(viewer.request(&request(8,3,&block),&mut next).unwrap().text.as_deref(),Some("中文 text\n"));
|
||||
// Viewer offer lists both formats; a Mac-style ask gets UTF-8 bytes back.
|
||||
let offer=viewer.offer_any_host(9,"hi".into()).unwrap();
|
||||
assert_eq!(format_ids(&offer),vec![13,0]);
|
||||
let mut ask=Vec::new();int(1,0,&mut ask);string(2,"k",&mut ask);string(3,MAC_TEXT,&mut ask);
|
||||
let out=viewer.request(&request(10,2,&ask),&mut next).unwrap();
|
||||
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]);
|
||||
}
|
||||
#[test]
|
||||
fn desktop_clipboard_negotiates_and_buffers_unicode_until_confirmation(){
|
||||
let text="UU-test-中文🙂\n".repeat(900);
|
||||
|
||||
@@ -111,7 +111,7 @@ impl SyncState {
|
||||
/// ignores the other form.
|
||||
fn local(&mut self,value:String)->Result<Option<Vec<Vec<u8>>>,&'static str>{
|
||||
if self.last.as_ref()==Some(&value){return Ok(None)}
|
||||
let id=self.next();let payload=self.rich.offer(id,value.clone())?;
|
||||
let id=self.next();let payload=self.rich.offer_any_host(id,value.clone())?;
|
||||
let rich=wire::envelope(self.next(),21,&payload);
|
||||
let text=wire::envelope(self.next(),21,&crate::clipboard_protocol::text_request(self.next(),&value));
|
||||
self.last=Some(value);Ok(Some(vec![rich,text]))
|
||||
|
||||
+2
-1
@@ -195,7 +195,8 @@ impl Peer {
|
||||
if state.chroma.swap(chroma,Ordering::AcqRel)!=chroma {log::info!("Viewer capture sync: chroma={chroma}");}
|
||||
}
|
||||
let count=state.control_messages.fetch_add(1,Ordering::Relaxed);
|
||||
if wire::echo_matches(&message.data,1) {state.clipboard_supported.store(wire::echo_clipboard_supported(&message.data),Ordering::Release);state.echo_received.store(true,Ordering::Release);}
|
||||
if wire::echo_matches(&message.data,1) {let supported=wire::echo_clipboard_supported(&message.data);
|
||||
if state.clipboard_supported.swap(supported,Ordering::AcqRel)!=supported || !state.echo_received.load(Ordering::Acquire) {log::info!("Viewer echo: clipboard_supported={supported}");}state.echo_received.store(true,Ordering::Release);}
|
||||
if let Some(request)=wire::echo_request_seq(&message.data) {
|
||||
if let Some(control)=control_for_echo.upgrade() {let _=control.send(&bytes::Bytes::from(wire::echo_response_with_clipboard(1_000_000+request,request,clipboard_enabled))).await;}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ impl Window {
|
||||
use super::clipboard::ClipboardRequest;
|
||||
match request {
|
||||
ClipboardRequest::Read(reply)=>{
|
||||
if self.clipboard_dirty {log::debug!("Viewer clipboard read: focused={} has_text={}",self.focused,self.clipboard.has_clipboard_text());}
|
||||
let result=if self.focused && std::mem::take(&mut self.clipboard_dirty) && self.clipboard.has_clipboard_text(){read_clipboard()}else{Ok(None)};
|
||||
let _=reply.send(result);
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user