Compare commits

..
13 Commits
Author SHA1 Message Date
VallierDevandClaude Opus 5.5 7beb3aecf0 Release v0.1.6
Docs for headless mode, virtual desktop, uinput udev rule and terminal
shortcuts; release tarball ships contrib/.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-15 10:15:59 +08:00
VallierDevandClaude Opus 5.5 26d4812480 Headless mode, virtual desktop scripts, tool peers without a desktop
- UU_DESKTOP_BACKEND=none: host goes online without a display; terminal, file
  transfer and port mapping stay available, desktop offers are ignored.
- Tool peers (file/terminal/port mapping) get a nominal ScreenSources/CaptureChange
  and Allow permissions when no desktop is available: the port-mapping viewer
  aborts otherwise (also affected portal hosts before local consent).
- x11_engine: an explicit DISPLAY that cannot be opened no longer falls back to
  :0/:1 (would silently capture the physical screen).
- contrib/virtual-desktop: Xvfb + desktop session on the systemd user bus
  (or a private dbus-run-session bus) and a uuremote-native drop-in.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-15 10:13:58 +08:00
VallierDevandClaude Opus 5.5 49edf1d389 uinput input backend and terminal-aware paste
- uinput.rs: kernel virtual keyboard + absolute pointer (Sunshine-style),
  physical evdev keycodes so the compositor's keysym lookup cannot drop
  shifted symbols (#3). Auto on Wayland/portal when /dev/uinput is
  accessible (udev uaccess rule), XTest kept on X11 (it suppresses
  autorepeat for held keys over latency). UU_INPUT_BACKEND=auto|uinput|native.
- Mac viewers send Cmd+V as Ctrl+V (verified: Cmd and Ctrl both arrive as
  VK_LCONTROL). In a focused X11 terminal Ctrl+V becomes Ctrl+Shift+V so it
  pastes instead of quoting the next key; Ctrl+C always interrupts (copy is
  Cmd+Shift+C). UU_TERMINAL_SHORTCUTS=0 disables.

Verified on the 3090 with the official Mac viewer: paste, interrupt,
uinput typing incl. underscores.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-15 09:49:03 +08:00
VallierDevandClaude Opus 5.5 ddbc75bbf6 Release v0.1.5
Room reconnect-key keepalive (fixes ~20 min cloud release), XDamage on
the opt-in in-process path, portal clipboard documented.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-15 08:27:42 +08:00
VallierDev 9fbe7d63c5 Recognize delayed reconnect-key refresh acknowledgements without regressing keys 2026-10-15 08:25:12 +08:00
VallierDev 3a78491f25 Close stale signaling writers even when live peer callbacks retain the sender 2026-10-15 08:25:12 +08:00
VallierDev fc8c10cde9 Refresh official room reconnect key periodically and stop obsolete signaling receivers 2026-10-15 08:25:12 +08:00
VallierDev 125baa8c8b Use GNOME session idle inhibition during isolated long-connection acceptance 2026-10-15 08:25:12 +08:00
VallierDev c5aa238f73 Distinguish cloud release events and trace signaling heartbeat progress without credentials 2026-10-15 08:25:12 +08:00
VallierDev 3673d37c1e Keep official viewer focus during marker-only reverse clipboard acceptance 2026-10-15 08:25:12 +08:00
ferstar 59a45e092b Address review on the XDamage capture PR
- Viewer PLI/FIR: dedupe only while an IDR is pending; drop the 1 s gap so a lost IDR cannot block recovery.
- XShm: release the local mapping on every attach failure; mark the segment for removal in all cases.
- Damage events no longer defer an overdue capture.
- After idle, the next tick is one frame after now instead of now.
2026-10-15 08:22:14 +08:00
ferstar a870f7d041 Limit viewer keyframe requests to one per second and none while one is pending
Accepted PLI/FIR feedback now goes through KeyframeGate: at most one request per
second, and none while the previous request still waits for the encoder.
2026-10-15 08:22:14 +08:00
ferstar 367be30a0f Capture only changed frames with XDamage on the in-process path
The in-process encoder can now capture through XShm and XDamage in pure Rust
(x11rb) instead of libav's x11grab. Damage marks the picture dirty; a dirty
picture is captured and encoded on a fixed frame tick so the stream keeps a
steady cadence. An idle screen sends a keepalive every 40-67 ms (15-25 fps,
random) so the viewer does not treat a static desktop as stalled.

- src/damage_capture.rs: XDamage NonEmpty reports and XShm copy-out
- src/inproc_encoder.rs: run_damage loop; x11grab stays as the fallback
- UU_CAPTURE=grab forces the x11grab path
- x11rb is an optional dependency, enabled by the inproc-av feature only

Measured on a static desktop, CPU drops from about 12% to about 1% versus
x11grab. Moving content costs about the same CPU as x11grab.
2026-10-15 08:22:14 +08:00
23 changed files with 1092 additions and 55 deletions

No files matched your search

+1
View File
@@ -26,6 +26,7 @@ jobs:
name=uu-remote-linux-${GITHUB_REF_NAME}-x86_64-linux
mkdir -p "$name"
cp target/release/uuremote-server LICENSE README.md README.en.md config.example.json "$name/"
cp -r contrib "$name/"
tar czf "$name.tar.gz" "$name"
sha256sum "$name.tar.gz" > "$name.tar.gz.sha256"
- uses: softprops/action-gh-release@v2
+8 -2
View File
@@ -104,7 +104,10 @@ viewer does not reconnect them automatically.
|---|---|
| `~/.config/uuremote/config.json` | user_id, device_id, client_id, system_id, machine_guid, token, csrf; optional `sign_key`, `ffmpeg_root`. `$UU_CONFIG` overrides the path |
| `~/.config/uuremote/host_settings.json` | persisted 安全 settings: auto_lock, keep_mute, mute_permanent |
| `UU_DESKTOP_BACKEND` | `auto` (default) / `x11` / `wayland` / `portal` |
| `UU_DESKTOP_BACKEND` | `auto` (default) / `x11` / `wayland` / `portal` / `none` (headless: no display; desktop offers ignored; tool peers get a nominal 1920x1080 screen + Allow permissions, which the port-mapping viewer requires) |
| `UU_INPUT_BACKEND` | `auto` (uinput on Wayland/portal when `/dev/uinput` is accessible, udev `uaccess` rule in README) / `uinput` / `native`. X11 keeps XTest (held-key autorepeat handling) |
| `UU_TERMINAL_SHORTCUTS=0` | disable Ctrl+V → Ctrl+Shift+V in focused X11 terminals (Mac Cmd and Ctrl both arrive as VK_LCONTROL) |
| `contrib/virtual-desktop/` | Xvfb + session (`UU_VIRTUAL_SESSION`, `UU_VIRTUAL_BUS=user|private`) for monitorless hosts; serve it with `DISPLAY=:99` |
| `UU_VIDEO_ENCODER=cpu` | force libx264 instead of NVENC |
| `UU_FFMPEG_ROOT` | FFmpeg prefix (`bin/ffmpeg`, libs in `lib/x86_64-linux-gnu`) |
| `UU_AUDIO=0`, `UU_AUDIO_SOURCE` | disable sound / choose the Pulse source (default `@DEFAULT_MONITOR@`) |
@@ -123,7 +126,7 @@ every 60 s.
| `src/webrtc.rs` | peer connection, data channels, CONTROL dispatch, initialization messages |
| `src/video.rs`, `src/capture_setting.rs` | FFmpeg H.264 pipeline; viewer quality/fps/resolution settings |
| `src/audio.rs` | Pulse/PipeWire monitor → Opus audio track |
| `src/input.rs`, `src/input_mapping.rs` | input injection (X11 XTest / Wayland / portal), Windows VK → keysym |
| `src/input.rs`, `src/input_mapping.rs`, `src/uinput.rs` | input injection (X11 XTest / Wayland / portal / uinput), Windows VK → keysym → evdev |
| `src/cursor.rs` | pointer shape mirroring (X11) |
| `src/clipboard*.rs` | text clipboard bridge and protocol |
| `src/file_trans.rs` | FileTransferFtp RPC |
@@ -196,6 +199,9 @@ started a second full host server instead, so check that a subcommand exists in
- Remote keys repeat at high RTT because key-up arrives after the X autorepeat delay. XTEST repeats through the
master keyboard; the engine disables global autorepeat only while a remote key is held.
- Interactive shells ignore SIGTERM: the server HUPs/KILLs PTY sessions on shutdown.
- An explicit `DISPLAY` that cannot be opened is an error; the X11 engine falls back to `:0`/`:1` only when DISPLAY is unset.
- systemd/D-Bus-activated apps (GNOME Terminal, portals) run with the user manager's environment, not the caller's:
a private `dbus-run-session` bus does not bring them onto a virtual display.
- GTK windows stop repainting while GNOME is locked or the monitor is off; test UI on Xvfb or after unlock.
- logind `unlock-session` by the session owner clears the GNOME shield in ~3 s.
- GNOME closes the portal session on lock; capture/input must share one portal session and be rebuilt after
Generated
+56 -1
View File
@@ -111,6 +111,12 @@ dependencies = [
"rustversion",
]
[[package]]
name = "as-raw-xcb-connection"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "175571dd1d178ced59193a6fc02dde1b972eb0bc56c892cde9beeceac5bf0f6b"
[[package]]
name = "asn1-rs"
version = "0.5.2"
@@ -801,6 +807,16 @@ dependencies = [
"zeroize",
]
[[package]]
name = "gethostname"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8"
dependencies = [
"rustix",
"windows-link",
]
[[package]]
name = "getrandom"
version = "0.2.17"
@@ -1210,6 +1226,12 @@ dependencies = [
"windows-link",
]
[[package]]
name = "linux-raw-sys"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
[[package]]
name = "litemap"
version = "0.8.3"
@@ -1885,6 +1907,19 @@ dependencies = [
"nom",
]
[[package]]
name = "rustix"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "891efababe418670775f199f0d233d84843c227a0949a883ce15b37c78d6629d"
dependencies = [
"bitflags 2.13.2",
"errno",
"libc",
"linux-raw-sys",
"windows-sys 0.61.2",
]
[[package]]
name = "rustls"
version = "0.21.12"
@@ -2614,7 +2649,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "uu-remote-linux"
version = "0.1.4"
version = "0.1.6"
dependencies = [
"base64 0.22.1",
"bytes",
@@ -2636,6 +2671,7 @@ dependencies = [
"tokio",
"tokio-tungstenite",
"webrtc",
"x11rb",
]
[[package]]
@@ -3094,6 +3130,25 @@ version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc"
[[package]]
name = "x11rb"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9993aa5be5a26815fe2c3eacfc1fde061fc1a1f094bf1ad2a18bf9c495dd7414"
dependencies = [
"as-raw-xcb-connection",
"gethostname",
"libc",
"rustix",
"x11rb-protocol",
]
[[package]]
name = "x11rb-protocol"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea6fc2961e4ef194dcbfe56bb845534d0dc8098940c7e5c012a258bfec6701bd"
[[package]]
name = "x25519-dalek"
version = "2.0.1"
+3 -2
View File
@@ -1,6 +1,6 @@
[package]
name = "uu-remote-linux"
version = "0.1.4"
version = "0.1.6"
edition = "2021"
authors = ["uu-remote-linux contributors"]
description = "Unofficial Linux host for NetEase UU Remote: control a Linux desktop from the official clients"
@@ -19,7 +19,7 @@ wayland = []
portal = []
# In-process capture and encoding through FFmpeg 6 libraries (libavcodec/libavdevice dev packages).
# Off by default so release binaries do not link the build machine's libav.
inproc-av = ["dep:ffmpeg-next"]
inproc-av = ["dep:ffmpeg-next", "dep:x11rb"]
[dependencies]
tokio = { version = "1", features = ["full"] }
@@ -41,6 +41,7 @@ log = "0.4"
qrcode = { version = "0.14", default-features = false }
env_logger = "0.11"
ffmpeg-next = { version = "6.1", optional = true, default-features = false, features = ["codec", "format", "device", "software-scaling", "software-resampling"] }
x11rb = { version = "0.13", features = ["damage", "shm", "allow-unsafe-code"], optional = true }
[build-dependencies]
cc = "1.0"
+51 -5
View File
@@ -33,7 +33,8 @@
|---|---|
| QR login | GTK login window (or a terminal QR code with `login --no-gui`); expired codes refresh automatically; the service opens the login window by itself when credentials are missing or expired |
| Remote desktop | H.264 video, NVENC hardware encoding on NVIDIA GPUs, libx264 otherwise; the viewer draws its local pointer, so there is no double cursor |
| Mouse / keyboard | Absolute and relative motion, clicks, wheel, keys; no spurious key repeat on high-latency links |
| Mouse / keyboard | Absolute and relative motion, clicks, wheel, keys; no spurious key repeat on high-latency links; optional uinput virtual devices on Wayland (layout independent, see below) |
| Terminal shortcuts | Mac viewers send both Cmd and Ctrl as Ctrl. In a focused terminal window Ctrl+V / Cmd+V become Ctrl+Shift+V (paste); Ctrl+C always interrupts, copy with Cmd+Shift+C (X11) |
| Pointer shape | Remote cursor shape is mirrored to the viewer (X11) |
| Clipboard | Two-way text sync |
| Quality / frame rate / resolution | Auto, Original 20M, Ultra 8M, HD 2M, custom; 30/60/90/144 fps; "other resolutions" are scaled by the encoder, the host monitor is left untouched |
@@ -46,6 +47,7 @@
| System actions | Lock, show desktop, task manager (system monitor), reboot, shut down |
| Port mapping | The official "port mapping" tool: forwards a local port on the viewer to an address reachable from the Linux host (e.g. 127.0.0.1:22); `UU_PORT_MAPPING=0` disables it |
| Reconnects | Every tool window has its own connection; they do not disturb each other |
| Headless servers | Goes online without a monitor with terminal, file transfer and port mapping; an Xvfb virtual desktop gives a full remote desktop (see below) |
## Supported Linux desktops
@@ -62,8 +64,8 @@ Apart from GNOME on X11, these desktops have been tested in virtual machines so
real hardware, please [open an issue](../../issues) with your distribution, desktop, GPU and the relevant lines from
`journalctl --user -u uuremote-native.service`.
Wayland limits: single screen, fixed resolution. The portal backend does not support clipboard, screen wake or
dynamic resolution yet. On the first connection the desktop asks for "Remote Desktop / Screen Sharing"
Wayland limits: single screen, fixed resolution. The portal backend does not support screen wake or
dynamic resolution yet; the clipboard syncs while the viewer's remote window has focus. On the first connection the desktop asks for "Remote Desktop / Screen Sharing"
permission; the permission is remembered once granted.
## Not implemented / not supported
@@ -77,7 +79,7 @@ permission; the permission is remembered once granted.
| Privacy screen on the host | Not implemented |
| Microphone (viewer audio played on the host) | Not implemented (needs a virtual sound card) |
| Plugins such as the WoW queue notifier | Not supported; the client is told that no plugins exist |
| Access before login (greeter / no user logged in) | Not supported; only an already logged-in desktop session can be controlled |
| Access before login (greeter / no user logged in) | The greeter cannot be controlled; without a logged-in user use headless mode or a virtual desktop (see below) |
| Relay connections on restrictive networks | Uses the ICE servers provided by the UU cloud; complex network setups are not thoroughly tested |
| Acting as a viewer (controlling other machines from Linux) | Out of scope |
@@ -149,6 +151,48 @@ journalctl --user -u uuremote-native.service -f # online once you see availabi
If you have not logged in yet, the service opens the QR login window on your desktop.
### 5. uinput virtual keyboard/mouse on Wayland (recommended)
On Wayland (especially GNOME/KDE via the portal) the default input path needs portal consent and some keyboard layouts
drop symbols such as the underscore. Once the logged-in user may access `/dev/uinput`, the host switches to kernel
virtual devices that send physical key codes:
```sh
echo 'KERNEL=="uinput", SUBSYSTEM=="misc", OPTIONS+="static_node=uinput", TAG+="uaccess"' | \
sudo tee /etc/udev/rules.d/60-uu-remote-linux-uinput.rules
sudo udevadm control --reload && sudo udevadm trigger --name-match=uinput
```
`uaccess` grants access only to the user sitting at the machine. `UU_INPUT_BACKEND=uinput|native` forces a backend.
X11 keeps XTest by default because it handles held keys correctly on high-latency links.
## Servers without a monitor
**Headless mode** (terminal, file transfer and port mapping only): add `Environment=UU_DESKTOP_BACKEND=none` to the
service and run `loginctl enable-linger $USER`, so the systemd user manager (with `XDG_RUNTIME_DIR` and the user D-Bus)
starts at boot without a login. The viewer's remote desktop keeps showing "connecting" in this mode; that is expected.
Log in once with `uuremote-server login --no-gui` (QR in the terminal).
**Virtual desktop**: for a full remote desktop, run a desktop session (Xfce recommended) on an Xvfb screen:
```sh
sudo apt install xvfb dbus-x11 xfce4 # or another session, chosen with UU_VIRTUAL_SESSION
install -Dm755 contrib/virtual-desktop/uu-virtual-desktop ~/.local/bin/uu-virtual-desktop
install -Dm644 contrib/virtual-desktop/uu-virtual-desktop.service ~/.config/systemd/user/uu-virtual-desktop.service
install -Dm644 contrib/virtual-desktop/virtual-display.conf ~/.config/systemd/user/uuremote-native.service.d/virtual-display.conf
loginctl enable-linger $USER
systemctl --user daemon-reload && systemctl --user enable --now uu-virtual-desktop.service
systemctl --user restart uuremote-native.service
```
The virtual screen is `:99`, 1920x1080 by default. Xvfb has no GPU acceleration, so it is a little less smooth than a
real display; NVENC is still used for encoding when an NVIDIA GPU is present. The script exports `DISPLAY` to the
systemd user session so D-Bus-activated programs open on the virtual screen; on a machine that also runs a real desktop
session set `UU_VIRTUAL_BUS=private` so the real session is not affected.
To make a GPU drive a real (non-Xvfb) desktop without a monitor, use a dummy HDMI plug or load an EDID file with the
kernel parameter `drm.edid_firmware=`, then install as for a normal X11 desktop.
## Configuration
Common environment variables:
@@ -156,7 +200,9 @@ Common environment variables:
| Variable | Purpose |
|---|---|
| `UU_CONFIG` | Config file path (default `~/.config/uuremote/config.json`) |
| `UU_DESKTOP_BACKEND` | `auto` / `x11` / `wayland` / `portal` |
| `UU_DESKTOP_BACKEND` | `auto` / `x11` / `wayland` / `portal` / `none` (headless) |
| `UU_INPUT_BACKEND` | `auto` (default: uinput on Wayland when accessible) / `uinput` / `native` |
| `UU_TERMINAL_SHORTCUTS=0` | Disable the Ctrl+V paste rewrite in terminal windows |
| `UU_VIDEO_ENCODER=cpu` | Force CPU encoding |
| `UU_FFMPEG_ROOT` | Use FFmpeg from this prefix |
| `UU_AUDIO=0` | Disable sound; `UU_AUDIO_SOURCE` picks the PulseAudio source |
+47 -4
View File
@@ -29,7 +29,8 @@
|---|---|
| 扫码登录 | GTK 登录窗口(或 `login --no-gui` 终端二维码);二维码过期自动刷新;登录凭证失效时服务会自动弹出登录窗口 |
| 远程桌面 | H.264 视频,NVIDIA 显卡用 NVENC 硬件编码,否则用 libx264;查看端绘制本地鼠标,不会出现双光标 |
| 鼠标 / 键盘 | 绝对/相对移动、点击、滚轮、按键;修复了网络延迟导致的按键连发 |
| 鼠标 / 键盘 | 绝对/相对移动、点击、滚轮、按键;修复了网络延迟导致的按键连发;Wayland 下可用 uinput 虚拟键鼠(不依赖键盘布局,见下文) |
| 终端快捷键 | Mac 控制端的 Cmd 和 Ctrl 到被控端都是 Ctrl。焦点在终端窗口时,Ctrl+V / Cmd+V 自动转成 Ctrl+Shift+V 粘贴;Ctrl+C 始终是中断,复制请用 Cmd+Shift+C(X11) |
| 鼠标指针样式 | 远端指针形状实时同步(X11) |
| 剪贴板 | 双向文本同步 |
| 画质 / 帧率 / 分辨率 | 自动、原画 20M、超清 8M、高清 2M、自定义;30/60/90/144 帧;「其他分辨率」由编码器缩放,不改动主机显示器 |
@@ -42,6 +43,7 @@
| 系统操作 | 锁屏、显示桌面、任务管理器(系统监视器)、重启、关机 |
| 端口映射 | 官方「端口映射」工具:把控制端本地端口转发到 Linux 能访问到的地址(如 127.0.0.1:22);`UU_PORT_MAPPING=0` 可关闭 |
| 多次重连 | 每个工具窗口独立连接,互不影响 |
| 无头服务器 | 没有显示器也能上线,提供终端、文件传输和端口映射;也可以用 Xvfb 虚拟桌面提供完整远程桌面(见下文) |
## 支持的 Linux 桌面
@@ -57,7 +59,7 @@
除 GNOME(X11)外,其余桌面目前都是在虚拟机里测试的。如果你在真机上遇到问题,欢迎[提交 issue](../../issues),
请附上发行版、桌面环境、显卡型号和 `journalctl --user -u uuremote-native.service` 里的相关日志。
Wayland 下的限制:只支持单屏、固定分辨率;portal 后端暂不支持剪贴板、唤醒屏幕和动态分辨率。
Wayland 下的限制:只支持单屏、固定分辨率;portal 后端暂不支持唤醒屏幕和动态分辨率;剪贴板只在控制端的远控窗口处于前台时同步。
首次连接时,桌面会弹窗请求「远程桌面 / 屏幕共享」授权,同意后会记住授权。
## 尚未实现 / 不支持
@@ -71,7 +73,7 @@ Wayland 下的限制:只支持单屏、固定分辨率;portal 后端暂不
| 被控端防窥模式 | 未实现 |
| 麦克风(控制端声音传到被控端) | 未实现(需要虚拟声卡) |
| 魔兽世界排队提醒等插件 | 不支持,会明确告诉客户端「无插件」 |
| 登录前(登录界面 / 无人登录)访问 | 不支持,只能控制已登录的桌面会话 |
| 登录前(登录界面 / 无人登录)访问 | 不支持控制登录界面;没有人登录时可以用无头模式或虚拟桌面(见下文) |
| 跨运营商 / 受限网络的中继连接 | 已接入官方下发的 ICE 服务器,但复杂网络环境未充分测试 |
| 作为控制端(在 Linux 上控制别的电脑) | 不在本项目范围 |
@@ -142,6 +144,45 @@ journalctl --user -u uuremote-native.service -f # 看到 availability=Some("re
如果还没有登录,服务会自动在桌面上弹出扫码窗口。
### 5. Wayland 下使用 uinput 虚拟键鼠(推荐)
Wayland(尤其是 GNOME/KDE portal)下,默认的键鼠注入要经过 portal 授权,部分键盘布局下还会丢符号(比如下划线)。
允许当前登录用户访问 `/dev/uinput` 后,服务会自动改用内核级虚拟键盘和鼠标,发送物理按键码:
```sh
echo 'KERNEL=="uinput", SUBSYSTEM=="misc", OPTIONS+="static_node=uinput", TAG+="uaccess"' | \
sudo tee /etc/udev/rules.d/60-uu-remote-linux-uinput.rules
sudo udevadm control --reload && sudo udevadm trigger --name-match=uinput
```
`uaccess` 只把权限给当前坐在这台机器前的登录用户。`UU_INPUT_BACKEND=uinput|native` 可以强制指定后端。
X11 默认继续用 XTest,因为它能正确处理网络延迟下按住不放的按键。
## 没有显示器的服务器
**无头模式**:只要终端、文件传输和端口映射,不需要图形界面。在服务里加 `Environment=UU_DESKTOP_BACKEND=none`,
再执行 `loginctl enable-linger $USER`,这样开机后不用登录,systemd 用户服务(以及 `XDG_RUNTIME_DIR`、用户 D-Bus)也会自动启动。
无头模式下控制端点「远程桌面」会一直显示正在连接,这是正常的。首次登录用 `uuremote-server login --no-gui` 在终端里扫码。
**虚拟桌面**:需要完整的远程桌面时,用 Xvfb 创建一块虚拟屏幕,再在上面跑一个桌面环境(推荐 Xfce):
```sh
sudo apt install xvfb dbus-x11 xfce4 # 或其他桌面环境,用 UU_VIRTUAL_SESSION 指定
install -Dm755 contrib/virtual-desktop/uu-virtual-desktop ~/.local/bin/uu-virtual-desktop
install -Dm644 contrib/virtual-desktop/uu-virtual-desktop.service ~/.config/systemd/user/uu-virtual-desktop.service
install -Dm644 contrib/virtual-desktop/virtual-display.conf ~/.config/systemd/user/uuremote-native.service.d/virtual-display.conf
loginctl enable-linger $USER
systemctl --user daemon-reload && systemctl --user enable --now uu-virtual-desktop.service
systemctl --user restart uuremote-native.service
```
虚拟屏幕默认是 `:99`、1920x1080。Xvfb 没有 GPU 加速,流畅度比真实显示器略差;有 NVIDIA 显卡时视频仍然用 NVENC 编码。
脚本会把 `DISPLAY` 导入 systemd 用户会话,这样通过 D-Bus 启动的程序也会显示在虚拟屏幕上;
如果这台机器同时还有真实的桌面会话,请设 `UU_VIRTUAL_BUS=private`,避免影响真实桌面。
想让 NVIDIA/AMD 显卡在不接显示器时也正常输出画面(而不是用 Xvfb),可以用假显示器插头(HDMI 诱骗器),
或者用内核参数 `drm.edid_firmware=` 加载 EDID 文件,再按普通 X11 桌面的方式安装。
## 配置
常用环境变量:
@@ -149,7 +190,9 @@ journalctl --user -u uuremote-native.service -f # 看到 availability=Some("re
| 变量 | 作用 |
|---|---|
| `UU_CONFIG` | 配置文件路径(默认 `~/.config/uuremote/config.json`) |
| `UU_DESKTOP_BACKEND` | `auto` / `x11` / `wayland` / `portal` |
| `UU_DESKTOP_BACKEND` | `auto` / `x11` / `wayland` / `portal` / `none`(无头模式) |
| `UU_INPUT_BACKEND` | `auto`(默认,Wayland 下可用时用 uinput)/ `uinput` / `native` |
| `UU_TERMINAL_SHORTCUTS=0` | 关闭终端窗口里的 Ctrl+V 粘贴转换 |
| `UU_VIDEO_ENCODER=cpu` | 强制使用 CPU 编码 |
| `UU_FFMPEG_ROOT` | 使用指定目录下的 FFmpeg |
| `UU_AUDIO=0` | 关闭声音转发;`UU_AUDIO_SOURCE` 指定 PulseAudio 采集源 |
+47 -2
View File
@@ -9,6 +9,8 @@
#include <sys/ipc.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <strings.h>
#include <X11/extensions/XShm.h>
#include <X11/extensions/XTest.h>
#include <X11/extensions/Xfixes.h>
@@ -58,9 +60,12 @@ int x11_init(const char *display_name) {
g_display = XOpenDisplay(display_name);
} else {
const char *configured = getenv("DISPLAY");
/* An explicit DISPLAY that fails must not silently fall back to another (physical) screen. */
if (configured && *configured) g_display = XOpenDisplay(configured);
if (!g_display) g_display = XOpenDisplay(":0");
if (!g_display) g_display = XOpenDisplay(":1");
else {
g_display = XOpenDisplay(":0");
if (!g_display) g_display = XOpenDisplay(":1");
}
}
if (!g_display) {
return -1;
@@ -190,6 +195,46 @@ int x11_key_event(int keycode, int is_press) {
return 0;
}
/* ---- Terminal-aware paste (Mac viewer Cmd+V arrives as Ctrl+V) ------------------------------
* Linux terminals paste with Ctrl+Shift+V; Ctrl+V quotes the next key (a paste then shows as
* "^[[200~..."). Reports whether the focused window is a terminal emulator. Uses its own
* connection so it never races the capture/input connection. */
static Display *g_probe = NULL;
static int class_is_terminal(const char *value) {
static const char *names[] = { "gnome-terminal", "gnome-terminal-server", "org.gnome.Console", "kgx", "konsole",
"xfce4-terminal", "mate-terminal", "lxterminal", "qterminal", "terminator", "tilix", "xterm", "uxterm",
"urxvt", "rxvt", "alacritty", "kitty", "wezterm", "wezterm-gui", "foot", "st-256color", "terminology",
"guake", "tilda", "deepin-terminal", "ptyxis", "io.elementary.terminal", "cool-retro-term", NULL };
if (!value) return 0;
for (int i = 0; names[i]; i++) if (strcasecmp(value, names[i]) == 0) return 1;
return 0;
}
/* Returns 1 when the focused window belongs to a terminal emulator, else 0. */
int x11_terminal_shortcut_state(void) {
if (!g_probe && !(g_probe = XOpenDisplay(NULL))) return 0;
Window focus = 0; int revert = 0;
XGetInputFocus(g_probe, &focus, &revert);
if (focus == None || focus == PointerRoot) return 0;
Window cur = focus;
for (int depth = 0; depth < 12 && cur; depth++) {
XClassHint hint = {0};
if (XGetClassHint(g_probe, cur, &hint)) {
int terminal = class_is_terminal(hint.res_name) || class_is_terminal(hint.res_class);
if (hint.res_name) XFree(hint.res_name);
if (hint.res_class) XFree(hint.res_class);
return terminal;
}
Window root, parent, *children = NULL; unsigned int n = 0;
if (!XQueryTree(g_probe, cur, &root, &parent, &children, &n)) return 0;
if (children) XFree(children);
if (parent == root) return 0;
cur = parent;
}
return 0;
}
void x11_close() {
if (!g_display) return;
if (g_use_shm) {
+40
View File
@@ -0,0 +1,40 @@
#!/bin/sh
# Virtual desktop for a monitorless Linux host: Xvfb + a desktop session on its own D-Bus session bus.
# uuremote-server then serves it with DISPLAY=$UU_VIRTUAL_DISPLAY (see README in this folder).
# UU_VIRTUAL_DISPLAY X display number (default :99)
# UU_VIRTUAL_SIZE screen size (default 1920x1080)
# UU_VIRTUAL_SESSION session command (default: first of startxfce4, mate-session, startlxqt, openbox-session, xterm)
# UU_VIRTUAL_BUS user (default): the systemd user bus (`loginctl enable-linger`) gets DISPLAY, so
# D-Bus/systemd-activated apps (GNOME terminal, portals, ...) open on the virtual screen;
# private: own dbus-run-session bus, for machines that also run a real desktop session
set -eu
display="${UU_VIRTUAL_DISPLAY:-:99}"
size="${UU_VIRTUAL_SIZE:-1920x1080}"
session="${UU_VIRTUAL_SESSION:-}"
if [ -z "$session" ]; then
for candidate in startxfce4 mate-session startlxqt openbox-session xterm; do
if command -v "$candidate" >/dev/null 2>&1; then session="$candidate"; break; fi
done
fi
[ -n "$session" ] || { echo "no desktop session found; set UU_VIRTUAL_SESSION" >&2; exit 1; }
command -v Xvfb >/dev/null || { echo "Xvfb not installed (apt install xvfb)" >&2; exit 1; }
command -v dbus-run-session >/dev/null || { echo "dbus-run-session not installed (apt install dbus)" >&2; exit 1; }
Xvfb "$display" -screen 0 "${size}x24" -nolisten tcp -noreset &
xvfb=$!
trap 'kill "$xvfb" 2>/dev/null' EXIT INT TERM
socket="/tmp/.X11-unix/X${display#:}"
for _ in $(seq 50); do [ -S "$socket" ] && break; sleep 0.1; done
[ -S "$socket" ] || { echo "Xvfb did not start on $display" >&2; exit 1; }
export DISPLAY="$display"
unset WAYLAND_DISPLAY XAUTHORITY
export XDG_SESSION_TYPE=x11
if [ "${UU_VIRTUAL_BUS:-user}" = user ]; then
# Activated services inherit the user manager's environment, not this process's: export DISPLAY there.
dbus-update-activation-environment --systemd DISPLAY XDG_SESSION_TYPE
exec sh -c "$session"
else
# Private bus: independent of the user manager; activation through systemd may still escape to the user bus.
dbus-run-session -- sh -c "$session"
fi
@@ -0,0 +1,14 @@
[Unit]
Description=Virtual X desktop for uu-remote-linux (Xvfb + session bus)
After=dbus.socket
[Service]
# Environment=UU_VIRTUAL_SESSION=startxfce4
# Environment=UU_VIRTUAL_SIZE=1920x1080
# Environment=UU_VIRTUAL_BUS=private
ExecStart=%h/.local/bin/uu-virtual-desktop
Restart=always
RestartSec=5
[Install]
WantedBy=default.target
@@ -0,0 +1,10 @@
# ~/.config/systemd/user/uuremote-native.service.d/virtual-display.conf
# Serve the virtual desktop instead of a physical display.
[Unit]
Requires=uu-virtual-desktop.service
After=uu-virtual-desktop.service
[Service]
Environment=DISPLAY=:99
Environment=UU_DESKTOP_BACKEND=x11
UnsetEnvironment=XAUTHORITY WAYLAND_DISPLAY
+22
View File
@@ -0,0 +1,22 @@
修复长时间远控约 20 分钟后被断开的问题。/ Fixes sessions being dropped after ~20 minutes.
### 修复 / Fixed
- **远控约 20 分钟后被云端断开**:官方客户端会定期(约每 5 分钟)通过信令刷新房间的重连凭证(`refresh_reconnect_key`),
之前没有实现,云端大约 20 分钟后就会回收房间并断开连接。现在被控端会按官方节奏刷新;凭证只保存在内存中,不写日志。
在测试虚拟机里长连接稳定运行 44 分钟以上(已越过原来的断开点),在 X11 实机上确认刷新被云端接受。
Sessions were released by the cloud after ~20 minutes because the room's reconnect key was never refreshed. The host now
refreshes it like the official clients (~every 5 minutes); the key stays in memory and is never logged.
- 旧的信令连接在重连后会被正确关闭。/ Stale signaling connections are closed after a reconnect.
### 其他 / Other
- 可选的进程内编码路径支持 XDamage:桌面静止时几乎不占 CPU 和带宽(`--features inproc-av`,默认关闭)(#7,感谢 @ferstar)。
XDamage capture on the opt-in in-process path (#7, thanks @ferstar).
- Wayland(portal)下双向剪贴板已在虚拟机中验收通过。注意:官方 Mac 客户端只在远控窗口处于前台(获得焦点)时接收被控端的剪贴板。
Two-way clipboard on the portal backend passes in the VM; the official Mac viewer only accepts the host clipboard while the
remote window has focus.
- 更多信令诊断日志(不含任何凭证)。/ More signaling diagnostics (no credentials).
### 下载 / Download
`uu-remote-linux-v0.1.5-x86_64-linux.tar.gz`:X11 版可执行文件(x86_64,glibc ≥ 2.35)。
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
+28
View File
@@ -0,0 +1,28 @@
无头服务器、虚拟桌面、uinput 输入和终端快捷键。/ Headless servers, virtual desktop, uinput input and terminal shortcuts.
### 新增 / Added
- **无头模式** `UU_DESKTOP_BACKEND=none`:没有显示器、没有图形会话也能上线,提供终端、文件传输和端口映射。
配合 `loginctl enable-linger` 可以开机自动上线。已在实机上用官方 Mac 客户端验收(端口映射传输 10 MB 校验一致)。
Headless mode: online without a display; terminal, file transfer and port mapping verified with the official Mac viewer.
- **虚拟桌面** `contrib/virtual-desktop/`:用 Xvfb 创建虚拟屏幕并启动桌面会话,没有显示器的服务器也能使用完整的远程桌面。
实机验收了画面和键鼠;默认的「用户总线」模式(把 `DISPLAY` 导入 systemd 用户会话)尚未在纯无头机器上验证。
Virtual desktop scripts (Xvfb + session). Video and input verified; the default user-bus mode is not yet verified on a
truly monitorless machine.
- **uinput 虚拟键鼠**(参考 Sunshine):Wayland/portal 下,只要当前用户能访问 `/dev/uinput`(README 里有一条 udev 规则),
就自动改用内核级虚拟键盘和鼠标,发送物理按键码,不依赖键盘布局,也不需要 portal 输入授权。应能解决 #3(下划线被吞)。
`UU_INPUT_BACKEND=auto|uinput|native`;X11 继续默认用 XTest。
uinput keyboard/mouse on Wayland (layout independent, no portal input consent); should fix #3.
- **终端快捷键**:Mac 控制端的 Cmd 和 Ctrl 到被控端都是 Ctrl。焦点在终端窗口时,Ctrl+V / Cmd+V 自动转成 Ctrl+Shift+V 粘贴;
Ctrl+C 始终是中断,复制用 Cmd+Shift+C(X11,`UU_TERMINAL_SHORTCUTS=0` 关闭)。
Terminal-aware paste: Ctrl+V/Cmd+V paste in terminal windows, Ctrl+C always interrupts.
### 修复 / Fixed
- 没有桌面时(无头模式,或 portal 后端还没授权时)打开端口映射会被控制端立即断开:现在工具连接会收到屏幕信息和「允许」权限。
Port mapping was aborted by the viewer when no desktop was available.
- 明确设置的 `DISPLAY` 打不开时,不再悄悄改用 `:0`/`:1`(会截到真实屏幕),而是报错。
An explicit DISPLAY that cannot be opened no longer falls back to the physical screen.
### 下载 / Download
`uu-remote-linux-v0.1.6-x86_64-linux.tar.gz`:X11 版可执行文件(x86_64,glibc ≥ 2.35),附带 `contrib/virtual-desktop/`。
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
+124
View File
@@ -0,0 +1,124 @@
//! Damage-driven X11 capture for the in-process encoder: XDamage reports when the root window changed,
//! XShm copies it out as 32-bit BGRX. Pure Rust over x11rb; only the SysV shared-memory calls use libc.
use std::os::unix::io::AsRawFd;
use std::time::{Duration, Instant};
use x11rb::connection::{Connection, RequestConnection};
use x11rb::protocol::damage::{self, ConnectionExt as _, ReportLevel};
use x11rb::protocol::shm::{self, ConnectionExt as _};
use x11rb::protocol::xproto::Window;
use x11rb::rust_connection::RustConnection;
use x11rb::NONE;
/// X11 ZPixmap image format.
const Z_PIXMAP: u8 = 2;
pub struct DamageCapture {
conn: RustConnection,
root: Window,
damage: damage::Damage,
damage_event: u8,
width: u16,
height: u16,
seg: shm::Seg,
shm_ptr: *mut u8,
len: usize,
}
fn text(error: impl std::fmt::Display) -> String { error.to_string() }
impl DamageCapture {
/// Connects to `display` and sets up XDamage and XShm. Errors name the missing extension or failed step.
pub fn open(display: &str) -> Result<Self, String> {
let (conn, screen_num) = RustConnection::connect(Some(display)).map_err(text)?;
let damage_info = conn.extension_information(damage::X11_EXTENSION_NAME).map_err(text)?
.ok_or("XDamage extension is missing")?;
if conn.extension_information(shm::X11_EXTENSION_NAME).map_err(text)?.is_none() {
return Err("XShm extension is missing".into());
}
conn.damage_query_version(1, 1).map_err(text)?.reply().map_err(text)?;
let setup = conn.setup();
let screen = setup.roots.get(screen_num).ok_or("X screen not found")?;
let (root, width, height, depth) = (screen.root, screen.width_in_pixels, screen.height_in_pixels, screen.root_depth);
// The frame layout assumes packed 32-bit pixels; anything else would shear the picture.
let format = setup.pixmap_formats.iter().find(|f| f.depth == depth).ok_or("no pixmap format for the root depth")?;
if format.bits_per_pixel != 32 { return Err(format!("root depth {depth} is not 32 bits per pixel")); }
let len = width as usize * height as usize * 4;
// NonEmpty: one event each time the root goes from clean to damaged; re-armed in `wait`.
let damage = conn.generate_id().map_err(text)?;
conn.damage_create(damage, root, ReportLevel::NON_EMPTY).map_err(text)?.check().map_err(text)?;
// Nothing below can fail without also releasing the local mapping, so every error path is covered here.
let seg = conn.generate_id().map_err(text)?;
let shmid = unsafe { libc::shmget(libc::IPC_PRIVATE, len, libc::IPC_CREAT | 0o600) };
if shmid < 0 { return Err("shmget failed".into()); }
let shm_ptr = unsafe { libc::shmat(shmid, std::ptr::null(), 0) } as *mut u8;
if shm_ptr as isize == -1 {
unsafe { libc::shmctl(shmid, libc::IPC_RMID, std::ptr::null_mut()) };
return Err("shmat failed".into());
}
let attach = conn.shm_attach(seg, shmid as u32, false).map_err(text).and_then(|c| c.check().map_err(text));
// Marked for removal either way; the kernel frees it after the last detach.
unsafe { libc::shmctl(shmid, libc::IPC_RMID, std::ptr::null_mut()) };
if let Err(error) = attach {
unsafe { libc::shmdt(shm_ptr as *const libc::c_void) };
return Err(error);
}
Ok(Self { conn, root, damage, damage_event: damage_info.first_event, width, height, seg, shm_ptr, len })
}
pub fn size(&self) -> (u32, u32) { (self.width as u32, self.height as u32) }
/// Waits up to `timeout` for the screen to change. Returns `true` on change, `false` on timeout.
pub fn wait(&mut self, timeout: Duration) -> Result<bool, String> {
let deadline = Instant::now() + timeout;
loop {
let mut changed = false;
while let Some(event) = self.conn.poll_for_raw_event().map_err(text)? {
// XDamageNotify is the extension's first event; the wire code keeps the high bit for synthetic events.
if event[0] & 0x7f == self.damage_event { changed = true; }
}
if changed {
self.conn.damage_subtract(self.damage, NONE, NONE).map_err(text)?;
self.conn.flush().map_err(text)?;
return Ok(true);
}
let remaining = deadline.saturating_duration_since(Instant::now());
if remaining.is_zero() { return Ok(false); }
let mut pfd = libc::pollfd { fd: self.conn.stream().as_raw_fd(), events: libc::POLLIN, revents: 0 };
match unsafe { libc::poll(&mut pfd, 1, remaining.as_millis().max(1) as i32) } {
ready if ready < 0 => return Err("poll on the X connection failed".into()),
// Readable but not yet a whole event: poll_for_raw_event would return None and poll would
// fire again at once, spinning a core. Block for the event instead.
ready if ready > 0 => {
let event = self.conn.wait_for_raw_event().map_err(text)?;
if event[0] & 0x7f == self.damage_event { changed = true; }
if changed {
self.conn.damage_subtract(self.damage, NONE, NONE).map_err(text)?;
self.conn.flush().map_err(text)?;
return Ok(true);
}
}
_ => {}
}
}
}
/// Copies the root into the shared segment and returns it as rows of `width * 4` bytes.
/// The slice is valid until the next call.
pub fn capture(&mut self) -> Result<&[u8], String> {
self.conn.shm_get_image(self.root, 0, 0, self.width, self.height, !0, Z_PIXMAP, self.seg, 0)
.map_err(text)?.reply().map_err(text)?;
Ok(unsafe { std::slice::from_raw_parts(self.shm_ptr, self.len) })
}
}
impl Drop for DamageCapture {
fn drop(&mut self) {
let _ = self.conn.damage_destroy(self.damage);
let _ = self.conn.shm_detach(self.seg);
let _ = self.conn.flush();
unsafe { libc::shmdt(self.shm_ptr as *const libc::c_void) };
}
}
+6 -1
View File
@@ -2,6 +2,10 @@
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum DesktopBackend { X11, Wayland, Portal }
/// `UU_DESKTOP_BACKEND=none`: headless host — no display is opened; terminal, file transfer and
/// port mapping stay available (servers without a monitor or logged-in session).
pub fn headless() -> bool { std::env::var("UU_DESKTOP_BACKEND").is_ok_and(|v| v == "none") }
pub fn detect() -> Result<DesktopBackend, String> {
let backend=select(std::env::var("UU_DESKTOP_BACKEND").ok().as_deref(),
std::env::var("XDG_SESSION_TYPE").ok().as_deref(),
@@ -16,12 +20,13 @@ fn select(explicit: Option<&str>, session: Option<&str>, socket: Option<&str>) -
Some("x11") => Ok(DesktopBackend::X11),
Some("wayland") => Ok(DesktopBackend::Wayland),
Some("portal") => Ok(DesktopBackend::Portal),
Some("none") => Ok(DesktopBackend::X11), // never opened, see headless()
None | Some("auto") => {
if session == Some("wayland") || socket.is_some_and(|s| !s.is_empty()) {
Ok(DesktopBackend::Wayland)
} else { Ok(DesktopBackend::X11) }
},
Some(_) => Err("UU_DESKTOP_BACKEND must be auto, x11, wayland or portal".into()),
Some(_) => Err("UU_DESKTOP_BACKEND must be auto, x11, wayland, portal or none".into()),
}
}
+116 -19
View File
@@ -12,6 +12,8 @@ use ff::util::picture;
use ff::{codec, encoder, frame, software::scaling, Dictionary, Packet, Rational};
use tokio::sync::mpsc;
use crate::damage_capture::DamageCapture;
pub struct Config {
pub display: String,
pub input: (u32, u32),
@@ -23,6 +25,8 @@ pub struct Config {
pub max_bps: i64,
pub buffer_bits: i64,
pub gpu: bool,
/// Capture on XDamage changes (XShm) instead of x11grab; `UU_CAPTURE=grab` turns it off.
pub damage: bool,
}
/// `UU_VIDEO_PIPELINE=process` keeps the original ffmpeg child-process path.
@@ -30,6 +34,11 @@ pub fn disabled() -> bool {
std::env::var("UU_VIDEO_PIPELINE").is_ok_and(|v| v == "process")
}
/// Damage-driven capture is on unless `UU_CAPTURE=grab` asks for x11grab.
pub fn damage_enabled() -> bool {
std::env::var("UU_CAPTURE").map_or(true, |v| v != "grab")
}
/// In-process capture is used unless the process path is requested, or a bundled FFmpeg prefix
/// (`UU_FFMPEG_ROOT` / config `ffmpeg_root`) is set: that build was chosen on purpose, so keep using it.
pub fn selected() -> bool {
@@ -62,24 +71,8 @@ fn drain(encoder: &mut encoder::Video, packet: &mut Packet, units: &mpsc::Sender
}
}
/// Runs until `stop` is set or the receiver is dropped. A set `idr` flag forces the next frame to be an IDR.
pub fn run(config: Config, units: mpsc::Sender<Vec<u8>>, stop: Arc<AtomicBool>, idr: Arc<AtomicBool>) -> Result<(), String> {
ensure_init()?;
let name = CString::new("x11grab").map_err(|e| e.to_string())?;
let raw = unsafe { ff::sys::av_find_input_format(name.as_ptr()) };
if raw.is_null() { return Err("x11grab input is not available in this FFmpeg build".into()); }
let input_format = Format::Input(unsafe { ff::format::format::Input::wrap(raw as *mut _) });
let mut capture_options = Dictionary::new();
capture_options.set("framerate", &config.fps.to_string());
capture_options.set("video_size", &format!("{}x{}", config.input.0, config.input.1));
// The viewer draws its own pointer; do not bake a second one into the video.
capture_options.set("draw_mouse", "0");
let mut input = ff::format::open_with(&config.display, &input_format, capture_options).map_err(text)?.input();
let stream = input.streams().best(ff::media::Type::Video).ok_or("X11 capture has no video stream")?;
let index = stream.index();
let mut decoder = codec::context::Context::from_parameters(stream.parameters()).map_err(text)?.decoder().video().map_err(text)?;
/// Opens the H.264 encoder for `config`. Returns the encoder, its input pixel format and output size.
fn open_encoder(config: &Config) -> Result<(encoder::Video, Pixel, u32, u32), String> {
let (width, height) = config.output.unwrap_or(config.input);
let codec = encoder::find_by_name(if config.gpu { "h264_nvenc" } else { "libx264" })
.ok_or("H.264 encoder is not available in this FFmpeg build")?;
@@ -119,7 +112,35 @@ pub fn run(config: Config, units: mpsc::Sender<Vec<u8>>, stop: Arc<AtomicBool>,
options.set("crf", &cq);
options.set("x264-params", &x264);
}
let mut encoder = context.open_as_with(codec, options).map_err(text)?;
let encoder = context.open_as_with(codec, options).map_err(text)?;
Ok((encoder, pixel, width, height))
}
/// Runs until `stop` is set or the receiver is dropped. A set `idr` flag forces the next frame to be an IDR.
pub fn run(config: Config, units: mpsc::Sender<Vec<u8>>, stop: Arc<AtomicBool>, idr: Arc<AtomicBool>) -> Result<(), String> {
ensure_init()?;
if config.damage {
match DamageCapture::open(&config.display) {
Ok(capture) => return run_damage(config, capture, units, stop, idr),
Err(error) => log::warn!("Damage-driven capture unavailable, using x11grab: {error}"),
}
}
let name = CString::new("x11grab").map_err(|e| e.to_string())?;
let raw = unsafe { ff::sys::av_find_input_format(name.as_ptr()) };
if raw.is_null() { return Err("x11grab input is not available in this FFmpeg build".into()); }
let input_format = Format::Input(unsafe { ff::format::format::Input::wrap(raw as *mut _) });
let mut capture_options = Dictionary::new();
capture_options.set("framerate", &config.fps.to_string());
capture_options.set("video_size", &format!("{}x{}", config.input.0, config.input.1));
// The viewer draws its own pointer; do not bake a second one into the video.
capture_options.set("draw_mouse", "0");
let mut input = ff::format::open_with(&config.display, &input_format, capture_options).map_err(text)?.input();
let stream = input.streams().best(ff::media::Type::Video).ok_or("X11 capture has no video stream")?;
let index = stream.index();
let mut decoder = codec::context::Context::from_parameters(stream.parameters()).map_err(text)?.decoder().video().map_err(text)?;
let (mut encoder, pixel, width, height) = open_encoder(&config)?;
let mut scaler: Option<(scaling::Context, (Pixel, u32, u32))> = None;
let mut decoded = frame::Video::empty();
@@ -169,6 +190,82 @@ pub fn run(config: Config, units: mpsc::Sender<Vec<u8>>, stop: Arc<AtomicBool>,
Ok(())
}
/// Damage-driven loop. Damage only marks the picture dirty; a dirty picture is captured and encoded on
/// the next fixed frame tick, so the stream keeps a steady cadence while the screen moves. The viewer's
/// jitter buffer grows with irregular arrivals, and irregular sends were what raised its latency.
/// An idle screen sends a keepalive about once a second so the viewer still sees traffic.
fn run_damage(config: Config, mut capture: DamageCapture, units: mpsc::Sender<Vec<u8>>, stop: Arc<AtomicBool>, idr: Arc<AtomicBool>) -> Result<(), String> {
let (mut encoder, pixel, width, height) = open_encoder(&config)?;
let (cap_width, cap_height) = capture.size();
let mut captured = frame::Video::new(Pixel::BGRZ, cap_width, cap_height);
let mut converted = frame::Video::new(pixel, width, height);
let mut scaler = None;
let mut packet = Packet::empty();
let started = Instant::now();
let frame_interval = Duration::from_nanos(1_000_000_000 / u64::from(config.fps));
// Keepalive gaps are random between 15 and 25 fps: a steady 1 fps reads as a stall to the viewer.
let mut seed = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map_or(1, |d| d.subsec_nanos()) | 1;
let mut keepalive = random_keepalive(&mut seed);
let mut dirty = true;
let mut next_tick = Instant::now();
let mut last_send = Instant::now();
let mut last_slot: i64 = -1;
loop {
if stop.load(Ordering::Relaxed) { return Ok(()); }
let deadline = if dirty { next_tick } else { last_send + keepalive };
let wait = deadline.saturating_duration_since(Instant::now());
// A change marks the picture dirty and falls through, so a client that damages the root constantly
// cannot keep an overdue tick waiting.
if capture.wait(wait.max(Duration::from_millis(1)))? { dirty = true; }
let now = Instant::now();
if dirty && now < next_tick { continue; }
if !dirty && now < last_send + keepalive { continue; }
let source = capture.capture()?;
let bytes_per_line = cap_width as usize * 4;
let stride = captured.stride(0);
let row = bytes_per_line.min(stride);
for (y, src) in source.chunks_exact(bytes_per_line).enumerate() {
captured.data_mut(0)[y * stride..y * stride + row].copy_from_slice(&src[..row]);
}
let slot = ((started.elapsed().as_micros() * u128::from(config.fps) + 500_000) / 1_000_000) as i64;
let slot = slot.max(last_slot + 1);
last_slot = slot;
let frame = if pixel == Pixel::BGRZ && width == cap_width && height == cap_height {
&mut captured
} else {
if scaler.is_none() {
scaler = Some(scaling::Context::get(Pixel::BGRZ, cap_width, cap_height, pixel, width, height, scaling::Flags::BILINEAR).map_err(text)?);
}
if let Some(context) = scaler.as_mut() { context.run(&captured, &mut converted).map_err(text)?; }
&mut converted
};
frame.set_pts(Some(slot));
frame.set_kind(if idr.swap(false, Ordering::AcqRel) { picture::Type::I } else { picture::Type::None });
encoder.send_frame(frame).map_err(text)?;
if !drain(&mut encoder, &mut packet, &units)? { return Ok(()); }
let now = Instant::now();
if dirty {
// Keep the tick phase; after a long idle, restart the phase from now instead of bursting to catch up.
let next = next_tick + frame_interval;
next_tick = if next > now { next } else { now + frame_interval };
dirty = false;
}
last_send = now;
keepalive = random_keepalive(&mut seed);
}
}
/// Picks the next keepalive gap in 40–67 ms (15–25 fps) with a small xorshift generator.
fn random_keepalive(seed: &mut u32) -> Duration {
*seed ^= *seed << 13;
*seed ^= *seed >> 17;
*seed ^= *seed << 5;
Duration::from_micros(40_000 + u64::from(*seed % 26_700))
}
/// Encodes a PulseAudio/PipeWire source to Opus in this process. Each Opus packet is sent as is.
pub fn run_audio(source: &str, units: mpsc::Sender<bytes::Bytes>, stop: Arc<AtomicBool>) -> Result<(), String> {
ensure_init()?;
+105 -2
View File
@@ -8,7 +8,10 @@ extern "C" {
fn x11_pointer_state(x:*mut libc::c_int,y:*mut libc::c_int,mask:*mut libc::c_uint)->libc::c_int;
fn x11_key_symbol(symbol: libc::c_ulong, is_press: libc::c_int) -> libc::c_int;
fn x11_key_event(keycode: libc::c_int, is_press: libc::c_int) -> libc::c_int;
fn x11_terminal_shortcut_state() -> libc::c_int;
}
#[cfg(not(target_os = "linux"))]
unsafe fn x11_terminal_shortcut_state() -> libc::c_int { 0 }
#[cfg(not(target_os = "linux"))]
unsafe fn x11_mouse_move(_: libc::c_int, _: libc::c_int) -> libc::c_int { 0 }
@@ -33,11 +36,22 @@ struct PendingPointer {
unsafe fn x11_pointer_state(_: *mut libc::c_int,_:*mut libc::c_int,_:*mut libc::c_uint)->libc::c_int {-1}
#[derive(Default)]
struct HeldInput { buttons: std::collections::BTreeSet<i32>, keys: std::collections::BTreeSet<u64> }
pub struct InputInjector { portal_failures: std::sync::atomic::AtomicUsize, portal_outcomes: [std::sync::atomic::AtomicUsize; 3], portal:std::sync::Mutex<Option<std::sync::Arc<crate::portal::PortalSession>>>, backend: crate::desktop_backend::DesktopBackend, pending: std::sync::Mutex<PendingPointer>, held: std::sync::Mutex<HeldInput> }
/// Held modifier VKs (bit 0 Ctrl, 1 Shift, 2 Alt, 3 Win) and keys that got a synthetic Shift.
#[derive(Default)]
struct Shortcuts { modifiers: u8, shifted: std::collections::BTreeSet<i32> }
pub struct InputInjector { shortcuts: std::sync::Mutex<Shortcuts>, uinput: Option<crate::uinput::Devices>, screen: std::sync::Mutex<(u32,u32)>, portal_failures: std::sync::atomic::AtomicUsize, portal_outcomes: [std::sync::atomic::AtomicUsize; 3], portal:std::sync::Mutex<Option<std::sync::Arc<crate::portal::PortalSession>>>, backend: crate::desktop_backend::DesktopBackend, pending: std::sync::Mutex<PendingPointer>, held: std::sync::Mutex<HeldInput> }
impl InputInjector {
pub fn new() -> Self {
Self { portal_failures: std::sync::atomic::AtomicUsize::new(0), portal_outcomes: std::array::from_fn(|_| std::sync::atomic::AtomicUsize::new(0)), portal:std::sync::Mutex::new(None), backend:crate::desktop_backend::detect().unwrap_or(crate::desktop_backend::DesktopBackend::X11), pending: std::sync::Mutex::new(PendingPointer::default()), held:std::sync::Mutex::new(HeldInput::default()) }
let backend = crate::desktop_backend::detect().unwrap_or(crate::desktop_backend::DesktopBackend::X11);
let uinput = if crate::uinput::wanted(backend) {
match crate::uinput::Devices::open() {
Ok(devices) => { log::info!("Input backend: uinput (kernel virtual keyboard/pointer)"); Some(devices) }
Err(e) => { log::warn!("uinput unavailable ({}); using the desktop input path. See README for the udev rule.", e.kind()); None }
}
} else { None };
Self { shortcuts: std::sync::Mutex::new(Shortcuts::default()), uinput, screen: std::sync::Mutex::new((0,0)), portal_failures: std::sync::atomic::AtomicUsize::new(0), portal_outcomes: std::array::from_fn(|_| std::sync::atomic::AtomicUsize::new(0)), portal:std::sync::Mutex::new(None), backend:crate::desktop_backend::detect().unwrap_or(crate::desktop_backend::DesktopBackend::X11), pending: std::sync::Mutex::new(PendingPointer::default()), held:std::sync::Mutex::new(HeldInput::default()) }
}
pub fn bind_portal(&self,session:Option<std::sync::Arc<crate::portal::PortalSession>>) {
@@ -49,6 +63,7 @@ impl InputInjector {
}
pub fn mouse_absolute_normalized(&self, x: f64, y: f64, size: (u32,u32)) {
*self.screen.lock().unwrap() = size;
if let Some(position) = crate::input_mapping::normalized_pointer(x,y,size.0,size.1) {
let mut pending = self.pending.lock().unwrap();
pending.absolute = Some(position);
@@ -117,7 +132,47 @@ impl InputInjector {
}
}
/// Mac viewers send Cmd+V as Ctrl+V (verified: Cmd and Ctrl both arrive as VK_LCONTROL), which in
/// a Linux terminal quotes the next key instead of pasting. In a focused terminal Ctrl+V becomes
/// Ctrl+Shift+V. Ctrl+C is never translated: it must always interrupt, and copy is Cmd+Shift+C
/// (= Ctrl+Shift+C). X11 only; `UU_TERMINAL_SHORTCUTS=0` disables.
fn terminal_shift(&self, key: i32, is_press: bool) -> bool {
let bit = match key { 0x11 | 0xa2 | 0xa3 => 1, 0x10 | 0xa0 | 0xa1 => 2, 0x12 | 0xa4 | 0xa5 => 4, 0x5b | 0x5c => 8, _ => 0 };
let mut shortcuts = self.shortcuts.lock().unwrap();
if bit != 0 {
if is_press { shortcuts.modifiers |= bit } else { shortcuts.modifiers &= !bit }
return false;
}
if !is_press { return shortcuts.shifted.remove(&key); }
if key != 0x56 || shortcuts.modifiers != 1 { return false; }
if std::env::var("UU_TERMINAL_SHORTCUTS").is_ok_and(|v| v == "0") || std::env::var_os("DISPLAY").is_none() { return false; }
let shift = unsafe { x11_terminal_shortcut_state() } & 1 != 0;
if shift {
shortcuts.shifted.insert(key);
static NOTED: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
if NOTED.fetch_add(1, std::sync::atomic::Ordering::Relaxed) < 4 {
log::info!("Terminal shortcut: Ctrl+V sent as Ctrl+Shift+V");
}
}
shift
}
pub fn windows_key_event(&self, key: i32, is_press: bool) {
if self.terminal_shift(key, is_press) {
const SHIFT_L: u64 = 0xffe1;
if is_press {
self.inject_key(SHIFT_L, true);
self.key_symbol_event(key, true);
} else {
self.key_symbol_event(key, false);
self.inject_key(SHIFT_L, false);
}
return;
}
self.key_symbol_event(key, is_press);
}
fn key_symbol_event(&self, key: i32, is_press: bool) {
if let Some(symbol) = crate::input_mapping::windows_vk_to_keysym(key) {
let result = self.inject_key(symbol,is_press);
static AUDIT: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
@@ -158,19 +213,44 @@ impl InputInjector {
}
}
}
fn uinput_result(result: std::io::Result<()>) -> i32 {
match result {
Ok(()) => 0,
Err(e) => {
static FAILURES: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
if FAILURES.fetch_add(1, std::sync::atomic::Ordering::Relaxed) < 8 { log::warn!("uinput injection failed: {}", e.kind()); }
-1
}
}
}
fn inject_move(&self,x:i32,y:i32,relative:bool)->i32 {
if let Some(uinput)=&self.uinput {
if relative { return Self::uinput_result(uinput.move_relative(x,y)); }
let (w,h)=*self.screen.lock().unwrap();
if w > 1 && h > 1 {
let scale = |v: i32, extent: u32| (i64::from(v) * i64::from(crate::uinput::ABS_MAX) / i64::from(extent - 1)) as i32;
return Self::uinput_result(uinput.move_absolute(scale(x,w),scale(y,h)));
}
}
if let Some(portal)=self.portal.lock().unwrap().as_ref() { return self.portal_result("motion", portal.move_pointer(f64::from(x),f64::from(y),relative)); }
if self.backend==crate::desktop_backend::DesktopBackend::Portal {return self.portal_result("motion", Err("Portal input session is not bound".into()));}
if self.backend==crate::desktop_backend::DesktopBackend::Wayland { crate::wayland::move_pointer(x,y,relative) }
else if relative { unsafe { x11_mouse_relative(x,y) } } else { unsafe { x11_mouse_move(x,y) } }
}
fn inject_button(&self,button:i32,pressed:bool)->i32 {
if let Some(uinput)=&self.uinput {
if let Some((v,h))=crate::uinput::wheel_step(button) { return if pressed { Self::uinput_result(uinput.wheel(v,h)) } else { 0 }; }
if let Some(code)=crate::uinput::button_code(button) { return Self::uinput_result(uinput.button(code,pressed)); }
}
if let Some(portal)=self.portal.lock().unwrap().as_ref() { return self.portal_result("button", portal.button(button,pressed)); }
if self.backend==crate::desktop_backend::DesktopBackend::Portal {return self.portal_result("button", Err("Portal input session is not bound".into()));}
if self.backend==crate::desktop_backend::DesktopBackend::Wayland { crate::wayland::button(button,pressed) }
else { unsafe { x11_mouse_button(button,i32::from(pressed)) } }
}
fn inject_key(&self,symbol:u64,pressed:bool)->i32 {
if let Some(uinput)=&self.uinput {
if let Some(code)=crate::uinput::keysym_to_evdev(symbol) { return Self::uinput_result(uinput.key(code,pressed)); }
}
if let Some(portal)=self.portal.lock().unwrap().as_ref() { return self.portal_result("keyboard", portal.key(symbol,pressed)); }
if self.backend==crate::desktop_backend::DesktopBackend::Portal {return self.portal_result("keyboard", Err("Portal input session is not bound".into()));}
if self.backend==crate::desktop_backend::DesktopBackend::Wayland { crate::wayland::key(symbol,pressed) }
@@ -213,6 +293,29 @@ mod motion_tests {
}
}
#[cfg(test)]
mod shortcut_tests {
use super::*;
#[test]
fn modifiers_are_tracked_and_non_terminal_keys_pass_through() {
let input = InputInjector::new();
assert!(!input.terminal_shift(0x11, true));
assert_eq!(input.shortcuts.lock().unwrap().modifiers, 1);
// No X display in tests: Ctrl+V is not translated.
assert!(!input.terminal_shift(0x56, true));
assert!(!input.terminal_shift(0x56, false));
assert!(!input.terminal_shift(0x11, false));
assert_eq!(input.shortcuts.lock().unwrap().modifiers, 0);
// A translated key keeps its synthetic Shift until its own release.
input.shortcuts.lock().unwrap().shifted.insert(0x56);
assert!(input.terminal_shift(0x56, false));
assert!(!input.terminal_shift(0x56, false));
// Ctrl+C is never translated.
input.terminal_shift(0x11, true);
assert!(!input.terminal_shift(0x43, true));
}
}
#[cfg(test)]
mod scroll_tests {
use super::*;
+10 -1
View File
@@ -14,6 +14,7 @@ mod session_lock;
mod capture;
mod file_trans;
mod input;
mod uinput;
mod input_mapping;
mod port_mapping;
mod power;
@@ -22,6 +23,8 @@ mod terminal;
mod webrtc;
mod video;
#[cfg(feature = "inproc-av")]
mod damage_capture;
#[cfg(feature = "inproc-av")]
mod inproc_encoder;
mod capture_setting;
mod audio;
@@ -202,7 +205,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
log::info!("Starting uu-remote-linux host v{}...", env!("CARGO_PKG_VERSION"));
let mut capture = Arc::new((if desktop_backend::detect()?==desktop_backend::DesktopBackend::Portal
let mut capture = Arc::new((if desktop_backend::headless() {
Err("headless mode (UU_DESKTOP_BACKEND=none)".to_owned())
} else if desktop_backend::detect()?==desktop_backend::DesktopBackend::Portal
&& std::env::var("UU_PORTAL_PREAUTHORIZE").ok().as_deref()!=Some("1") {
Err("Portal screen access requires a desktop connection and local consent".to_owned())
} else { ScreenCapture::new() }).unwrap_or_else(|error| {
@@ -356,6 +361,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
let stale_portal=capture.portal.as_ref().is_some_and(|session|!session.is_alive())
&& crate::session_lock::locked_now() == Some(false);
if desktop && desktop_backend::headless() {
log::info!("Desktop connection ignored: headless mode (terminal, file transfer and port mapping remain available)");
continue;
}
let session_capture=if desktop && (capture.init_error.is_some() || stale_portal) {
if stale_portal {
input.release_held();input.bind_portal(None);
+122 -8
View File
@@ -47,6 +47,51 @@ pub enum SignalingEvent {
pub struct SignalingClient {
tx_outgoing: mpsc::Sender<String>,
// Belongs to this room only; fresh-room reconnect must not reuse it.
_reconnect_key: Arc<std::sync::Mutex<Option<String>>>,
}
fn refreshed_key(ack:&Value)->Option<String> {
let values=ack.as_array()?;
if values.first()?.as_str()? != "success" { return None; }
let key=values.get(1)?.get("reconnect_key")?.as_str()?;
(!key.is_empty() && key.len()<=16384).then(||key.to_owned())
}
#[cfg(test)]
mod refresh_tests {
use super::refreshed_key;
use serde_json::json;
#[test]
fn accepts_only_successful_complete_reconnect_key_ack() {
assert_eq!(refreshed_key(&json!(["success",{"reconnect_key":"synthetic-key"}])),Some("synthetic-key".into()));
for ack in [json!(["failure",{"reconnect_key":"synthetic-key"}]),json!(["success"]),json!(["success",{"reconnect_key":""}]),json!(["success",{"reconnect_key":123}]),json!({"reconnect_key":"synthetic-key"})] {
assert!(refreshed_key(&ack).is_none());
}
}
#[tokio::test]
async fn closes_obsolete_socket_even_if_peer_retains_client() {
use futures_util::{SinkExt,StreamExt};
use tokio_tungstenite::tungstenite::Message;
let listener=tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let address=listener.local_addr().unwrap();
let server=tokio::spawn(async move {
let (tcp,_)=listener.accept().await.unwrap();
let mut socket=tokio_tungstenite::accept_async(tcp).await.unwrap();
socket.send(Message::Text("0{}".into())).await.unwrap();
assert_eq!(socket.next().await.unwrap().unwrap(),Message::Text("40".into()));
socket.send(Message::Text("40{}".into())).await.unwrap();
assert!(socket.next().await.unwrap().unwrap().into_text().unwrap().contains("room_info"));
matches!(socket.next().await,None|Some(Err(_))|Some(Ok(Message::Close(_))))
});
let (sender,mut events)=tokio::sync::mpsc::channel(4);
let retained=super::SignalingClient::connect(&format!("ws://{address}"),"synthetic-only",sender).await.unwrap();
assert!(matches!(events.recv().await,Some(super::SignalingEvent::Connected)));
drop(events);
assert!(tokio::time::timeout(std::time::Duration::from_secs(2),server).await.unwrap().unwrap());
// Retain it until after the server sees closure, just like PC callbacks.
drop(retained);
}
}
impl SignalingClient {
@@ -79,7 +124,7 @@ impl SignalingClient {
let (tx_outgoing, mut rx_outgoing) = mpsc::channel::<String>(32);
// 发送协程
tokio::spawn(async move {
let writer=tokio::spawn(async move {
while let Some(msg) = rx_outgoing.recv().await {
if let Err(e) = write.send(Message::Text(msg)).await {
log::warn!("WS send error: {}", e);
@@ -89,23 +134,66 @@ impl SignalingClient {
});
let tx_out_clone = tx_outgoing.clone();
static GENERATION: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1);
let generation=GENERATION.fetch_add(1,std::sync::atomic::Ordering::Relaxed);
let reconnect_key=Arc::new(std::sync::Mutex::new(None));
let refreshed=reconnect_key.clone();
// 接收与状态机协程
tokio::spawn(async move {
let mut req_counter = 10;
let started=std::time::Instant::now();
let mut last_ping=started;
let mut pings=0u64;
let mut pong_queued=0u64;
let mut connected=false;
let mut next_refresh=tokio::time::Instant::now()+std::time::Duration::from_secs(30);
let mut refresh_acks=std::collections::VecDeque::new();
let mut accepted_refresh=0;
// Socket.IO binary event awaiting attachments: (event name, header JSON).
let mut pending_binary: Option<(String, Value)> = None;
while let Some(msg_res) = read.next().await {
loop {
let msg_res=tokio::select! {
_=event_sender.closed()=>break,
// Official ControlledSession RefreshSignalTokenLoop: first
// 30s, success every ~300s, failure retry after 30s. Native
// libstreamer 0x885774 / 0x885e58; emit has NO payload args.
_=tokio::time::sleep_until(next_refresh), if connected => {
req_counter+=1;
refresh_acks.push_back(req_counter);
if refresh_acks.len()>16 { refresh_acks.pop_front(); }
let packet=format!("42{}[\"refresh_reconnect_key\"]",req_counter);
if tx_out_clone.send(packet).await.is_err() {
let _=event_sender.send(SignalingEvent::Disconnected).await;break;
}
next_refresh=tokio::time::Instant::now()+std::time::Duration::from_secs(30);
log::info!("Signaling reconnect-key refresh requested: generation={} age_s={}",generation,started.elapsed().as_secs());
continue;
},
msg=read.next()=>match msg {
Some(msg)=>msg,
None=>{let _=event_sender.send(SignalingEvent::Disconnected).await;break;}
},
};
match msg_res {
Ok(Message::Text(txt)) => {
// Engine.IO 报文处理
if txt.starts_with('0') {
if let Ok(open)=serde_json::from_str::<Value>(&txt[1..]) {
log::info!("Signaling heartbeat config: generation={} ping_interval_ms={:?} ping_timeout_ms={:?}",generation,open.get("pingInterval").and_then(Value::as_u64),open.get("pingTimeout").and_then(Value::as_u64));
}
// Open packet -> 发送 Socket.IO connect
let _ = tx_out_clone.send("40".into()).await;
} else if txt == "2" {
// Ping -> 回复 Pong
let _ = tx_out_clone.send("3".into()).await;
let gap=last_ping.elapsed().as_secs();last_ping=std::time::Instant::now();pings+=1;
if tx_out_clone.send("3".into()).await.is_ok() { pong_queued+=1; }
if pings==1 || pings%12==0 {
log::info!("Signaling heartbeat progress: generation={} age_s={} pings={} pong_queued={} gap_s={}",generation,started.elapsed().as_secs(),pings,pong_queued,gap);
}
} else if txt.starts_with("40") {
connected=true;
next_refresh=tokio::time::Instant::now()+std::time::Duration::from_secs(30);
// Socket.IO connected -> 发送 room_info 请求
req_counter += 1;
let room_req = format!("42{}[\"room_info\"]", req_counter);
@@ -113,9 +201,23 @@ impl SignalingClient {
let _ = event_sender.send(SignalingEvent::Connected).await;
} else if txt.starts_with("43") {
// Socket.IO ack 回调
let payload = &txt[txt.find('[').unwrap_or(2)..];
let begin=txt.find('[').unwrap_or(2);
let ack_id=txt[2..begin].parse::<u64>().ok();
let payload = &txt[begin..];
if let Ok(v) = serde_json::from_str::<Value>(payload) {
let _ = event_sender.send(SignalingEvent::RoomInfoAck(v)).await;
if let Some(id)=ack_id.filter(|id|refresh_acks.contains(id)) {
refresh_acks.retain(|pending|*pending!=id);
let key=refreshed_key(&v);
let success=key.is_some();
// Accept a delayed retry response, but never replace
// a newer key with an older successful response.
if success && id>accepted_refresh {
accepted_refresh=id;
*refreshed.lock().unwrap()=key;
next_refresh=tokio::time::Instant::now()+std::time::Duration::from_secs(300);
}
log::info!("Signaling reconnect-key refresh acknowledged: generation={} age_s={} success={}",generation,started.elapsed().as_secs(),success);
} else { let _ = event_sender.send(SignalingEvent::RoomInfoAck(v)).await; }
}
} else if txt.starts_with("45") || txt.starts_with("46") {
// Socket.IO binary event/ack: header text, attachments follow as binary frames.
@@ -170,14 +272,16 @@ impl SignalingClient {
}
}
"released" => {
log::info!("Cloud peer event: generation={} event=released age_s={} pings={} last_ping_gap_s={} ice_id_present={}",generation,started.elapsed().as_secs(),pings,last_ping.elapsed().as_secs(),data.get("ice_id").is_some());
let _ = event_sender
.send(SignalingEvent::Released(data.clone()))
.await;
}
"left" | "leave" => {
log::info!("Cloud peer event: generation={} event={} age_s={} pings={} last_ping_gap_s={} ice_id_present={}",generation,event_name,started.elapsed().as_secs(),pings,last_ping.elapsed().as_secs(),data.get("ice_id").is_some());
let ice_id = data.get("ice_id").and_then(|v| v.as_str()).unwrap_or("");
if ice_id.is_empty() {
log::warn!("Room expired from NetEase cloud (leave event). Triggering room renewal...");
log::warn!("Cloud room leave without peer identifier; renewing signaling (expiry cause unknown)");
let _ = event_sender.send(SignalingEvent::Disconnected).await;
} else {
let _ = event_sender
@@ -212,16 +316,26 @@ impl SignalingClient {
}
}
}
Ok(Message::Close(_)) | Err(_) => {
Ok(Message::Close(frame)) => {
log::warn!("Signaling socket closed: generation={} age_s={} close_code={:?} pings={} last_ping_gap_s={}",generation,started.elapsed().as_secs(),frame.map(|f|u16::from(f.code)),pings,last_ping.elapsed().as_secs());
let _ = event_sender.send(SignalingEvent::Disconnected).await;
break;
}
Err(_) => {
log::warn!("Signaling socket receive failed: generation={} age_s={} pings={} last_ping_gap_s={}",generation,started.elapsed().as_secs(),pings,last_ping.elapsed().as_secs());
let _ = event_sender.send(SignalingEvent::Disconnected).await;
break;
}
_ => {}
}
}
log::info!("Signaling receiver stopped: generation={} age_s={}",generation,started.elapsed().as_secs());
// Live peer callbacks can retain the old SignalingClient sender.
// Explicitly drop its write half too when this room stops reading.
writer.abort();
});
Ok(Self { tx_outgoing })
Ok(Self { tx_outgoing, _reconnect_key:reconnect_key })
}
pub async fn emit_event(&self, event: &str, payload: serde_json::Value) -> Result<(), String> {
+247
View File
@@ -0,0 +1,247 @@
//! Kernel-level virtual keyboard and pointer through /dev/uinput (as Sunshine does).
//!
//! Works the same under X11, every Wayland compositor and the greeter/lock screen, needs no
//! portal permission and sends physical keycodes, so the compositor's keysym → key lookup
//! (which can pick an AltGr level for `minus` and drop `_`, issue #3) is not involved.
//! Access: a udev rule `KERNEL=="uinput", SUBSYSTEM=="misc", OPTIONS+="static_node=uinput",
//! TAG+="uaccess"` grants the logged-in seat user access (see README).
//!
//! Devices: one keyboard + relative mouse, one absolute pointer (ABS_X/ABS_Y 0..=65535 with
//! buttons and wheels, like a QEMU tablet). Mixing relative and absolute axes in one device
//! confuses libinput.
#[cfg(target_os = "linux")]
mod imp {
use std::fs::{File, OpenOptions};
use std::io::Write;
use std::os::unix::fs::OpenOptionsExt;
use std::os::unix::io::AsRawFd;
use std::sync::Mutex;
const EV_SYN: u16 = 0x00;
const EV_KEY: u16 = 0x01;
const EV_REL: u16 = 0x02;
const EV_ABS: u16 = 0x03;
const SYN_REPORT: u16 = 0;
const REL_X: u16 = 0x00;
const REL_Y: u16 = 0x01;
const REL_HWHEEL: u16 = 0x06;
const REL_WHEEL: u16 = 0x08;
const ABS_X: u16 = 0x00;
const ABS_Y: u16 = 0x01;
pub const BTN_LEFT: u16 = 0x110;
pub const BTN_RIGHT: u16 = 0x111;
pub const BTN_MIDDLE: u16 = 0x112;
pub const BTN_SIDE: u16 = 0x113;
pub const BTN_EXTRA: u16 = 0x114;
pub const ABS_MAX: i32 = 65535;
const UI_SET_EVBIT: libc::c_ulong = 0x4004_5564;
const UI_SET_KEYBIT: libc::c_ulong = 0x4004_5565;
const UI_SET_RELBIT: libc::c_ulong = 0x4004_5566;
const UI_SET_ABSBIT: libc::c_ulong = 0x4004_5567;
const UI_DEV_CREATE: libc::c_ulong = 0x5501;
const UI_DEV_DESTROY: libc::c_ulong = 0x5502;
const UI_DEV_SETUP: libc::c_ulong = 0x405c_5503;
const UI_ABS_SETUP: libc::c_ulong = 0x401c_5504;
#[repr(C)]
struct InputId { bustype: u16, vendor: u16, product: u16, version: u16 }
#[repr(C)]
struct UinputSetup { id: InputId, name: [u8; 80], ff_effects_max: u32 }
#[repr(C)]
struct AbsInfo { value: i32, minimum: i32, maximum: i32, fuzz: i32, flat: i32, resolution: i32 }
#[repr(C)]
struct UinputAbsSetup { code: u16, _pad: u16, absinfo: AbsInfo }
#[repr(C)]
struct InputEvent { time: libc::timeval, kind: u16, code: u16, value: i32 }
struct Device(File);
impl Drop for Device {
fn drop(&mut self) { unsafe { libc::ioctl(self.0.as_raw_fd(), UI_DEV_DESTROY); } }
}
impl Device {
fn ioctl(&self, request: libc::c_ulong, value: libc::c_ulong) -> std::io::Result<()> {
if unsafe { libc::ioctl(self.0.as_raw_fd(), request, value) } < 0 { Err(std::io::Error::last_os_error()) } else { Ok(()) }
}
fn create(name: &str, product: u16, configure: impl FnOnce(&Device) -> std::io::Result<()>) -> std::io::Result<Self> {
let file = OpenOptions::new().write(true).custom_flags(libc::O_NONBLOCK).open("/dev/uinput")?;
let device = Device(file);
configure(&device)?;
let mut setup = UinputSetup { id: InputId { bustype: 0x06 /* BUS_VIRTUAL */, vendor: 0x1d6b, product, version: 1 }, name: [0; 80], ff_effects_max: 0 };
setup.name[..name.len().min(79)].copy_from_slice(&name.as_bytes()[..name.len().min(79)]);
if unsafe { libc::ioctl(device.0.as_raw_fd(), UI_DEV_SETUP, &setup) } < 0 { return Err(std::io::Error::last_os_error()); }
device.ioctl(UI_DEV_CREATE, 0)?;
Ok(device)
}
fn abs(&self, code: u16) -> std::io::Result<()> {
self.ioctl(UI_SET_ABSBIT, code.into())?;
let setup = UinputAbsSetup { code, _pad: 0, absinfo: AbsInfo { value: 0, minimum: 0, maximum: ABS_MAX, fuzz: 0, flat: 0, resolution: 0 } };
if unsafe { libc::ioctl(self.0.as_raw_fd(), UI_ABS_SETUP, &setup) } < 0 { return Err(std::io::Error::last_os_error()); }
Ok(())
}
fn emit(&mut self, events: &[(u16, u16, i32)]) -> std::io::Result<()> {
let zero = libc::timeval { tv_sec: 0, tv_usec: 0 };
let mut buffer = Vec::with_capacity((events.len() + 1) * std::mem::size_of::<InputEvent>());
for &(kind, code, value) in events.iter().chain(std::iter::once(&(EV_SYN, SYN_REPORT, 0))) {
let event = InputEvent { time: zero, kind, code, value };
let bytes = unsafe { std::slice::from_raw_parts((&event as *const InputEvent).cast::<u8>(), std::mem::size_of::<InputEvent>()) };
buffer.extend_from_slice(bytes);
}
self.0.write_all(&buffer)
}
}
pub struct Devices { keyboard: Mutex<Device>, pointer: Mutex<Device> }
impl Devices {
pub fn open() -> std::io::Result<Self> {
let keyboard = Device::create("uu-remote-linux keyboard", 1, |d| {
d.ioctl(UI_SET_EVBIT, EV_KEY.into())?;
for code in 1..=248u16 { d.ioctl(UI_SET_KEYBIT, code.into())?; }
// Relative motion (games / pointer lock) lives with the keyboard device.
d.ioctl(UI_SET_EVBIT, EV_REL.into())?;
d.ioctl(UI_SET_RELBIT, REL_X.into())?;
d.ioctl(UI_SET_RELBIT, REL_Y.into())?;
for button in [BTN_LEFT, BTN_RIGHT, BTN_MIDDLE] { d.ioctl(UI_SET_KEYBIT, button.into())?; }
Ok(())
})?;
let pointer = Device::create("uu-remote-linux pointer", 2, |d| {
d.ioctl(UI_SET_EVBIT, EV_KEY.into())?;
for button in [BTN_LEFT, BTN_RIGHT, BTN_MIDDLE, BTN_SIDE, BTN_EXTRA] { d.ioctl(UI_SET_KEYBIT, button.into())?; }
d.ioctl(UI_SET_EVBIT, EV_REL.into())?;
d.ioctl(UI_SET_RELBIT, REL_WHEEL.into())?;
d.ioctl(UI_SET_RELBIT, REL_HWHEEL.into())?;
d.ioctl(UI_SET_EVBIT, EV_ABS.into())?;
d.abs(ABS_X)?;
d.abs(ABS_Y)
})?;
Ok(Self { keyboard: Mutex::new(keyboard), pointer: Mutex::new(pointer) })
}
pub fn key(&self, code: u16, pressed: bool) -> std::io::Result<()> {
self.keyboard.lock().unwrap().emit(&[(EV_KEY, code, i32::from(pressed))])
}
pub fn move_absolute(&self, x: i32, y: i32) -> std::io::Result<()> {
self.pointer.lock().unwrap().emit(&[(EV_ABS, ABS_X, x.clamp(0, ABS_MAX)), (EV_ABS, ABS_Y, y.clamp(0, ABS_MAX))])
}
pub fn move_relative(&self, dx: i32, dy: i32) -> std::io::Result<()> {
self.keyboard.lock().unwrap().emit(&[(EV_REL, REL_X, dx), (EV_REL, REL_Y, dy)])
}
pub fn button(&self, code: u16, pressed: bool) -> std::io::Result<()> {
self.pointer.lock().unwrap().emit(&[(EV_KEY, code, i32::from(pressed))])
}
pub fn wheel(&self, vertical: i32, horizontal: i32) -> std::io::Result<()> {
let mut events = Vec::new();
if vertical != 0 { events.push((EV_REL, REL_WHEEL, vertical)); }
if horizontal != 0 { events.push((EV_REL, REL_HWHEEL, horizontal)); }
if events.is_empty() { return Ok(()); }
self.pointer.lock().unwrap().emit(&events)
}
}
}
#[cfg(not(target_os = "linux"))]
mod imp {
pub const BTN_LEFT: u16 = 0x110;
pub const BTN_RIGHT: u16 = 0x111;
pub const BTN_MIDDLE: u16 = 0x112;
pub const BTN_SIDE: u16 = 0x113;
pub const BTN_EXTRA: u16 = 0x114;
pub const ABS_MAX: i32 = 65535;
pub struct Devices;
impl Devices {
pub fn open() -> std::io::Result<Self> { Err(std::io::Error::new(std::io::ErrorKind::Unsupported, "uinput requires Linux")) }
pub fn key(&self, _: u16, _: bool) -> std::io::Result<()> { Ok(()) }
pub fn move_absolute(&self, _: i32, _: i32) -> std::io::Result<()> { Ok(()) }
pub fn move_relative(&self, _: i32, _: i32) -> std::io::Result<()> { Ok(()) }
pub fn button(&self, _: u16, _: bool) -> std::io::Result<()> { Ok(()) }
pub fn wheel(&self, _: i32, _: i32) -> std::io::Result<()> { Ok(()) }
}
}
pub use imp::{Devices, ABS_MAX, BTN_EXTRA, BTN_LEFT, BTN_MIDDLE, BTN_RIGHT, BTN_SIDE};
/// X11 button ordinal (1 left, 2 middle, 3 right, 8/9 side) → evdev button code.
pub fn button_code(x11_button: i32) -> Option<u16> {
match x11_button { 1 => Some(BTN_LEFT), 2 => Some(BTN_MIDDLE), 3 => Some(BTN_RIGHT), 8 => Some(BTN_SIDE), 9 => Some(BTN_EXTRA), _ => None }
}
/// X11 wheel "buttons" 4/5 (vertical) and 6/7 (horizontal) → (REL_WHEEL, REL_HWHEEL) steps.
pub fn wheel_step(x11_button: i32) -> Option<(i32, i32)> {
match x11_button { 4 => Some((1, 0)), 5 => Some((-1, 0)), 6 => Some((0, -1)), 7 => Some((0, 1)), _ => None }
}
/// Base keysym (as produced by input_mapping::windows_vk_to_keysym) → physical evdev keycode
/// at its US-layout position. The compositor then applies the user's own layout, exactly as
/// for a hardware keyboard.
pub fn keysym_to_evdev(keysym: u64) -> Option<u16> {
const LETTERS: [u16; 26] = [30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44];
const KEYPAD: [u16; 10] = [82, 79, 80, 81, 75, 76, 77, 71, 72, 73];
let code = match keysym {
0x61..=0x7a => LETTERS[(keysym - 0x61) as usize],
0x31..=0x39 => (keysym - 0x31) as u16 + 2, // 1..9
0x30 => 11,
0xffb0..=0xffb9 => KEYPAD[(keysym - 0xffb0) as usize],
0xffbe..=0xffc7 => (keysym - 0xffbe) as u16 + 59, // F1..F10
0xffc8 => 87, 0xffc9 => 88, // F11, F12
0xffca..=0xffd5 => (keysym - 0xffca) as u16 + 183, // F13..F24
0xff0b => 76, // Clear: keypad 5 without NumLock, as on PC keyboards
0xff08 => 14, 0xff09 => 15, 0xff0d => 28, 0xff1b => 1, 0x20 => 57,
0xff13 => 119, 0xffe5 => 58, 0xff7f => 69, 0xff14 => 70, 0xff61 => 99,
0xffe1 => 42, 0xffe2 => 54, 0xffe3 => 29, 0xffe4 => 97, 0xffe9 => 56, 0xffea => 100,
0xffeb => 125, 0xffec => 126, 0xff67 => 127,
0xff55 => 104, 0xff56 => 109, 0xff57 => 107, 0xff50 => 102,
0xff51 => 105, 0xff52 => 103, 0xff53 => 106, 0xff54 => 108,
0xff63 => 110, 0xffff => 111,
0xffaa => 55, 0xffab => 78, 0xffac => 121, 0xffad => 74, 0xffae => 83, 0xffaf => 98, 0xff8d => 96,
0x3b => 39, 0x3d => 13, 0x2c => 51, 0x2d => 12, 0x2e => 52, 0x2f => 53, 0x60 => 41,
0x5b => 26, 0x5c => 43, 0x5d => 27, 0x27 => 40,
0x1008ff12 => 113, 0x1008ff11 => 114, 0x1008ff13 => 115,
0x1008ff17 => 163, 0x1008ff16 => 165, 0x1008ff15 => 166, 0x1008ff14 => 164,
_ => return None,
};
Some(code)
}
/// Input backend policy: `UU_INPUT_BACKEND=uinput` forces uinput, `native` disables it,
/// `auto` (default) uses uinput for Wayland/portal sessions when /dev/uinput is accessible
/// and keeps the verified XTest path on X11.
pub fn wanted(backend: crate::desktop_backend::DesktopBackend) -> bool {
match std::env::var("UU_INPUT_BACKEND").as_deref() {
Ok("uinput") => true,
Ok("native") => false,
_ => backend != crate::desktop_backend::DesktopBackend::X11,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn maps_keysyms_to_physical_us_positions() {
assert_eq!(keysym_to_evdev(0x61), Some(30)); // a
assert_eq!(keysym_to_evdev(0x7a), Some(44)); // z
assert_eq!(keysym_to_evdev(0x30), Some(11)); // 0
assert_eq!(keysym_to_evdev(0x31), Some(2)); // 1
assert_eq!(keysym_to_evdev(0x2d), Some(12)); // minus: Shift+minus gives '_' (#3)
assert_eq!(keysym_to_evdev(0xffe1), Some(42)); // Shift_L
assert_eq!(keysym_to_evdev(0xffc9), Some(88)); // F12
assert_eq!(keysym_to_evdev(0xffb5), Some(76)); // KP_5
assert_eq!(keysym_to_evdev(0x12345), None);
}
#[test]
fn every_mapped_windows_vk_has_a_physical_key() {
let missing: Vec<i32> = (0..=0xff).filter(|vk| {
crate::input_mapping::windows_vk_to_keysym(*vk).is_some_and(|ks| keysym_to_evdev(ks).is_none())
}).collect();
assert!(missing.is_empty(), "VKs without evdev mapping: {missing:x?}");
}
#[test]
fn buttons_and_wheel() {
assert_eq!(button_code(1), Some(BTN_LEFT));
assert_eq!(button_code(3), Some(BTN_RIGHT));
assert_eq!(wheel_step(4), Some((1, 0)));
assert_eq!(wheel_step(7), Some((0, 1)));
assert_eq!(button_code(4), None);
}
}
+1
View File
@@ -179,6 +179,7 @@ async fn read_encoder_with(
gop: gop_frames(settings.fps, true) as u32, cq: settings.cq() as u32,
target_bps: settings.max_kbps().map_or(16_000, |k| i64::from(k) * 3 / 4) * 1000,
max_bps: max_kbps * 1000, buffer_bits: (max_kbps / 8).clamp(100, 500) * 1000, gpu,
damage: crate::inproc_encoder::damage_enabled(),
};
log::info!("Desktop encoder: display={} source={}x{} output={:?} fps={} cq={} maxrate={}k encoder={} pipeline=in-process",
display,size.0,size.1,settings.output,settings.fps,config.cq,max_kbps,if gpu{"h264_nvenc"}else{"libx264"});
+12 -4
View File
@@ -198,7 +198,11 @@ impl WebRtcSession {
feedback_counts.observe(packet.as_any());
if packet.as_any().is::<webrtc::rtcp::payload_feedbacks::picture_loss_indication::PictureLossIndication>()
|| packet.as_any().is::<webrtc::rtcp::payload_feedbacks::full_intra_request::FullIntraRequest>() {
idr_on_feedback.store(true, std::sync::atomic::Ordering::Release);
// Dedupe only while an IDR is pending; the encoder clears the flag when it emits one,
// so a lost IDR does not block the next recovery request.
if !idr_on_feedback.load(std::sync::atomic::Ordering::Acquire) {
idr_on_feedback.store(true, std::sync::atomic::Ordering::Release);
}
}
if let Some(report) = packet.as_any().downcast_ref::<webrtc::rtcp::receiver_report::ReceiverReport>() {
reports += 1;
@@ -434,18 +438,22 @@ impl WebRtcSession {
let next_seq = || sequence.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
// Default file-transfer folder: the desktop user's home directory.
let home = std::env::var("HOME").unwrap_or_else(|_| "/".into());
let desktop_permission=if screen.init_error.is_none() {
// Tool peers are permitted without a desktop; the port-mapping viewer aborts on Reject.
let desktop_permission=if screen.init_error.is_none() || !desktop {
crate::system_metrics::Permission::Allow
} else { crate::system_metrics::Permission::Reject };
// Without a desktop (headless/portal before consent) the port-mapping tool still waits
// for ScreenSources/CaptureChange and aborts otherwise: tool peers get a nominal screen.
let screen_size=if screen.init_error.is_none() { (screen.width, screen.height) } else { (1920, 1080) };
let messages = [
(8, crate::initialization::encode_capture_change(next_seq(), timestamp, 0, 0, "Linux desktop")),
(13, Ok(crate::initialization::envelope(next_seq(), timestamp, 13, &init_actions.metrics_payload(desktop_sound, desktop_permission)))),
(26, Ok(crate::initialization::envelope(next_seq(), timestamp, 26,
&crate::system_metrics::remote_download_path(&home)))),
(7, crate::capture_setting::screen_sources(next_seq(), timestamp, (screen.width, screen.height), init_video.borrow().output, "Linux desktop")),
(7, crate::capture_setting::screen_sources(next_seq(), timestamp, screen_size, init_video.borrow().output, "Linux desktop")),
];
for (field, message) in messages {
if screen.init_error.is_some() && matches!(field,7|8) { continue; }
if desktop && screen.init_error.is_some() && matches!(field,7|8) { continue; }
let message = match message {
Ok(message) => message,
Err(e) => { log::error!("CONTROL initialization encode failed: {}", e); return; }
+15 -1
View File
@@ -6,6 +6,17 @@ final class MarkerCheck: NSObject {
let kde = NSTextField(labelWithString: "KDE → Mac: not checked")
let copied = NSTextField(labelWithString: "Mac marker: not copied")
let formats = NSTextField(labelWithString: "Known text formats: not checked")
// The official viewer drops remote format offers before ACK unless its
// remote window is key (viewer 0x100380f20 -> isKeyWindow). A delayed
// marker-only comparison lets it stay key throughout negotiation.
@objc func armGnome() {
gnome.stringValue = "GNOME → Mac: armed; return to UU and copy VM marker"
DispatchQueue.main.asyncAfter(deadline: .now() + 15) { self.compareGnome() }
}
@objc func armKde() {
kde.stringValue = "KDE → Mac: armed; return to UU and copy VM marker"
DispatchQueue.main.asyncAfter(deadline: .now() + 15) { self.compareKde() }
}
@objc func copyMarker() {
NSPasteboard.general.clearContents()
let ok = NSPasteboard.general.setString("UU-Mac-to-VM 中文🙂", forType: .string)
@@ -32,14 +43,17 @@ final class MarkerCheck: NSObject {
NSButton(title: title, target: self, action: action)
}
func show() {
let window = NSWindow(contentRect: NSRect(x: 0,y: 0,width: 500,height: 360), styleMask: [.titled,.closable], backing: .buffered, defer: false)
let window = NSWindow(contentRect: NSRect(x: 0,y: 0,width: 620,height: 500), styleMask: [.titled,.closable], backing: .buffered, defer: false)
window.title = "UU synthetic clipboard acceptance"
window.isReleasedWhenClosed = false
let stack = NSStackView(views: [
NSTextField(labelWithString: "Only fixed test-marker matches are displayed."),
NSTextField(labelWithString: "Keep the UU remote window key until format ACK / text request."),
button("Copy Mac test marker", #selector(copyMarker)), copied,
button("Compare GNOME VM marker", #selector(compareGnome)), gnome,
button("Compare KDE VM marker", #selector(compareKde)), kde, formats,
button("Arm GNOME comparison in 15 seconds", #selector(armGnome)),
button("Arm KDE comparison in 15 seconds", #selector(armKde)),
button("Quit test fixture", #selector(quit))])
stack.orientation = .vertical; stack.spacing = 14
stack.translatesAutoresizingMaskIntoConstraints = false
+7 -3
View File
@@ -1,5 +1,5 @@
"""Hold an ephemeral idle inhibition only in the isolated QEMU acceptance VM."""
import pathlib,subprocess,signal,threading,sys
import pathlib,subprocess,signal,threading,sys,os
assert pathlib.Path('/proc/sys/kernel/hostname').read_text().strip()=='uu-hyprland-test'
assert subprocess.check_output(['systemd-detect-virt'],text=True).strip()=='qemu'
import gi
@@ -7,7 +7,11 @@ gi.require_version('Gio','2.0')
from gi.repository import Gio,GLib
seconds=min(4200,max(1,int(sys.argv[1]) if len(sys.argv)>1 else 3600))
bus=Gio.bus_get_sync(Gio.BusType.SESSION,None)
reply=bus.call_sync('org.freedesktop.ScreenSaver','/ScreenSaver','org.freedesktop.ScreenSaver','Inhibit',GLib.Variant('(ss)',('UU isolated acceptance','Timed live-connection acceptance')),GLib.VariantType.new('(u)'),Gio.DBusCallFlags.NONE,3000,None)
gnome='GNOME' in os.environ.get('XDG_CURRENT_DESKTOP','').upper().split(':')
destination='org.gnome.SessionManager' if gnome else 'org.freedesktop.ScreenSaver'
object_path='/org/gnome/SessionManager' if gnome else '/ScreenSaver'
parameters=GLib.Variant('(susu)',('UU isolated acceptance',0,'Timed live-connection acceptance',8)) if gnome else GLib.Variant('(ss)',('UU isolated acceptance','Timed live-connection acceptance'))
reply=bus.call_sync(destination,object_path,destination,'Inhibit',parameters,GLib.VariantType.new('(u)'),Gio.DBusCallFlags.NONE,3000,None)
cookie=reply.unpack()[0]
stop=threading.Event()
signal.signal(signal.SIGTERM,lambda *_:stop.set())
@@ -16,6 +20,6 @@ print('VM timed idle inhibition acquired',flush=True)
try:stop.wait(seconds)
finally:
try:
bus.call_sync('org.freedesktop.ScreenSaver','/ScreenSaver','org.freedesktop.ScreenSaver','UnInhibit',GLib.Variant('(u)',(cookie,)),None,Gio.DBusCallFlags.NONE,3000,None)
bus.call_sync(destination,object_path,destination,'Uninhibit' if gnome else 'UnInhibit',GLib.Variant('(u)',(cookie,)),None,Gio.DBusCallFlags.NONE,3000,None)
print('VM timed idle inhibition released',flush=True)
except GLib.Error:print('VM idle inhibition connection closed',flush=True)