From 6bf05a6361e58dbeec5846f044d234bed04fcf02 Mon Sep 17 00:00:00 2001 From: tingfeng347 <135083299+tingfeng347@users.noreply.github.com> Date: Fri, 30 Oct 2026 13:43:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20niri=20=E4=B8=BB=E6=8E=A7?= =?UTF-8?q?=E7=AB=AF=E6=8E=A7=E5=88=B6=E5=AE=98=E6=96=B9=20Windows=20?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E5=8F=8C=E5=90=91=E6=96=87=E6=9C=AC=E5=89=AA?= =?UTF-8?q?=E8=B4=B4=E6=9D=BF=E5=90=8C=E6=AD=A5=20(#138)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #139. --- README.en.md | 3 ++- README.md | 3 ++- src/viewer/clipboard.rs | 23 ++++++++++++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/README.en.md b/README.en.md index 1c1bac0..b5094d5 100644 --- a/README.en.md +++ b/README.en.md @@ -589,7 +589,8 @@ terminal emulator (`TERMINAL` selects one). From source: `sudo apt install libsd `cargo build --release --locked --features native-viewer,viewer-sdl --bin uuremote-viewer`. SDL clipboard access reuses the desktop window to avoid temporary-window Dock churn on GNOME Wayland (#37). -Synchronization runs only while that window is focused and keeps the 30 KiB text limit. Selections without a supported +On niri, data-control-capable `wl-clipboard` is used instead, so synchronization does not require window focus. +Other SDL backends synchronize only while that window is focused. The 30 KiB text limit applies. Selections without a supported text format are skipped; empty-text detection depends on the SDL2 backend. Builds without SDL retain the command backend. SDL2 reads selections synchronously, so a slow selection owner can temporarily block the window; the bridge timeout cannot interrupt it. GNOME-to-official-Mac bidirectional clipboard synchronization is still unverified; this change does not resolve host compatibility. diff --git a/README.md b/README.md index 3c14c46..48250a0 100644 --- a/README.md +++ b/README.md @@ -514,7 +514,8 @@ xfce4-session xfce4-panel xfdesktop xfwm4 gnome-terminal`。 `ffmpeg` 命令;SDL 桌面窗口直接同步文本剪贴板(Wayland/X11),无需额外剪贴板工具;终端功能需要本机终端程序(可用 `TERMINAL` 指定)。 从源码构建:`sudo apt install libsdl2-dev`,然后 `cargo build --release --locked --features native-viewer,viewer-sdl --bin uuremote-viewer`。 -SDL 剪贴板复用桌面窗口,避免 GNOME Wayland 上临时窗口引起的 Dock 跳动(#37)。仅在桌面窗口获得焦点时同步, +SDL 剪贴板复用桌面窗口,避免 GNOME Wayland 上临时窗口引起的 Dock 跳动(#37)。niri 改用支持 data-control 的 +`wl-clipboard`,不需要桌面窗口保持焦点;其他 SDL 后端仅在桌面窗口获得焦点时同步。 保留 30 KiB 文本上限;跳过不含支持的文本格式的本地选择,空文本的识别取决于 SDL2 后端。不带 SDL 的构建保留命令后端。 SDL2 同步读取选择内容,慢速的剪贴板提供者可能暂时阻塞窗口,桥接超时无法中断该原生调用。 GNOME 与官方 Mac 被控端的双向剪贴板尚未验证通过;此修改不解决被控端兼容问题。 diff --git a/src/viewer/clipboard.rs b/src/viewer/clipboard.rs index aa3434d..2cfd316 100644 --- a/src/viewer/clipboard.rs +++ b/src/viewer/clipboard.rs @@ -156,6 +156,16 @@ async fn send(channel:&RTCDataChannel,message:Vec)->Result<(),()>{ tokio::time::timeout(Duration::from_secs(2),channel.send(&bytes::Bytes::from(message))).await.map_err(|_|())?.map_err(|_|())?;Ok(()) } pub struct Bridge {backend:Option,pub enabled:bool,tx:Option>>,task:Option>,target_mac:Option} +#[cfg(feature="viewer-sdl")] +fn sdl_backend(wayland:bool,niri:bool,tx:mpsc::Sender,find:impl Fn(&str)->Option)->Option{ + if wayland && niri { + // SDL3 only retains a Wayland selection offer associated with its seat; + // niri's regular clipboard is not exposed through that seat state. + // Unlike GNOME, niri supports data-control, so polling wl-clipboard + // neither requires a focused toplevel nor creates transient windows. + CommandBackend::select(true,find).map(Backend::Command).or(Some(Backend::Sdl(tx))) + }else{Some(Backend::Sdl(tx))} +} impl Bridge { pub fn new(desktop:bool)->Self{ let backend=if desktop{Backend::detect()}else{None};let enabled=backend.is_some(); @@ -163,7 +173,9 @@ impl Bridge { } #[cfg(feature="viewer-sdl")] pub fn sdl(tx:mpsc::Sender)->Self{ - let backend=(std::env::var("UU_VIEWER_CLIPBOARD").as_deref()!=Ok("0")).then_some(Backend::Sdl(tx)); + let wayland=std::env::var_os("WAYLAND_DISPLAY").is_some_and(|v|!v.is_empty()); + let backend=(std::env::var("UU_VIEWER_CLIPBOARD").as_deref()!=Ok("0")) + .then(||sdl_backend(wayland,std::env::var_os("NIRI_SOCKET").is_some(),tx,executable)).flatten(); Self{enabled:backend.is_some(),backend,tx:None,task:None,target_mac:None} } pub fn set_target_mac(&mut self,mac:Option){self.target_mac=mac;} @@ -249,6 +261,15 @@ impl Drop for Bridge{fn drop(&mut self){self.stop();}} assert!(select(true,&[]).is_none()); } #[cfg(feature="viewer-sdl")] + #[test] fn niri_command_backend_avoids_sdl_seat_selection(){ + let(tx,_rx)=mpsc::channel(1); + let find=|n:&str|n.starts_with("wl-").then(||PathBuf::from(n)); + assert!(matches!(sdl_backend(true,true,tx.clone(),find),Some(Backend::Command(_)))); + assert!(matches!(sdl_backend(true,true,tx.clone(),|_|None),Some(Backend::Sdl(_)))); + assert!(matches!(sdl_backend(true,false,tx.clone(),find),Some(Backend::Sdl(_)))); + assert!(matches!(sdl_backend(false,true,tx,find),Some(Backend::Sdl(_)))); + } + #[cfg(feature="viewer-sdl")] #[tokio::test] async fn unfocused_write_does_not_mark_remote_text_as_applied(){ let(tx,mut rx)=mpsc::channel(8);let backend=Backend::Sdl(tx); let ui=tokio::spawn(async move{