mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 08:50:40 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b6703b19df | ||
|
|
76a225a235 | ||
|
|
da99c1ceb4 | ||
|
|
0fe9b979e5 | ||
|
|
cb4850d296 | ||
|
|
16ded48a99 | ||
|
|
d95053d490 |
No files matched your search
@@ -116,6 +116,8 @@ 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` / `kms` (experimental feature) / `none` (headless: no display; desktop offers ignored; tool peers get a nominal 1920x1080 screen + Allow permissions, which the port-mapping viewer requires) |
|
||||
| `UU_DESKTOP_RESIZE=0` | X11: the viewer's 分辨率 choice scales the encoded stream instead of changing the display mode. Default: `src/desktop_mode.rs` switches the primary output via xrandr (adds a CVT-RB mode when missing, re-applies once if mutter resets it), restores the original mode for resolution_type 3 and 2 s after the last desktop stream ends |
|
||||
| `UU_NVENC_RGB=0` / `=1` | NVENC 4:2:0 without scaling takes packed BGRA/BGR0 directly (no CPU swscale). Default: on, except when a connected DRM connector belongs to an nvidia-bound card (desktop composited on the encoding GPU; #16 measured 82.6 vs 98 fps at 4K). `0` forces CPU conversion, `1` forces the direct path |
|
||||
| `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) |
|
||||
| Mac viewer Cmd | With 「使用 macOS 快捷键」 off the Mac viewer sends Cmd=VK_LWIN 0x5B, Option=0xA4, Ctrl=0xA2; connect header `controller_platform`=4 is macOS. For Mac controllers Cmd is held back: Cmd+C/V/A/F/X/Z → Ctrl+key (terminal: Cmd+C/V → Ctrl+Shift+C/V), other combos/alone → Super |
|
||||
| `UU_TERMINAL_SHORTCUTS=0` | disable Ctrl+V → Ctrl+Shift+V in focused X11 terminals (Mac Cmd and Ctrl both arrive as VK_LCONTROL) |
|
||||
@@ -130,8 +132,9 @@ viewer does not reconnect them automatically.
|
||||
| `UU_USE_PROXY=1` | honor HTTP/SOCKS proxy env vars; cloud API clients bypass env proxies by default |
|
||||
| `UU_REMOTE_ASSIST=0`, `UU_ASSIST_ALLOW=1`, `UU_ASSIST_UI=tty`, `UU_ASSIST_DEBUG=1` | disable assistance / allow at start / terminal UI for `assist` / include the server's short error message in assist errors |
|
||||
|
||||
Token has no expiry field; API code 1120 (HTTP 422) means invalid/expired → re-login. The config is re-read
|
||||
every 60 s.
|
||||
Token has no expiry field; API code 1120 (HTTP 422) means invalid/expired → re-login. `config.json` is parsed once
|
||||
(`config::file()`); only a `LoginExpired` room answer re-reads it from disk (`config::read_fresh()`) before waiting
|
||||
for a new QR login.
|
||||
|
||||
## 6. Code map
|
||||
|
||||
|
||||
Generated
+1
-1
@@ -2741,7 +2741,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "uu-remote-linux"
|
||||
version = "0.2.23"
|
||||
version = "0.2.26"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64 0.22.1",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "uu-remote-linux"
|
||||
version = "0.2.23"
|
||||
version = "0.2.26"
|
||||
edition = "2021"
|
||||
default-run = "uuremote-server"
|
||||
authors = ["uu-remote-linux contributors"]
|
||||
|
||||
+3
-1
@@ -46,7 +46,7 @@
|
||||
| Mac shortcuts | **Recommended**: turn off 「使用 macOS 快捷键」 (use macOS shortcuts) in the Mac viewer's remote-window menu; then Cmd+C/V/A/F/X/Z work as on a Mac (Cmd+C/V become Ctrl+Shift+C/V in terminals) and Ctrl+C always interrupts. With the option on, the viewer sends Cmd as Ctrl: in a terminal Ctrl+V / Cmd+V paste, Ctrl+C interrupts, copy is 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 |
|
||||
| Quality / frame rate / resolution | Auto, Original 20M, Ultra 8M, HD 2M, custom; 30/60/90/144 fps; on X11 a resolution choice changes the desktop resolution itself like the official Windows host (xrandr, adding the mode when missing; restored for "original" or on disconnect), `UU_DESKTOP_RESIZE=0` scales in the encoder instead; Wayland scales in the encoder |
|
||||
| Sound | System audio captured from PulseAudio / PipeWire and sent as Opus |
|
||||
| File transfer | Upload, download (including folders), create folder, rename, delete |
|
||||
| Terminal | The official "Terminal" tool, PTY sessions, multiple sessions, rename |
|
||||
@@ -330,6 +330,8 @@ Common environment variables:
|
||||
|---|---|
|
||||
| `UU_CONFIG` | Config file path (default `~/.config/uuremote/config.json`) |
|
||||
| `UU_DESKTOP_BACKEND` | `auto` / `x11` / `wayland` / `portal` / `kms` (experimental feature) / `none` (headless) |
|
||||
| `UU_DESKTOP_RESIZE=0` | on X11, keep the desktop resolution and only scale the encoded stream when the viewer picks a resolution |
|
||||
| `UU_NVENC_RGB=0` / `=1` | NVENC encodes BGRA directly (saves CPU). Off by default when a monitor is connected to the NVIDIA card (slower when the desktop is composited on the same GPU); `0` forces off, `1` forces on |
|
||||
| `UU_WAYLAND_MULTISCREEN=1` | Enable Hyprland physical monitor switching (off by default) |
|
||||
| `UU_WAYLAND_OUTPUT` | Initial native Wayland output name, e.g. `HDMI-A-1` |
|
||||
| `UU_WAYLAND_NO_VIRTUAL_KEYBOARD=1` | Native Wayland skips the virtual keyboard (e.g. Denial reserves it for its input method); keys go through uinput. Without wlr-virtual-pointer the pointer also uses uinput (#72) |
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
| Mac 快捷键 | **推荐**:在 Mac 远控窗口菜单里关闭「使用 macOS 快捷键」,之后和在 Mac 上一样:Cmd+C/V/A/F/X/Z 是复制、粘贴、全选、查找、剪切、撤销(终端里 Cmd+C/V 自动变成 Ctrl+Shift+C/V),Ctrl+C 在终端里始终是中断。保持开启时,客户端会把 Cmd 和 Ctrl 都当成 Ctrl 发送:终端里 Ctrl+V / Cmd+V 自动转成粘贴,Ctrl+C 是中断,复制用 Cmd+Shift+C(X11) |
|
||||
| 鼠标指针样式 | 远端指针形状实时同步(X11) |
|
||||
| 剪贴板 | 双向文本同步 |
|
||||
| 画质 / 帧率 / 分辨率 | 自动、原画 20M、超清 8M、高清 2M、自定义;30/60/90/144 帧;「其他分辨率」由编码器缩放,不改动主机显示器 |
|
||||
| 画质 / 帧率 / 分辨率 | 自动、原画 20M、超清 8M、高清 2M、自定义;30/60/90/144 帧;X11 下切换分辨率会像官方 Windows 被控端一样真正修改桌面分辨率(xrandr,缺少该模式时自动添加;选「原始」或断开后恢复),`UU_DESKTOP_RESIZE=0` 改为仅由编码器缩放;Wayland 仍由编码器缩放 |
|
||||
| 声音 | 采集系统声音(PulseAudio / PipeWire),Opus 编码传到控制端 |
|
||||
| 文件传输 | 上传、下载(含文件夹)、新建文件夹、重命名、删除 |
|
||||
| 终端 | 官方「终端」工具,PTY 会话,支持多会话和重命名 |
|
||||
@@ -299,6 +299,8 @@ systemctl --user restart uuremote-native.service
|
||||
|---|---|
|
||||
| `UU_CONFIG` | 配置文件路径(默认 `~/.config/uuremote/config.json`) |
|
||||
| `UU_DESKTOP_BACKEND` | `auto` / `x11` / `wayland` / `portal` / `kms`(实验性特性) / `none`(无头模式) |
|
||||
| `UU_DESKTOP_RESIZE=0` | X11 下控制端切换分辨率时不改桌面分辨率,只缩放编码画面 |
|
||||
| `UU_NVENC_RGB=0` / `=1` | NVENC 直接编码 BGRA(省 CPU)。显示器接在 NVIDIA 卡上时默认关闭(同卡合成时直吃反而更慢),`0` 强制关,`1` 强制开 |
|
||||
| `UU_WAYLAND_MULTISCREEN=1` | 启用 Hyprland 物理显示器切换(默认关闭) |
|
||||
| `UU_WAYLAND_OUTPUT` | 原生 Wayland 默认采集输出名称,例如 `HDMI-A-1` |
|
||||
| `UU_WAYLAND_NO_VIRTUAL_KEYBOARD=1` | 原生 Wayland 不创建虚拟键盘(如 Denial 只把它给自己的输入法),键盘改走 uinput。合成器没有 wlr-virtual-pointer 时鼠标也自动改走 uinput(#72) |
|
||||
|
||||
@@ -305,6 +305,32 @@ static void on_status_menu(GtkStatusIcon *i, guint button, guint time, gpointer
|
||||
(void)i; (void)button; (void)time; (void)d;
|
||||
gtk_menu_popup_at_pointer(GTK_MENU(tray_menu), NULL);
|
||||
}
|
||||
// Monochrome tray icon that follows light/dark panels: GTK and the GNOME AppIndicator extension
|
||||
// recolor "-symbolic" names, KDE recolors the ColorScheme-Text class. Installed into the user's
|
||||
// hicolor theme (found by every panel's default lookup) and also offered as the icon theme path,
|
||||
// so it needs no package install. KDE tries dash-trimmed names ("uu-remote-linux") in each theme
|
||||
// before the next one, so the name must not trim into the colored app icon (#87).
|
||||
static const char TRAY_ICON_NAME[] = "uuremote-tray-symbolic";
|
||||
static const char TRAY_ICON_SVG[] =
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\">"
|
||||
"<style id=\"current-color-scheme\">.ColorScheme-Text{color:#232629}</style>"
|
||||
"<path class=\"ColorScheme-Text\" fill=\"currentColor\" fill-rule=\"evenodd\" d=\"M2.5 2h11A1.5 1.5 0 0 1 15 3.5v7a1.5 1.5 0 0 1-1.5 1.5h-11"
|
||||
"A1.5 1.5 0 0 1 1 10.5v-7A1.5 1.5 0 0 1 2.5 2zm0 1.5v7h11v-7z\"/>"
|
||||
"<path class=\"ColorScheme-Text\" fill=\"currentColor\" d=\"M7.25 12h1.5v1.5H11a.75.75 0 0 1 0 1.5H5a.75.75 0 0 1 0-1.5h2.25z"
|
||||
"M11.5 4.5v4l-1.35-1.35-3.1 3.1-1.2-1.2 3.1-3.1L7.5 4.5z\"/></svg>\n";
|
||||
// Returns the icon theme root holding the icon ($XDG_DATA_HOME/icons), or NULL.
|
||||
static gchar *write_tray_icon(void) {
|
||||
gchar *root = g_build_filename(g_get_user_data_dir(), "icons", NULL);
|
||||
gchar *apps = g_build_filename(root, "hicolor", "scalable", "apps", NULL);
|
||||
gchar *file = g_strconcat(TRAY_ICON_NAME, ".svg", NULL);
|
||||
gchar *path = g_build_filename(apps, file, NULL), *current = NULL;
|
||||
// Rewriting an unchanged file would only make icon caches rescan.
|
||||
int ok = g_file_get_contents(path, ¤t, NULL, NULL) && strcmp(current, TRAY_ICON_SVG) == 0;
|
||||
if (!ok) ok = g_mkdir_with_parents(apps, 0755) == 0 && g_file_set_contents(path, TRAY_ICON_SVG, -1, NULL);
|
||||
g_free(apps); g_free(file); g_free(path); g_free(current);
|
||||
if (!ok) { g_free(root); return NULL; }
|
||||
return root;
|
||||
}
|
||||
static void build_tray(void) {
|
||||
tray_menu = gtk_menu_new();
|
||||
GtkWidget *open = gtk_menu_item_new_with_label("打开主窗口");
|
||||
@@ -318,7 +344,10 @@ static void build_tray(void) {
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(tray_menu), gtk_separator_menu_item_new());
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(tray_menu), quit);
|
||||
gtk_widget_show_all(tray_menu);
|
||||
const char *icon = gtk_icon_theme_has_icon(gtk_icon_theme_get_default(), "uu-remote-linux") ? "uu-remote-linux" : "computer";
|
||||
gchar *icon_path = write_tray_icon();
|
||||
if (icon_path) gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), icon_path);
|
||||
const char *fallback = gtk_icon_theme_has_icon(gtk_icon_theme_get_default(), "uu-remote-linux") ? "uu-remote-linux" : "computer";
|
||||
const char *icon = icon_path ? TRAY_ICON_NAME : fallback;
|
||||
|
||||
// StatusNotifierItem (GNOME AppIndicator extension, KDE): libayatana-appindicator3 / libappindicator3.
|
||||
const char *libs[] = { "libayatana-appindicator3.so.1", "libappindicator3.so.1" };
|
||||
@@ -329,8 +358,11 @@ static void build_tray(void) {
|
||||
void (*set_status)(void *, int) = (void (*)(void *, int))dlsym(h, "app_indicator_set_status");
|
||||
void (*set_menu)(void *, GtkMenu *) = (void (*)(void *, GtkMenu *))dlsym(h, "app_indicator_set_menu");
|
||||
void (*set_title)(void *, const char *) = (void (*)(void *, const char *))dlsym(h, "app_indicator_set_title");
|
||||
void (*set_theme_path)(void *, const char *) = (void (*)(void *, const char *))dlsym(h, "app_indicator_set_icon_theme_path");
|
||||
if (ind_new && set_status && set_menu) {
|
||||
void *ind = ind_new("uu-remote-linux", icon, 0 /* APPLICATION_STATUS */);
|
||||
// Without a theme path the panel cannot find the cached icon; keep the installed one.
|
||||
void *ind = ind_new("uu-remote-linux", set_theme_path ? icon : fallback, 0 /* APPLICATION_STATUS */);
|
||||
if (icon_path && set_theme_path) set_theme_path(ind, icon_path);
|
||||
if (set_title) set_title(ind, "UU 远程 Linux 主机");
|
||||
set_menu(ind, GTK_MENU(tray_menu));
|
||||
set_status(ind, 1 /* ACTIVE */);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
X11 下切换分辨率会真正修改桌面分辨率。/ On X11 the viewer's resolution choice now changes the desktop resolution.
|
||||
|
||||
### 新增 / Added
|
||||
- **控制端切换分辨率时真正修改桌面分辨率**,与官方 Windows 被控端一致:以前「其他分辨率」只缩放编码画面,选小分辨率反而让字更小更糊。
|
||||
现在 X11 下用 xrandr 切换主显示器模式,列表里没有的分辨率会自动添加;选「原始」或断开连接后恢复原分辨率。
|
||||
已用官方 Mac 控制端在 GNOME(X11)上实测切换与恢复。设置 `UU_DESKTOP_RESIZE=0` 可回到只缩放画面的旧行为;Wayland 不变。
|
||||
- On X11 the resolution choice switches the display mode via xrandr (adding the mode when missing) and restores it for
|
||||
"original" or on disconnect, like the official Windows host. `UU_DESKTOP_RESIZE=0` restores encoder scaling.
|
||||
|
||||
### 修复 / Fixed
|
||||
- **连接中桌面分辨率变化后画面中断**:以前会把采集失败当成编码器故障,逐个换编码器后停止推流。现在按新尺寸重新采集,鼠标坐标随之更新。
|
||||
- A desktop resize during a session no longer stops the stream; capture restarts at the new size and pointer mapping follows.
|
||||
|
||||
### 下载 / Download
|
||||
`uu-remote-linux_0.2.24_<amd64|arm64>.deb`,或 `uu-remote-linux-v0.2.24-<x86_64|aarch64>-linux.tar.gz`,或 `docker pull ghcr.io/vallierdev/uu-remote-linux:v0.2.24`(x86_64)。
|
||||
|
||||
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
|
||||
@@ -0,0 +1,12 @@
|
||||
托盘图标随深色/浅色模式自动变色。/ The tray icon now follows light and dark panels.
|
||||
|
||||
### 修复 / Fixed
|
||||
- **深色模式下托盘图标看不清**(#87):托盘改用内置单色符号图标,GNOME(AppIndicator 扩展)和 KDE 会按面板主题自动着色,
|
||||
tarball 安装也不用另装图标。旧版 AppIndicator 库或缓存目录不可写时沿用原图标。目前只经过 CI 编译,尚未在 KDE / GNOME 面板上实机确认。
|
||||
- The tray uses a built-in monochrome symbolic icon (written to the user cache and offered as the indicator's icon theme
|
||||
path) that GNOME's AppIndicator extension and KDE recolor for the panel theme. Built in CI; not yet checked on a real panel.
|
||||
|
||||
### 下载 / Download
|
||||
`uu-remote-linux_0.2.25_<amd64|arm64>.deb`,或 `uu-remote-linux-v0.2.25-<x86_64|aarch64>-linux.tar.gz`,或 `docker pull ghcr.io/vallierdev/uu-remote-linux:v0.2.25`(x86_64)。
|
||||
|
||||
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
|
||||
@@ -0,0 +1,16 @@
|
||||
修复 KDE 托盘图标显示为未知图标;显示器接在 NVIDIA 卡上时默认不再让 NVENC 直接编码 BGRA。/ Fixes the KDE tray icon; NVENC skips direct BGRA input when NVIDIA drives the display.
|
||||
|
||||
### 修复 / Fixed
|
||||
- **KDE 托盘显示成未知(空白页)图标**(#87,v0.2.25 引入):单色托盘图标改名为 `uuremote-tray-symbolic`,写到 `~/.local/share/icons/hicolor`,
|
||||
各家面板的默认图标查找都能找到,仍会随深色/浅色面板着色。已在 Plasma 6.7 / KF6 上用 KIconLoader 按 Plasma 的查找方式验证,Plasma 6.8 面板待报告者确认。
|
||||
v0.2.25 留下的 `~/.cache/uu-remote-linux/icons` 不再使用,可以删除。
|
||||
- **同一张 NVIDIA 卡负责显示时编码变慢**(#16):显示、采集、编码都在同一张 NVIDIA 卡上时,NVENC 直接编码 BGRA 反而比 CPU 转换慢
|
||||
(RTX 5070 4K:探针 82.6 vs 98 fps)。现在只要有显示器接在 NVIDIA 卡上就改用 CPU 转换;核显接显示器的机器不变。`UU_NVENC_RGB=1` 强制直接编码,`=0` 强制 CPU 转换。
|
||||
- The tray icon is installed as `uuremote-tray-symbolic` in the user hicolor theme, so KDE's default lookup finds it
|
||||
(v0.2.25 showed the unknown icon on Plasma 6.8). NVENC no longer takes packed BGRA when a connected monitor hangs off
|
||||
an NVIDIA card (slower when the desktop is composited on the encoding GPU); `UU_NVENC_RGB=1` forces it.
|
||||
|
||||
### 下载 / Download
|
||||
`uu-remote-linux_0.2.26_<amd64|arm64>.deb`,或 `uu-remote-linux-v0.2.26-<x86_64|aarch64>-linux.tar.gz`,或 `docker pull ghcr.io/vallierdev/uu-remote-linux:v0.2.26`(x86_64)。
|
||||
|
||||
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
|
||||
+12
-4
@@ -46,14 +46,22 @@ unsafe fn x11_display_name() -> *const libc::c_char { b":0\0".as_ptr().cast() }
|
||||
|
||||
/// The X11 root can be resized while the host runs (RandR, xrdp reconnects); the
|
||||
/// geometry read at startup then makes x11grab reject every new connection.
|
||||
pub fn x11_resized() -> bool {
|
||||
/// Re-reads the root size; None when the X11 engine is not in use or the query fails.
|
||||
pub fn x11_size() -> Option<(u32, u32)> {
|
||||
match unsafe { x11_refresh_geometry() } {
|
||||
1 => true,
|
||||
0 => false,
|
||||
code => { log::warn!("X11 geometry query failed with code {code}"); false }
|
||||
0 | 1 => x11_last_size(),
|
||||
-1 => None,
|
||||
code => { log::warn!("X11 geometry query failed with code {code}"); None }
|
||||
}
|
||||
}
|
||||
|
||||
/// The root size from the last refresh, without an X round trip (pointer mapping).
|
||||
pub fn x11_last_size() -> Option<(u32, u32)> {
|
||||
let (mut w, mut h): (libc::c_int, libc::c_int) = (0, 0);
|
||||
if unsafe { x11_get_dimensions(&mut w, &mut h) } != 0 || w <= 0 || h <= 0 { return None; }
|
||||
Some((w as u32, h as u32))
|
||||
}
|
||||
|
||||
pub struct ScreenCapture {
|
||||
pub backend: crate::desktop_backend::DesktopBackend,
|
||||
pub init_error: Option<String>,
|
||||
|
||||
@@ -141,6 +141,21 @@ pub fn handle_rpc_with_codecs(rpc: &[WireField], settings: &watch::Sender<VideoS
|
||||
apply_rpc(rpc, settings, native, h264, h265, crate::video::full_chroma_available())
|
||||
}
|
||||
|
||||
/// The resolution a capture/resolution RPC asks for, parsed like apply_rpc: X11 hosts apply it
|
||||
/// to the display mode itself (desktop_mode), as the official Windows host changes its resolution.
|
||||
pub fn requested_resolution(rpc: &[WireField]) -> Option<crate::desktop_mode::Request> {
|
||||
use crate::desktop_mode::Request;
|
||||
if let Some(request) = message(rpc, 2) {
|
||||
let fields = decode_wire(request).ok()?;
|
||||
if number(&fields, 10) == Some(3) { return Some(Request::Native); }
|
||||
let (w, h) = number(&fields, 16).zip(number(&fields, 17)).or_else(|| number(&fields, 5).zip(number(&fields, 6)))?;
|
||||
Some(Request::Size(u32::try_from(w).ok()?, u32::try_from(h).ok()?))
|
||||
} else if let Some(request) = message(rpc, 6) {
|
||||
let fields = decode_wire(request).ok()?;
|
||||
Some(Request::Size(u32::try_from(number(&fields, 1)?).ok()?, u32::try_from(number(&fields, 2)?).ok()?))
|
||||
} else { None }
|
||||
}
|
||||
|
||||
fn apply_rpc(rpc: &[WireField], settings: &watch::Sender<VideoSettings>, native: (u32, u32), h264: bool, h265: bool, full_chroma: bool) -> Option<Vec<u8>> {
|
||||
let header = message(rpc, 1).unwrap_or(&[]);
|
||||
let mut next = *settings.borrow();
|
||||
|
||||
@@ -0,0 +1,222 @@
|
||||
//! X11 desktop resolution follows the viewer's 分辨率 choice, like the official Windows host:
|
||||
//! the display mode itself changes (xrandr), not just the encoded size. The mode in use before
|
||||
//! the first change is restored for 原始/follow-remote and when the last desktop stream ends.
|
||||
//! Disable with UU_DESKTOP_RESIZE=0 (the viewer choice then scales the encoded stream instead).
|
||||
|
||||
use std::process::Command;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Request { Native, Size(u32, u32) }
|
||||
|
||||
struct Original { display: String, output: String, mode: String }
|
||||
|
||||
static ORIGINAL: Mutex<Option<Original>> = Mutex::new(None);
|
||||
static STREAMS: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
/// Upper bound per side (H.264 NVENC/VAAPI limit) and lower bound for a usable desktop.
|
||||
const MAX_SIDE: u32 = 4096;
|
||||
const MIN_SIZE: (u32, u32) = (640, 480);
|
||||
|
||||
pub fn enabled() -> bool { std::env::var("UU_DESKTOP_RESIZE").map_or(true, |v| v != "0") }
|
||||
|
||||
/// Keeps the changed mode while any desktop stream runs; the last one restores it.
|
||||
pub struct StreamGuard;
|
||||
impl StreamGuard {
|
||||
pub fn new() -> Self { STREAMS.fetch_add(1, Ordering::SeqCst); Self }
|
||||
}
|
||||
impl Drop for StreamGuard {
|
||||
fn drop(&mut self) {
|
||||
if STREAMS.fetch_sub(1, Ordering::SeqCst) == 1 && ORIGINAL.lock().unwrap().is_some() {
|
||||
// xrandr blocks; never run it on the async runtime thread dropping the stream.
|
||||
std::thread::spawn(|| {
|
||||
std::thread::sleep(std::time::Duration::from_secs(2));
|
||||
if STREAMS.load(Ordering::SeqCst) == 0 { restore(); }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies the viewer's resolution request to the X11 display; returns the desktop size now in
|
||||
/// use, or None when nothing changed hands (the caller keeps encoder scaling as the fallback).
|
||||
pub fn apply(display: &str, request: Request) -> Option<(u32, u32)> {
|
||||
match request {
|
||||
Request::Native => { restore(); crate::capture::x11_size() },
|
||||
Request::Size(w, h) => {
|
||||
let target = fit(w, h)?;
|
||||
match switch(display, target) {
|
||||
Ok(()) => crate::capture::x11_size(),
|
||||
Err(error) => { log::warn!("Desktop resolution change to {}x{} failed: {}", target.0, target.1, error); None },
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Even sides within MIN_SIZE..=MAX_SIDE, keeping the aspect ratio when scaled down.
|
||||
fn fit(w: u32, h: u32) -> Option<(u32, u32)> {
|
||||
if w == 0 || h == 0 { return None; }
|
||||
let scale = (f64::from(MAX_SIDE) / f64::from(w.max(h))).min(1.0);
|
||||
let (w, h) = ((f64::from(w) * scale).round() as u32, (f64::from(h) * scale).round() as u32);
|
||||
Some((w.max(MIN_SIZE.0) & !1, h.max(MIN_SIZE.1) & !1))
|
||||
}
|
||||
|
||||
fn switch(display: &str, target: (u32, u32)) -> Result<(), String> {
|
||||
let state = query(display)?;
|
||||
if state.current == Some(target) { return Ok(()); }
|
||||
{
|
||||
let mut original = ORIGINAL.lock().unwrap();
|
||||
if original.is_none() {
|
||||
let mode = state.current_mode.clone().ok_or("current mode unknown")?;
|
||||
log::info!("Desktop resolution: saving original mode {} on {}", mode, state.output);
|
||||
*original = Some(Original { display: display.into(), output: state.output.clone(), mode });
|
||||
}
|
||||
}
|
||||
let mode = match state.modes.iter().find(|(_, size)| *size == target) {
|
||||
Some((name, _)) => name.clone(),
|
||||
None => {
|
||||
let (name, timings) = cvt_reduced(target.0, target.1);
|
||||
// An existing mode of this name (earlier session) makes --newmode fail harmlessly.
|
||||
let mut args = vec!["--newmode", name.as_str()];
|
||||
args.extend(timings.iter().map(String::as_str));
|
||||
let _ = xrandr(display, &args);
|
||||
xrandr(display, &["--addmode", &state.output, &name])?;
|
||||
name
|
||||
},
|
||||
};
|
||||
set_mode(display, &state.output, &mode, target)?;
|
||||
log::info!("Desktop resolution changed to {}x{} ({})", target.0, target.1, mode);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Restores the mode saved before the first change, if any.
|
||||
pub fn restore() {
|
||||
let Some(original) = ORIGINAL.lock().unwrap().take() else { return; };
|
||||
let size = query(&original.display).ok().and_then(|state| state.modes.into_iter().find(|(name, _)| *name == original.mode).map(|(_, size)| size));
|
||||
match size.ok_or_else(|| "original mode no longer listed".to_owned())
|
||||
.and_then(|size| set_mode(&original.display, &original.output, &original.mode, size)) {
|
||||
Ok(()) => log::info!("Desktop resolution restored to {}", original.mode),
|
||||
Err(error) => log::warn!("Desktop resolution restore failed: {}", error),
|
||||
}
|
||||
let _ = crate::capture::x11_size();
|
||||
}
|
||||
|
||||
/// GNOME/mutter may answer a mode list change by re-applying its preferred mode; set it again.
|
||||
fn set_mode(display: &str, output: &str, mode: &str, size: (u32, u32)) -> Result<(), String> {
|
||||
for _ in 0..3 {
|
||||
xrandr(display, &["--output", output, "--mode", mode])?;
|
||||
std::thread::sleep(std::time::Duration::from_millis(1500));
|
||||
if query(display)?.current == Some(size) { return Ok(()); }
|
||||
}
|
||||
Err(format!("{output} did not keep {mode}"))
|
||||
}
|
||||
|
||||
fn xrandr(display: &str, args: &[&str]) -> Result<String, String> {
|
||||
let output = Command::new("xrandr").arg("--display").arg(display).args(args).output()
|
||||
.map_err(|e| format!("xrandr unavailable: {}", e.kind()))?;
|
||||
if !output.status.success() { return Err(format!("xrandr {} exited with {}", args.first().unwrap_or(&""), output.status)); }
|
||||
Ok(String::from_utf8_lossy(&output.stdout).into_owned())
|
||||
}
|
||||
|
||||
struct State { output: String, current: Option<(u32, u32)>, current_mode: Option<String>, modes: Vec<(String, (u32, u32))> }
|
||||
|
||||
fn query(display: &str) -> Result<State, String> { parse(&xrandr(display, &["--query"])?).ok_or_else(|| "no connected output".into()) }
|
||||
|
||||
/// The primary connected output (else the first connected one with a mode) and its mode list.
|
||||
fn parse(text: &str) -> Option<State> {
|
||||
let mut outputs: Vec<(bool, State)> = Vec::new();
|
||||
for line in text.lines() {
|
||||
if let Some(rest) = line.strip_prefix(" ") {
|
||||
let Some((_, state)) = outputs.last_mut() else { continue; };
|
||||
let mut parts = rest.split_whitespace();
|
||||
let Some(name) = parts.next() else { continue; };
|
||||
let Some(size) = mode_size(name) else { continue; };
|
||||
if parts.any(|rate| rate.contains('*')) { state.current = Some(size); state.current_mode = Some(name.into()); }
|
||||
state.modes.push((name.into(), size));
|
||||
} else if !line.starts_with(' ') {
|
||||
let mut parts = line.split_whitespace();
|
||||
let (Some(name), Some("connected")) = (parts.next(), parts.next()) else { outputs.push((false, State { output: String::new(), current: None, current_mode: None, modes: Vec::new() })); continue; };
|
||||
let primary = line.contains(" connected primary ");
|
||||
outputs.push((primary, State { output: name.into(), current: None, current_mode: None, modes: Vec::new() }));
|
||||
}
|
||||
}
|
||||
let mut connected: Vec<(bool, State)> = outputs.into_iter().filter(|(_, s)| !s.output.is_empty() && s.current.is_some()).collect();
|
||||
let index = connected.iter().position(|(primary, _)| *primary).unwrap_or(0);
|
||||
(index < connected.len()).then(|| connected.swap_remove(index).1)
|
||||
}
|
||||
|
||||
/// "1920x1080", "1920x1080R", "1920x1080_60.00", "1920x1080i" → (1920, 1080).
|
||||
fn mode_size(name: &str) -> Option<(u32, u32)> {
|
||||
let (w, rest) = name.split_once('x')?;
|
||||
let h: String = rest.chars().take_while(char::is_ascii_digit).collect();
|
||||
Some((w.parse().ok()?, h.parse().ok()?))
|
||||
}
|
||||
|
||||
/// VESA CVT reduced-blanking (v1) timings: 60 Hz, or 30 Hz when 60 Hz exceeds an HDMI 2.0
|
||||
/// pixel clock (virtual/forced connectors on integrated GPUs reject faster modes).
|
||||
fn cvt_reduced(w: u32, h: u32) -> (String, Vec<String>) {
|
||||
const H_BLANK: u32 = 160; const H_SYNC: u32 = 32; const H_FRONT: u32 = 48;
|
||||
const V_FRONT: u32 = 3; const MIN_V_BACK: u32 = 6; const MIN_VBLANK_US: f64 = 460.0;
|
||||
let v_sync = match (w * 3 == h * 4, w * 9 == h * 16, w * 10 == h * 16, w * 4 == h * 5, w * 9 == h * 15) {
|
||||
(true, ..) => 4, (_, true, ..) => 5, (_, _, true, ..) => 6, (_, _, _, true, _) | (.., true) => 7, _ => 10,
|
||||
};
|
||||
let timing = |refresh: f64| {
|
||||
let h_period = (1_000_000.0 / refresh - MIN_VBLANK_US) / f64::from(h);
|
||||
let vbi = ((MIN_VBLANK_US / h_period) as u32 + 1).max(V_FRONT + v_sync + MIN_V_BACK);
|
||||
let (total_h, total_v) = (w + H_BLANK, h + vbi);
|
||||
let clock = (refresh * f64::from(total_h) * f64::from(total_v) / 1_000_000.0 / 0.25).floor() * 0.25;
|
||||
(clock, total_h, total_v)
|
||||
};
|
||||
let (mut refresh, mut t) = (60, timing(60.0));
|
||||
if t.0 > 590.0 { refresh = 30; t = timing(30.0); }
|
||||
let (clock, total_h, total_v) = t;
|
||||
let name = format!("{w}x{h}_{refresh}R");
|
||||
let timings = [format!("{clock:.2}"), w.to_string(), (w + H_FRONT).to_string(), (w + H_FRONT + H_SYNC).to_string(), total_h.to_string(),
|
||||
h.to_string(), (h + V_FRONT).to_string(), (h + V_FRONT + v_sync).to_string(), total_v.to_string(), "+hsync".into(), "-vsync".into()];
|
||||
(name, timings.into())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn reduced_blanking_matches_the_cvt_tool() {
|
||||
// `cvt -r 1920 1080`: 138.50 1920 1968 2000 2080 1080 1083 1088 1111 +hsync -vsync
|
||||
let (name, t) = cvt_reduced(1920, 1080);
|
||||
assert_eq!(name, "1920x1080_60R");
|
||||
assert_eq!(t.join(" "), "138.50 1920 1968 2000 2080 1080 1083 1088 1111 +hsync -vsync");
|
||||
// `cvt -r 2560 1600`: 268.50 2560 2608 2640 2720 1600 1603 1609 1646
|
||||
assert_eq!(cvt_reduced(2560, 1600).1.join(" "), "268.50 2560 2608 2640 2720 1600 1603 1609 1646 +hsync -vsync");
|
||||
// 4K at 60 Hz needs 533 MHz (under the cap); a larger desktop drops to 30 Hz.
|
||||
assert_eq!(cvt_reduced(3840, 2160).0, "3840x2160_60R");
|
||||
assert_eq!(cvt_reduced(4096, 2560).0, "4096x2560_30R");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn requested_sizes_are_even_and_bounded() {
|
||||
assert_eq!(fit(1280, 720), Some((1280, 720)));
|
||||
assert_eq!(fit(4112, 2580), Some((4096, 2570)));
|
||||
assert_eq!(fit(301, 201), Some((640, 480)));
|
||||
assert_eq!(fit(0, 1080), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_primary_output_modes_and_current_mode() {
|
||||
let text = r"Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384
|
||||
DP-1 disconnected (normal left inverted right x axis y axis)
|
||||
HDMI-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
|
||||
1024x768 60.00
|
||||
3840x2160R 29.98
|
||||
1920x1080R 59.93*+
|
||||
HDMI-2 disconnected (normal left inverted right x axis y axis)
|
||||
";
|
||||
let state = parse(text).unwrap();
|
||||
assert_eq!(state.output, "HDMI-1");
|
||||
assert_eq!(state.current, Some((1920, 1080)));
|
||||
assert_eq!(state.current_mode.as_deref(), Some("1920x1080R"));
|
||||
assert_eq!(state.modes.len(), 3);
|
||||
assert_eq!(state.modes[1], ("3840x2160R".to_owned(), (3840, 2160)));
|
||||
assert!(parse("Screen 0: minimum 320 x 200\nDP-1 disconnected (normal)\n").is_none());
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -5,6 +5,7 @@ mod engine_plugin;
|
||||
mod doctor;
|
||||
mod wol;
|
||||
mod desktop_backend;
|
||||
mod desktop_mode;
|
||||
mod desktop_session;
|
||||
mod desktop_power;
|
||||
mod portal;
|
||||
@@ -784,7 +785,8 @@ async fn serve(mut capture: Arc<ScreenCapture>, input: Arc<InputInjector>, shutd
|
||||
continue;
|
||||
}
|
||||
let resized=desktop && capture.init_error.is_none() && capture.backend==desktop_backend::DesktopBackend::X11
|
||||
&& tokio::task::spawn_blocking(crate::capture::x11_resized).await.unwrap_or(false);
|
||||
// Compare with this capture, not the engine: a live stream may already have refreshed it.
|
||||
&& tokio::task::spawn_blocking(crate::capture::x11_size).await.ok().flatten().is_some_and(|size| size!=(capture.width,capture.height));
|
||||
if resized { log::info!("Desktop geometry changed since startup; reinitializing capture"); }
|
||||
let session_capture=if desktop && portal_desktop.is_none() && (capture.init_error.is_some() || resized) {
|
||||
match tokio::task::spawn_blocking(ScreenCapture::new).await {
|
||||
|
||||
+64
-6
@@ -262,10 +262,29 @@ fn cpu_hevc_options(settings: &VideoSettings, gop: &str) -> Vec<String> {
|
||||
|
||||
/// NVENC converts packed RGB on the GPU (BT.601 limited range, tagged bt470bg like the swscale default;
|
||||
/// compared on the 3090), so 4:2:0 without scaling skips the CPU BGRA→YUV pass (#16: ~2 cores at 4K).
|
||||
/// `input` is the source pixel format; `UU_NVENC_RGB=0` restores CPU conversion.
|
||||
/// When the desktop is composited on the NVIDIA card itself, the packed-RGB path is slower than CPU
|
||||
/// conversion (#16: RTX 5070 at 4K, 82.6 vs 98 fps), so it stays off unless `UU_NVENC_RGB=1`.
|
||||
/// `input` is the source pixel format; `UU_NVENC_RGB=0` always restores CPU conversion.
|
||||
fn nvenc_rgb_input(settings: &VideoSettings, encoder: Encoder, input: &'static str) -> Option<&'static str> {
|
||||
(encoder == Encoder::Nvenc && settings.chroma != crate::capture_setting::CHROMA_444 && settings.output.is_none()
|
||||
&& std::env::var("UU_NVENC_RGB").as_deref() != Ok("0")).then_some(input)
|
||||
let wanted = match std::env::var("UU_NVENC_RGB").as_deref() {
|
||||
Ok("0") => false,
|
||||
Ok("1") => true,
|
||||
_ => !nvidia_drives_display(std::path::Path::new("/sys/class/drm")),
|
||||
};
|
||||
(encoder == Encoder::Nvenc && settings.chroma != crate::capture_setting::CHROMA_444 && settings.output.is_none() && wanted)
|
||||
.then_some(input)
|
||||
}
|
||||
|
||||
/// A connected DRM connector (`cardN-HDMI-A-1/status`) on a card bound to the nvidia driver.
|
||||
/// Only visible with nvidia-drm modeset, which Wayland compositors require.
|
||||
fn nvidia_drives_display(drm: &std::path::Path) -> bool {
|
||||
std::fs::read_dir(drm).into_iter().flatten().flatten().any(|entry| {
|
||||
let name = entry.file_name().to_string_lossy().into_owned();
|
||||
let Some((card, _)) = name.split_once('-') else { return false; };
|
||||
card.starts_with("card")
|
||||
&& std::fs::read_to_string(entry.path().join("status")).is_ok_and(|s| s.trim() == "connected")
|
||||
&& std::fs::read_link(drm.join(card).join("device/driver")).is_ok_and(|p| p.file_name().is_some_and(|n| n == "nvidia"))
|
||||
})
|
||||
}
|
||||
|
||||
fn encoder_options(settings: &VideoSettings, encoder: Encoder, gop: &str, rgb: Option<&'static str>) -> Vec<String> {
|
||||
@@ -510,14 +529,14 @@ async fn read_encoder(
|
||||
// A failed native NVENC session (old driver, unsupported mode) still leaves FFmpeg's NVENC process pipeline.
|
||||
#[cfg(feature = "inproc-av")]
|
||||
if let Err(error) = &result {
|
||||
if !latest.is_closed() && native_inproc(&display, portal.is_some(), encoder) {
|
||||
if !latest.is_closed() && native_inproc(&display, portal.is_some(), encoder) && x11_resized(&display, portal.is_some(), size).is_none() {
|
||||
log::warn!("In-process {} stream unavailable; switching to the FFmpeg process pipeline: {}",encoder.name_for(settings.codec),error);
|
||||
result = read_encoder_with(size,display.clone(),portal.clone(),latest.clone(),encoder,false,sequence.clone(),settings,idr.clone(),budget.clone()).await;
|
||||
}
|
||||
}
|
||||
match result {
|
||||
Ok(())=>Ok(()),
|
||||
Err(error) if !latest.is_closed()=>{
|
||||
Err(error) if !latest.is_closed() && x11_resized(&display, portal.is_some(), size).is_none()=>{
|
||||
log::warn!("{} stream unavailable; switching scoped encoder to CPU: {}",encoder.name_for(settings.codec),error);
|
||||
read_encoder_with(size,display,portal,latest,Encoder::Cpu,true,sequence,settings,idr,budget).await
|
||||
},
|
||||
@@ -525,6 +544,13 @@ async fn read_encoder(
|
||||
}
|
||||
}
|
||||
|
||||
/// A resized X11 root fails every encoder alike (x11grab BadMatch on the old size);
|
||||
/// returns the new size so the stream restarts capture instead of walking the fallback chain.
|
||||
fn x11_resized(display: &str, portal: bool, size: (u32, u32)) -> Option<(u32, u32)> {
|
||||
if portal || display.starts_with("wayland:") || display.starts_with("kms:") { return None; }
|
||||
crate::capture::x11_size().filter(|current| *current != size)
|
||||
}
|
||||
|
||||
/// The native in-process NVENC path serves X11 only (not Wayland/KMS capture or a portal session).
|
||||
#[cfg(feature = "inproc-av")]
|
||||
fn native_inproc(display: &str, portal: bool, encoder: Encoder) -> bool {
|
||||
@@ -915,8 +941,9 @@ pub async fn probe(size:(u32,u32),display:String,portal:Option<Arc<crate::portal
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn stream_desktop(pc: Arc<RTCPeerConnection>, track: Arc<crate::video_track::VideoTrack>, size: (u32, u32), display: String, portal:Option<Arc<crate::portal::PortalSession>>,
|
||||
pub async fn stream_desktop(pc: Arc<RTCPeerConnection>, track: Arc<crate::video_track::VideoTrack>, mut size: (u32, u32), display: String, portal:Option<Arc<crate::portal::PortalSession>>,
|
||||
mut settings: tokio::sync::watch::Receiver<VideoSettings>, applied: Arc<tokio::sync::watch::Sender<VideoSettings>>, idr: Arc<AtomicBool>) -> Result<(), String> {
|
||||
let _desktop_mode = crate::desktop_mode::StreamGuard::new();
|
||||
loop {
|
||||
if transport_closed(&pc) { return Ok(()); }
|
||||
if pc.connection_state() == RTCPeerConnectionState::Connected
|
||||
@@ -956,6 +983,8 @@ pub async fn stream_desktop(pc: Arc<RTCPeerConnection>, track: Arc<crate::video_
|
||||
let discard = next.codec != current.codec || next.source_generation != current.source_generation || next.source_id != current.source_id || send_interrupted;
|
||||
current = next;
|
||||
timeline.fps = u64::from(next.fps);
|
||||
// A viewer resolution choice may have changed the X11 display mode (desktop_mode).
|
||||
if let Some(resized) = x11_resized(&display, portal_stream, size) { size = resized; }
|
||||
if discard {
|
||||
reader.0.abort();
|
||||
let _ = (&mut reader.0).await;
|
||||
@@ -969,6 +998,13 @@ pub async fn stream_desktop(pc: Arc<RTCPeerConnection>, track: Arc<crate::video_
|
||||
tokio::select! {
|
||||
result = &mut reader.0 => {
|
||||
let result = result.map_err(|e| format!("Encoder reader task: {e}"))?;
|
||||
if let Some(resized) = result.as_ref().err().and_then(|_| x11_resized(&display, portal_stream, size)) {
|
||||
log::info!("Desktop geometry changed during the stream ({}x{} -> {}x{}); restarting capture", size.0, size.1, resized.0, resized.1);
|
||||
size = resized;
|
||||
while receiver.try_recv().is_ok() {}
|
||||
reader.0 = tokio::spawn(read_encoder(size, display.clone(), portal.clone(), latest.clone(), current, sequence.clone(), idr.clone(), budget.clone()));
|
||||
continue;
|
||||
}
|
||||
if let (Err(error), VideoCodec::H265, true) = (&result, current.codec, track.supports(VideoCodec::H264)) {
|
||||
log::warn!("HEVC stream failed ({error}); falling back to negotiated H264");
|
||||
applied.send_modify(|value| value.codec = VideoCodec::H264);
|
||||
@@ -1045,6 +1081,28 @@ pub async fn stream_desktop(pc: Arc<RTCPeerConnection>, track: Arc<crate::video_
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn nvidia_display_is_detected_from_connected_connectors() {
|
||||
use std::os::unix::fs::symlink;
|
||||
let root = std::env::temp_dir().join(format!("uu-drm-test-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&root);
|
||||
let card = |n: &str, driver: &str, connector: &str, status: &str| {
|
||||
std::fs::create_dir_all(root.join(format!("drivers/{driver}"))).unwrap();
|
||||
std::fs::create_dir_all(root.join(format!("drm/{n}/device"))).unwrap();
|
||||
let _ = symlink(root.join(format!("drivers/{driver}")), root.join(format!("drm/{n}/device/driver")));
|
||||
std::fs::create_dir_all(root.join(format!("drm/{n}-{connector}"))).unwrap();
|
||||
std::fs::write(root.join(format!("drm/{n}-{connector}/status")), format!("{status}\n")).unwrap();
|
||||
};
|
||||
let drm = root.join("drm");
|
||||
card("card0", "i915", "HDMI-A-1", "connected");
|
||||
card("card1", "nvidia", "DP-1", "disconnected");
|
||||
assert!(!super::nvidia_drives_display(&drm), "iGPU drives the display");
|
||||
card("card1", "nvidia", "DP-2", "connected");
|
||||
assert!(super::nvidia_drives_display(&drm), "NVIDIA drives a display");
|
||||
assert!(!super::nvidia_drives_display(&root.join("missing")));
|
||||
let _ = std::fs::remove_dir_all(&root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn native_frame_dimensions_are_padded_to_even() {
|
||||
// A scaled compositor can report an odd logical desktop (e.g. two stacked 150% monitors →
|
||||
|
||||
+20
-2
@@ -560,6 +560,20 @@ impl WebRtcSession {
|
||||
(21, WireValue::Bytes(rpc)) => Some(*rpc), _ => None,
|
||||
}) else { continue; };
|
||||
let Ok(rpc_fields) = crate::protocol::decode_wire(rpc) else { continue; };
|
||||
// X11: 分辨率 changes the display mode itself, like the official Windows host; the stream
|
||||
// then carries the new native size instead of a scaled one (desktop_mode).
|
||||
let resized = if desktop && active_screen.init_error.is_none() && active_screen.portal.is_none()
|
||||
&& active_screen.backend == crate::desktop_backend::DesktopBackend::X11 && crate::desktop_mode::enabled() {
|
||||
match crate::capture_setting::requested_resolution(&rpc_fields) {
|
||||
Some(request) => {
|
||||
let display = active_screen.display.clone();
|
||||
tokio::task::spawn_blocking(move || crate::desktop_mode::apply(&display, request)).await.ok().flatten()
|
||||
.filter(|size| *size != input_size)
|
||||
},
|
||||
None => None,
|
||||
}
|
||||
} else { None };
|
||||
let input_size = resized.unwrap_or(input_size);
|
||||
let before = *settings.borrow();
|
||||
let output_before = before.output;
|
||||
let revision = track.revision();
|
||||
@@ -571,6 +585,8 @@ impl WebRtcSession {
|
||||
let mut response=None;owner.with_current(||response=apply());response
|
||||
} else {apply()};
|
||||
let Some(response)=response else {continue;};
|
||||
// Restart capture even when the encoded settings are unchanged (native size, no scaling).
|
||||
if resized.is_some() { settings.send_modify(|s| s.source_generation = s.source_generation.wrapping_add(1)); }
|
||||
let codec_changed = settings.borrow().codec != before.codec;
|
||||
if desktop && codec_changed && !track.wait_for_applied(revision, &settings).await {
|
||||
log::warn!("Codec switch did not produce a transmitted frame; success reply withheld");
|
||||
@@ -581,7 +597,7 @@ impl WebRtcSession {
|
||||
let next = || sequence.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
let _ = response_tx.send(crate::initialization::envelope(next(), timestamp, 22, &response));
|
||||
let current = *settings.borrow();
|
||||
if current.output != output_before {
|
||||
if current.output != output_before || resized.is_some() {
|
||||
match crate::capture_setting::screen_sources(next(), timestamp, input_size, current.output, "Linux desktop") {
|
||||
Ok(screens) => { let _ = response_tx.send(screens); }
|
||||
Err(error) => log::warn!("Screen sources update failed: {}", error),
|
||||
@@ -889,6 +905,8 @@ impl WebRtcSession {
|
||||
|
||||
Box::pin(async move {
|
||||
let input_size = crate::wayland::input_size((screen.width, screen.height));
|
||||
// After a RandR resize the stream restarts capture at the new size; map the pointer to it.
|
||||
let live_x11 = screen.init_error.is_none() && screen.portal.is_none() && screen.backend == crate::desktop_backend::DesktopBackend::X11;
|
||||
if let Some(term) = &terminal_worker {
|
||||
if crate::terminal::is_frame(&msg.data) { term.handle(&msg.data); return; }
|
||||
}
|
||||
@@ -1160,7 +1178,7 @@ impl WebRtcSession {
|
||||
if let Some(session)=message_input_session.as_ref() {session.with_input(|| {
|
||||
if !crate::wayland::input_ready() {return;}
|
||||
match &event {
|
||||
ControlInput::MouseAbsolute {x,y} => input_worker.mouse_absolute_normalized(*x,*y,crate::wayland::input_size(input_size)),
|
||||
ControlInput::MouseAbsolute {x,y} => input_worker.mouse_absolute_normalized(*x,*y,crate::wayland::input_size(if live_x11 {crate::capture::x11_last_size().unwrap_or(input_size)} else {input_size})),
|
||||
ControlInput::MouseRelative {dx,dy} => input_worker.mouse_relative(*dx,*dy),
|
||||
ControlInput::MouseScroll {dx,dy} => input_worker.mouse_scroll(*dx,*dy),
|
||||
ControlInput::Keyboard {key, pressed} => input_worker.windows_key_event(*key, *pressed),
|
||||
|
||||
Reference in new issue
Block a user