From ef14f76422381a1a6131889c699e3e9a559d4227 Mon Sep 17 00:00:00 2001 From: m <46401469+xfjm136@users.noreply.github.com> Date: Mon, 2 Nov 2026 13:18:55 +0800 Subject: [PATCH] fix(viewer): disable local IME text input in remote desktop window (#150) --- README.en.md | 2 ++ README.md | 2 ++ src/viewer/sdl.rs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/README.en.md b/README.en.md index a1ef3f7..8700da9 100644 --- a/README.en.md +++ b/README.en.md @@ -640,6 +640,8 @@ GNOME-to-official-Mac bidirectional clipboard synchronization is still unverifie - Frames are decoded at the host's native resolution and scaled to the window with linear filtering; a host resolution change restarts the decoder. `UU_VIEWER_SIZE=WxH` forces a fixed letterboxed canvas instead. +The SDL remote desktop window disables local IME text composition and forwards physical keys; use the remote host’s input method and its language toggle (for example, Shift) to enter Chinese. + Mac targets use native macOS keycodes; Windows / Linux targets retain Windows VK. Keys follow physical positions, without automatically translating Ctrl to Command; on a Mac target the PC Super / Windows key acts as Command. Only verified target platform values 1 (Windows / this project's Linux host) and 4 (Mac) are accepted; unknown values fail explicitly. Account diff --git a/README.md b/README.md index 3e67e65..c595a85 100644 --- a/README.md +++ b/README.md @@ -563,6 +563,8 @@ GNOME 与官方 Mac 被控端的双向剪贴板尚未验证通过;此修改不 以 CaptureSettingSync 回报为准。两种色度均由 FFmpeg 转为 RGB24 显示。 - 按被控端原始分辨率解码,窗口缩放使用线性过滤;被控端分辨率变化时自动重启解码器。`UU_VIEWER_SIZE=WxH` 可改为固定的留黑边画布。 +SDL 远程画面窗口关闭本地输入法的文本组合,按物理键转发;输入中文时请使用被控端的输入法及其中英切换键(例如 Shift)。 + Mac 目标使用 macOS 原生键码,Windows / Linux 目标保留 Windows VK。键盘按物理键位置转发,不自动把 Ctrl 改成 Command; 控制 Mac 时,PC 键盘的 Super / Win 键对应 Command。仅接受已验证的目标平台值 1(Windows / 本项目 Linux 主机)和 4(Mac), 未知值会报错,不猜测键码。账号连接缺少平台字段时查询目标设备;远程协助必须由连接响应提供平台。只看模式不需要此识别。 diff --git a/src/viewer/sdl.rs b/src/viewer/sdl.rs index d991097..2b1fd15 100644 --- a/src/viewer/sdl.rs +++ b/src/viewer/sdl.rs @@ -19,6 +19,9 @@ impl Window { let name=super::device_label(std::env::var("UU_VIEWER_DEVICE_NAME").ok().as_deref()).to_owned(); let window=video.window(&format!("{name} · {}",crate::i18n::s("UU 远程 Linux 控制端","UU Remote Linux viewer")),1280,720).position_centered().resizable().build().map_err(|_|"Window creation failed")?; let mut canvas=window.into_canvas().build().map_err(|_|"Renderer creation failed")?; + // This window forwards scancodes, not SDL_TEXTINPUT. SDL enables text input by + // default; its X11 IME path can consume keys before KeyDown/KeyUp (#149). + video.text_input().stop(); // Wayland maps a toplevel only after its first buffer; without this the window stays // invisible until the first decoded frame, which a stalled stream never delivers. canvas.set_draw_color(LOADING_BG);canvas.clear();canvas.present(); @@ -708,6 +711,33 @@ async fn pump_type_job(job: &mut TypeJob, session: &mut Session, window: &mut Wi #[cfg(test)] mod tests { use super::*; + #[cfg_attr(target_os="macos",ignore)] + #[test] fn remote_window_disables_local_text_input_and_forwards_shift(){ + if std::env::var_os("UU_VIEWER_IME_TEST_CHILD").is_none(){ + let output=std::process::Command::new(std::env::current_exe().unwrap()) + .args(["--exact","viewer::sdl::tests::remote_window_disables_local_text_input_and_forwards_shift","--test-threads=1"]) + .env("SDL_VIDEODRIVER","dummy").env("UU_VIEWER_IME_TEST_CHILD","1").output().unwrap(); + assert!(output.status.success(),"{}{}",String::from_utf8_lossy(&output.stdout),String::from_utf8_lossy(&output.stderr));return + } + let mut window=Window::new().unwrap(); + assert!(!window.canvas.window().subsystem().text_input().is_active()); + let id=window.canvas.window().id(); + let key=|down,scan|if down { + Event::KeyDown{timestamp:0,window_id:id,keycode:None,scancode:Some(scan),keymod:sdl2::keyboard::Mod::NOMOD,repeat:false} + }else{ + Event::KeyUp{timestamp:0,window_id:id,keycode:None,scancode:Some(scan),keymod:sdl2::keyboard::Mod::NOMOD,repeat:false} + }; + let push=|event|window._sdl.event().unwrap().push_event(event).unwrap(); + use sdl2::keyboard::Scancode as S; + for event in [key(true,S::LShift),key(false,S::LShift),key(true,S::A),key(false,S::A), + key(true,S::RShift),Event::Window{timestamp:0,window_id:id,win_event:WindowEvent::FocusLost}, + Event::Window{timestamp:0,window_id:id,win_event:WindowEvent::FocusGained}] {push(event);} + let (_,messages)=window.poll(&mut Input::new(false)); + let keys:Vec<_>=messages.iter().filter_map(|m|Some((m.get("action")?.as_str()?,m.get("key")?.as_i64()?))).collect(); + assert_eq!(keys,vec![("kbd_press",0xa0),("kbd_release",0xa0),("kbd_press",0x41),("kbd_release",0x41), + ("kbd_press",0xa1),("kbd_release",0xa1)]); + assert!(!window.canvas.window().subsystem().text_input().is_active()); + } // macOS: SDL video must start on the main thread, which the test harness does not use; CI runs it on Linux. #[cfg_attr(target_os="macos",ignore)] #[tokio::test] async fn clipboard_requests_use_existing_window(){