Compare commits

...
8 Commits
Author SHA1 Message Date
VallierDevandClaude Opus 5.5 296f0fdbcc Release v0.1.25
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-16 21:45:44 +08:00
wanglz111 b20fd6ccef Portal: map scaled GNOME input through EIS regions (#24)
* fix(portal): map scaled GNOME input through EIS regions

Keep unsupported portals on legacy input and leave capture/uinput independent of EIS. Cache logical geometry without the native handle lock and reject geometry changes during recovery.

Add native capability, handshake, geometry and lifecycle regression coverage with sanitizer checks; preserve existing non-portal paths. Refs #23.

* fix(portal): keep version 4 capture settings in pixel coordinates

Keep native, selectable and current screen rectangles in pixels with DPR 1 so legacy setting requests cannot implicitly downscale a scaled desktop. Leave Portal and EIS coordinate mapping local and unchanged.

Add inventory/request/ack/sync roundtrip regression coverage, including repeated settings changes and restoring native output. Refs #23.
2026-10-16 21:45:17 +08:00
VallierDevandClaude Opus 5.5 51b489b1e2 Log whether an offer's client_id equals the be-controlled client_id (boolean only)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-16 18:19:22 +08:00
VallierDevandClaude Opus 5.5 fb09b60b8a Release v0.1.24
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-16 18:09:38 +08:00
GuanchengLiandClaude Code 37504c7fe8 Adapt FFmpeg output timing args to detected capabilities (#22)
* Adapt FFmpeg output timing args to detected capabilities

Probe the selected FFmpeg (PATH or UU_FFMPEG_ROOT/config ffmpeg_root)
once per process with `-h full` and cache the result per executable
environment (program + LD_LIBRARY_PATH + PATH). FFmpeg 5+ gets
`-fps_mode vfr -enc_time_base 1/<fps>`; older builds such as Ubuntu
22.04's FFmpeg 4.4 fall back to `-vsync 0`. Probe failures, timeouts
and unparseable help output all take the legacy path, and no output
side `-r` is ever emitted. HEVC availability probing stays independent.

Verified on FFmpeg 4.4.2: 20 video tests pass and desktop-video-probe
emits 5 H.264 frames with the first frame an IDR.

Co-Authored-By: Claude Code <[email protected]>

* Keep modern timing args when the FFmpeg probe fails

A failed probe (spawn error, non-zero exit, timeout, or no parseable
help text) previously fell back to -vsync 0, but -vsync is deprecated
since FFmpeg 5.1 and a newer build may reject it, killing the encoder.
Legacy is now selected only from a completed help dump that visibly
lacks -fps_mode/-enc_time_base; everything else keeps
-fps_mode vfr -enc_time_base 1/fps. Also fix the encoder comment: the
same-slot drop belongs to vfr on a 1/fps timebase, while -vsync 0
passes catch-up frames through (a known degradation on FFmpeg 4.x).

Co-Authored-By: Claude Code <[email protected]>

---------

Co-authored-by: Claude Code <[email protected]>
2026-10-16 18:09:13 +08:00
VallierDevandClaude Opus 5.5 41ba1e9440 Log whether an offer's ice_id equals the be-controlled ice_id (boolean only)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-16 17:17:54 +08:00
VallierDevandClaude Opus 5.5 1e4bec4514 Log offer SDP structure (attribute names, extmap URIs, payload counts only)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-16 15:57:49 +08:00
VallierDevandClaude Opus 5.5 b4b872878f Log the structure of incoming SOAC offers (keys, types, lengths only)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-16 15:44:14 +08:00
21 changed files with 1385 additions and 53 deletions

No files matched your search

+13 -1
View File
@@ -28,10 +28,22 @@ jobs:
sudo apt-get update
sudo apt-get install -y build-essential pkg-config \
libx11-dev libxext-dev libxtst-dev libxfixes-dev libgtk-3-dev \
libwayland-dev libxkbcommon-dev libglib2.0-dev libpipewire-0.3-dev
libwayland-dev libxkbcommon-dev libglib2.0-dev libpipewire-0.3-dev libei-dev libeis-dev
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo test --locked --features wayland,portal
- name: Native portal and EIS regression tests (ASan/UBSan)
env:
ASAN_OPTIONS: detect_leaks=1
UBSAN_OPTIONS: halt_on_error=1
run: |
for source in tests/portal_engine.c tests/portal_input.c tests/portal_eis.c; do
target="/tmp/$(basename "$source" .c)"
cc -O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer \
-Wall -Wextra -Wno-unused-parameter "$source" -o "$target" \
$(pkg-config --cflags --libs gio-2.0 gio-unix-2.0 libpipewire-0.3 libei-1.0 libeis-1.0) -lpthread -lm
"$target"
done
test-inproc:
runs-on: ubuntu-24.04
+2 -1
View File
@@ -40,7 +40,7 @@ sudo apt install build-essential pkg-config \
# --features inproc-av: libavcodec-dev libavformat-dev libavdevice-dev libswscale-dev libclang-dev
# (FFmpeg 6.x; in-process capture/encoding, Ubuntu 24.04 ships it)
# --features wayland: libwayland-dev libxkbcommon-dev wl-clipboard
# --features wayland,portal: + libglib2.0-dev libpipewire-0.3-dev
# --features wayland,portal: + libglib2.0-dev libpipewire-0.3-dev libei-dev (libei >= 1.1)
```
Rust stable via rustup. Commands:
@@ -139,6 +139,7 @@ every 60 s.
| `src/initialization.rs`, `src/control_protocol.rs`, `src/protocol.rs` | protobuf encoders/decoders for CONTROL |
| `src/session_ice.rs`, `src/network_diagnostics.rs` | cloud ICE servers, address-free path diagnostics |
| `src/desktop_backend.rs`, `src/wayland.rs`, `src/portal*.rs` | backend selection, Hyprland, GNOME/KDE portal |
| `c_engine/portal_eis.inc` | scaled GNOME input through the existing Portal session's EIS connection; all input must use EIS once connected |
| `c_engine/x11_engine.c`, `c_engine/clipboard.c` | X11 capture/input/selection |
| `c_engine/wayland_engine.c`, `c_engine/portal_engine.c` | Wayland and portal engines |
| `src/assist.rs`, `c_engine/assist_window.c` | remote assistance (guest + account) and the unified GTK main window (assist + account/QR card) |
Generated
+1 -1
View File
@@ -2717,7 +2717,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "uu-remote-linux"
version = "0.1.23"
version = "0.1.25"
dependencies = [
"async-trait",
"base64 0.22.1",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "uu-remote-linux"
version = "0.1.23"
version = "0.1.25"
edition = "2021"
authors = ["uu-remote-linux contributors"]
description = "Unofficial Linux host for NetEase UU Remote: control a Linux desktop from the official clients"
+5 -3
View File
@@ -65,9 +65,9 @@ authorized session. Independent file/terminal tool peers do not reset input.
| Xfce | X11 | ✅ Tested in a VM | default |
| Cinnamon / MATE | X11 | ✅ Tested in a VM | default |
| Hyprland | Wayland (native wlroots protocols) | 🧪 Experimental, tested in a VM (some features limited, see below) | `--features wayland` |
| GNOME / KDE Plasma | Wayland (xdg-desktop-portal) | 🧪 Experimental, tested in a VM (some features limited, see below) | `--features wayland,portal` |
| GNOME / KDE Plasma | Wayland (xdg-desktop-portal) | 🧪 Experimental; validation scope and limits below | `--features wayland,portal` |
Apart from GNOME on X11, these desktops have been tested in virtual machines so far. If something goes wrong on
The GNOME Wayland Portal/EIS path has been checked for video and mouse/keyboard input on Ubuntu 26.04, GNOME 50, with one 4K screen at 200% scale; lock recovery and reconnection still need hardware acceptance testing. Apart from that path and GNOME on X11, desktop testing has primarily used virtual machines. If something goes wrong on
real hardware, please [open an issue](../../issues) with your distribution, desktop, GPU and the relevant lines from
`journalctl --user -u uuremote-native.service`.
@@ -75,6 +75,8 @@ Wayland limits: single screen, fixed resolution. The native Hyprland backend now
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.
Scaled GNOME desktops using native Portal input use EIS on the same authorized session when `ConnectToEIS` and a screen `mapping_id` are available. Each axis is mapped using the matched region and actual frame dimensions, with no fixed resolution or scale factor. This avoids scaled-coordinate rejection by `NotifyPointerMotionAbsolute`. Portal builds require libei >= 1.1. Missing EIS support retains the legacy input path and its existing scaling limitations; other initialization failures are reported and trigger session recovery. After a successful EIS connection, all input uses EIS. Capture alone and uinput do not initialize EIS; missing optional logical dimensions do not block capture. Keyboard input uses the existing Windows VK to evdev mapping. Recovery requires reconnecting if physical or logical dimensions change. Lock recovery still needs hardware acceptance testing; multi-monitor support, live resolution changes, and rotation/reflection transforms are outside this fix's scope. Capture settings remain at protocol version 4: advertised resolutions use pixel coordinates and DPR 1; Portal logical dimensions are used only for local input mapping and recovery checks.
The native Wayland backend needs `wlr-output-power-management` from the compositor to wake a turned-off screen; without it only wake is unavailable — capture and encoding are unaffected.
Native Wayland experiments: `UU_WAYLAND_PIPELINE=0` disables pipelining for comparison.
@@ -111,7 +113,7 @@ sudo apt install build-essential pkg-config \
# optional: Wayland backend
sudo apt install libwayland-dev libxkbcommon-dev wl-clipboard
# optional: GNOME/KDE portal backend
sudo apt install libglib2.0-dev libpipewire-0.3-dev
sudo apt install libglib2.0-dev libpipewire-0.3-dev libei-dev
```
- A Rust toolchain is required (<https://rustup.rs>).
+5 -3
View File
@@ -59,13 +59,15 @@ Portal 仅作用于本服务获授权的会话。文件传输、终端等独立
| Xfce | X11 | ✅ 虚拟机测试通过 | 默认 |
| Cinnamon / MATE | X11 | ✅ 虚拟机测试通过 | 默认 |
| Hyprland | Wayland(wlroots 原生协议) | 🧪 实验性,虚拟机测试(部分功能受限,见下) | `--features wayland` |
| GNOME / KDE Plasma | Wayland(xdg-desktop-portal) | 🧪 实验性,虚拟机测试(部分功能受限,见下) | `--features wayland,portal` |
| GNOME / KDE Plasma | Wayland(xdg-desktop-portal) | 🧪 实验性,验证范围与限制见下 | `--features wayland,portal` |
除 GNOME(X11)外,其余桌面目前都是在虚拟机里测试的。如果你在真机上遇到问题,欢迎[提交 issue](../../issues),
GNOME Wayland 的 Portal/EIS 路径已在 Ubuntu 26.04、GNOME 50、单屏 4K/200% 缩放下验证画面和键鼠;锁屏恢复及重连仍待实机验收。除 GNOME 的上述路径和 X11 外,其余桌面目前主要在虚拟机里测试。如果你在真机上遇到问题,欢迎[提交 issue](../../issues),
请附上发行版、桌面环境、显卡型号和 `journalctl --user -u uuremote-native.service` 里的相关日志。
Wayland 下的限制:只支持单屏、固定分辨率;Hyprland 原生后端默认使用双缓冲流水线 shm screencopy,控制端帧率设置会同步到采集节拍和编码器,但实际帧率仍受合成器、渲染和读回速度限制(旧串行路径在 2560x1600 曾测得约 16~22 帧;流水线只在虚拟机里测量过,不代表实机保证);portal 后端暂不支持唤醒屏幕和动态分辨率;剪贴板只在控制端的远控窗口处于前台时同步。
GNOME 缩放桌面在使用 Portal 原生键鼠时,若支持 `ConnectToEIS` 和屏幕 `mapping_id`,通过同一授权会话的 EIS 接口注入输入,按匹配的区域与实际帧尺寸分别映射横纵坐标,没有固定分辨率或缩放倍率,可避免 `NotifyPointerMotionAbsolute` 在缩放时拒绝坐标。Portal 构建需要 libei ≥ 1.1。缺少 EIS 支持时保留旧输入路径及其既有缩放限制;其他初始化错误会明确报告并触发会话恢复。EIS 连接成功后全部输入统一使用 EIS。只采集画面或使用 uinput 时不会初始化 EIS;缺少可选的逻辑尺寸也不阻断采集。键盘沿用项目现有的 Windows VK → evdev 映射。恢复时若物理或逻辑尺寸变化,需要重新连接。此路径仍需实机验证锁屏恢复;多屏、连接中改变分辨率及旋转/镜像变换不属于本次修复范围。 捕获设置协议仍为版本 4:对客户端上报的分辨率统一使用像素坐标、DPR 为 1;Portal 逻辑尺寸仅用于本地输入映射和恢复校验。
原生 Wayland 后端需要合成器提供 `wlr-output-power-management` 才能唤醒已关闭的屏幕;缺少该协议不影响采集和编码。
原生 Wayland 实验选项:`UU_WAYLAND_PIPELINE=0` 可关闭流水线做对照。`UU_WAYLAND_DMABUF=1` 显式尝试 dma-buf→GBM CPU 映射(默认关闭,需要运行时 libgbm;可用 `UU_WAYLAND_DMABUF_DEVICE` 指定 render node,默认 `/dev/dri/renderD128`)。仅支持显式线性修饰符、单平面 8-bit RGB,失败回退 SHM;virgl VM 中只验证了回退,成功导入/映射和硬件加速均未验证。这不是零拷贝 VAAPI 路径;选择 `UU_VIDEO_ENCODER=vaapi` 时仍由 FFmpeg 上传 CPU 帧。
@@ -97,7 +99,7 @@ sudo apt install build-essential pkg-config \
# 可选:Wayland 后端
sudo apt install libwayland-dev libxkbcommon-dev wl-clipboard
# 可选:GNOME/KDE portal 后端
sudo apt install libglib2.0-dev libpipewire-0.3-dev
sudo apt install libglib2.0-dev libpipewire-0.3-dev libei-dev
```
- 需要 Rust 工具链(<https://rustup.rs>)。
+4 -3
View File
@@ -51,10 +51,11 @@ fn main() {
if std::env::var_os("CARGO_FEATURE_PORTAL").is_some() {
println!("cargo:rerun-if-changed=c_engine/portal_engine.c");
println!("cargo:rerun-if-changed=c_engine/portal_engine.h");
println!("cargo:rerun-if-changed=c_engine/portal_eis.inc");
let flags=|kind:&str| {
let output=std::process::Command::new("pkg-config").args([kind,"gio-2.0","gio-unix-2.0","libpipewire-0.3"]).output()
.expect("Install pkg-config and GIO/PipeWire development libraries");
assert!(output.status.success(),"Portal requires GIO and PipeWire development libraries");
let output=std::process::Command::new("pkg-config").args([kind,"gio-2.0","gio-unix-2.0","libpipewire-0.3","libei-1.0 >= 1.1"]).output()
.expect("Install pkg-config and GIO/PipeWire/libei development libraries");
assert!(output.status.success(),"Portal requires GIO, PipeWire and libei >= 1.1 development libraries");
String::from_utf8(output.stdout).expect("pkg-config flags must be UTF-8")
};
let mut build=cc::Build::new();
+167
View File
@@ -0,0 +1,167 @@
/* All access is serialized by PortalSession's handle mutex, including close.
* ConnectToEIS disables every legacy Notify* input method on this session. */
enum { PORTAL_EIS_UNSUPPORTED = 13 };
static void portal_eis_log(struct ei *ei, enum ei_log_priority priority,
const char *message, struct ei_log_context *context) {
/* Library error text can include input values. Keep diagnostics numeric. */
static atomic_uint count;
if (atomic_fetch_add(&count, 1) < 12)
fprintf(stderr, "Portal EIS library diagnostic: priority=%d\n", priority);
}
static int portal_eis_dispatch(struct uu_portal *p) {
ei_dispatch(p->ei);
struct ei_event *event;
while ((event = ei_get_event(p->ei))) {
struct ei_device *device = ei_event_get_device(event);
switch (ei_event_get_type(event)) {
case EI_EVENT_SEAT_ADDED:
ei_seat_bind_capabilities(ei_event_get_seat(event),
EI_DEVICE_CAP_POINTER, EI_DEVICE_CAP_POINTER_ABSOLUTE,
EI_DEVICE_CAP_BUTTON, EI_DEVICE_CAP_SCROLL, EI_DEVICE_CAP_KEYBOARD, NULL);
break;
case EI_EVENT_DEVICE_RESUMED:
if (!g_list_find(p->ei_devices, device)) {
p->ei_devices = g_list_append(p->ei_devices, ei_device_ref(device));
ei_device_start_emulating(device, ++p->ei_sequence);
}
break;
case EI_EVENT_DEVICE_PAUSED:
case EI_EVENT_DEVICE_REMOVED:
if (g_list_find(p->ei_devices, device)) {
p->ei_devices = g_list_remove(p->ei_devices, device);
ei_device_unref(device);
}
break;
case EI_EVENT_DISCONNECT:
p->ei_failed = 1;
break;
default: break;
}
ei_event_unref(event);
}
return p->ei_failed ? 9 : 0;
}
static struct ei_device *portal_eis_device(struct uu_portal *p, enum ei_device_capability capability) {
for (GList *item = p->ei_devices; item; item = item->next)
if (ei_device_has_capability(item->data, capability)) return item->data;
return NULL;
}
static struct ei_region *portal_eis_region(struct uu_portal *p, struct ei_device *device) {
for (size_t i = 0; ; i++) {
struct ei_region *region = ei_device_get_region(device, i);
if (!region) return NULL;
const char *id = ei_region_get_mapping_id(region);
if (id && p->mapping_id && !strcmp(id, p->mapping_id) &&
ei_region_get_width(region) && ei_region_get_height(region)) return region;
}
}
static struct ei_device *portal_eis_absolute(struct uu_portal *p, struct ei_region **region) {
for (GList *item = p->ei_devices; item; item = item->next) {
struct ei_device *device = item->data;
if (ei_device_has_capability(device, EI_DEVICE_CAP_POINTER_ABSOLUTE) &&
(*region = portal_eis_region(p, device))) return device;
}
return NULL;
}
static void portal_eis_close(struct uu_portal *p) {
for (GList *item = p->ei_devices; item; item = item->next) ei_device_unref(item->data);
g_list_free(p->ei_devices); p->ei_devices = NULL;
if (p->ei) p->ei = ei_unref(p->ei);
}
static int portal_eis_open(struct uu_portal *p) {
if (!p->mapping_id) return PORTAL_EIS_UNSUPPORTED;
GUnixFDList *fds = NULL;
GError *error = NULL;
GVariant *reply = g_dbus_connection_call_with_unix_fd_list_sync(p->bus, DEST, PATH, REMOTE,
"ConnectToEIS", g_variant_new("(o@a{sv})", p->session, empty_options()),
G_VARIANT_TYPE("(h)"), G_DBUS_CALL_FLAGS_NONE, 3000, NULL, &fds, NULL, &error);
if (!reply) {
int unsupported = g_error_matches(error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD) ||
g_error_matches(error, G_DBUS_ERROR, G_DBUS_ERROR_NOT_SUPPORTED);
g_clear_error(&error); g_clear_object(&fds);
return unsupported ? PORTAL_EIS_UNSUPPORTED : 9;
}
gint32 index; g_variant_get(reply, "(h)", &index);
int fd = fds && index >= 0 && index < g_unix_fd_list_get_length(fds) ?
g_unix_fd_list_get(fds, index, NULL) : -1;
g_variant_unref(reply); g_clear_object(&fds);
if (fd < 0) return 9;
p->ei = ei_new_sender(NULL);
if (!p->ei) { close(fd); return 8; }
ei_log_set_handler(p->ei, portal_eis_log);
ei_configure_name(p->ei, "uu-remote-linux");
if (ei_setup_backend_fd(p->ei, fd)) return 9;
gint64 deadline = g_get_monotonic_time() + 3000000;
while (!portal_eis_dispatch(p)) {
struct ei_region *region = NULL;
if (portal_eis_absolute(p, &region) &&
portal_eis_device(p, EI_DEVICE_CAP_POINTER) &&
portal_eis_device(p, EI_DEVICE_CAP_BUTTON) &&
portal_eis_device(p, EI_DEVICE_CAP_SCROLL) &&
portal_eis_device(p, EI_DEVICE_CAP_KEYBOARD)) {
fprintf(stderr, "Portal EIS input ready: region=%ux%u\n",
ei_region_get_width(region), ei_region_get_height(region));
return 0;
}
gint64 remaining = deadline - g_get_monotonic_time();
if (remaining <= 0) break;
struct pollfd pending = {.fd = ei_get_fd(p->ei), .events = POLLIN};
int result = poll(&pending, 1, (int)((remaining + 999) / 1000));
if (result < 0 && errno != EINTR) break;
}
fprintf(stderr, "Portal EIS input initialization failed\n");
return 9;
}
static int portal_eis_available(struct uu_portal *p) {
if (!uu_portal_alive(p)) return 9;
return portal_eis_dispatch(p);
}
static int portal_eis_frame(struct uu_portal *p, struct ei_device *device) {
ei_device_frame(device, ei_now(p->ei));
return portal_eis_dispatch(p);
}
static int portal_eis_move(struct uu_portal *p, double x, double y, int relative) {
if (portal_eis_available(p)) return 9;
struct ei_device *device;
if (relative) {
device = portal_eis_device(p, EI_DEVICE_CAP_POINTER);
if (!device) return 9;
ei_device_pointer_motion(device, x * p->logical_width / p->width,
y * p->logical_height / p->height);
} else {
if (x < 0 || y < 0 || x >= p->width || y >= p->height) return 11;
struct ei_region *region = NULL;
device = portal_eis_absolute(p, &region);
if (!device) return 9;
double target_x = ei_region_get_x(region) + x * ei_region_get_width(region) / p->width;
double target_y = ei_region_get_y(region) + y * ei_region_get_height(region) / p->height;
ei_device_pointer_motion_absolute(device, target_x, target_y);
}
return portal_eis_frame(p, device);
}
static int portal_eis_button(struct uu_portal *p, int button, int pressed) {
if (portal_eis_available(p)) return 9;
if (button >= 4 && button <= 7) {
if (!pressed) return 0;
struct ei_device *device = portal_eis_device(p, EI_DEVICE_CAP_SCROLL);
if (!device) return 9;
int step = button == 4 || button == 6 ? -120 : 120;
ei_device_scroll_discrete(device, button <= 5 ? 0 : step, button <= 5 ? step : 0);
return portal_eis_frame(p, device);
}
int code = button == 1 ? 0x110 : button == 2 ? 0x112 : button == 3 ? 0x111 :
button == 8 ? 0x113 : button == 9 ? 0x114 : 0;
if (!code) return 11;
struct ei_device *device = portal_eis_device(p, EI_DEVICE_CAP_BUTTON);
if (!device) return 9;
ei_device_button_button(device, code, !!pressed);
return portal_eis_frame(p, device);
}
static int portal_eis_key(struct uu_portal *p, int code, int pressed) {
if (code < 0 || code > 0x2ff) return 11;
if (portal_eis_available(p)) return 9;
struct ei_device *device = portal_eis_device(p, EI_DEVICE_CAP_KEYBOARD);
if (!device) return 9;
ei_device_keyboard_key(device, (uint32_t)code, !!pressed);
return portal_eis_frame(p, device);
}
+80 -17
View File
@@ -2,6 +2,8 @@
#include "portal_engine.h"
#include <gio/gio.h>
#include <gio/gunixfdlist.h>
#include <libei.h>
#include <poll.h>
#include <pipewire/pipewire.h>
#include <spa/param/video/format-utils.h>
#include <spa/pod/builder.h>
@@ -47,6 +49,12 @@ struct uu_portal {
uint32_t node, width, height;
int logical_width, logical_height;
int absolute_stream_pixels;
struct ei *ei;
GList *ei_devices;
char *mapping_id;
uint32_t ei_sequence;
atomic_int ei_failed;
int ei_unavailable;
enum spa_video_format format;
uint8_t *frame;
size_t frame_length;
@@ -59,6 +67,7 @@ static pthread_once_t pw_once = PTHREAD_ONCE_INIT;
static atomic_uint token_sequence = 1;
static void initialize_pipewire(void) { pw_init(NULL, NULL); }
static GVariant *empty_options(void) { return g_variant_new_array(G_VARIANT_TYPE("{sv}"), NULL, 0); }
#include "portal_eis.inc"
static void fail(struct uu_portal *p, int error) {
pthread_mutex_lock(&p->lock);
if (!p->error) p->error = error;
@@ -271,6 +280,27 @@ static int connect_pipewire(struct uu_portal *p) {
pthread_mutex_unlock(&p->lock);
return result;
}
static int read_stream_result(struct uu_portal *p, GVariant *results) {
guint devices = 0;
GVariant *streams = g_variant_lookup_value(results, "streams", G_VARIANT_TYPE("a(ua{sv})"));
gboolean has_devices = g_variant_lookup(results, "devices", "u", &devices);
fprintf(stderr, "Portal authorization result: devices_present=%d device_bits=%u stream_count=%zu\n",
has_devices, devices, streams ? (size_t)g_variant_n_children(streams) : 0);
int error = 0;
if (!has_devices || (devices & 3) != 3 || !streams || g_variant_n_children(streams) != 1) {
error = 6;
} else {
GVariant *entry = g_variant_get_child_value(streams, 0), *properties;
g_variant_get(entry, "(u@a{sv})", &p->node, &properties);
/* Optional 'size' is compositor logical coordinates, not frame pixels. */
g_variant_lookup(properties, "size", "(ii)", &p->logical_width, &p->logical_height);
const char *mapping_id = NULL;
if (g_variant_lookup(properties, "mapping_id", "&s", &mapping_id)) p->mapping_id = g_strdup(mapping_id);
g_variant_unref(properties); g_variant_unref(entry);
}
if (streams) g_variant_unref(streams);
return error;
}
struct uu_portal *uu_portal_open_persist(const char *restore, void (*save_token)(const char *, void *), void *data, int *error, uint32_t *width, uint32_t *height) {
*error = 0; *width = *height = 0;
struct uu_portal *p = calloc(1, sizeof(*p));
@@ -341,18 +371,7 @@ struct uu_portal *uu_portal_open_persist(const char *restore, void (*save_token)
g_variant_lookup(results,"clipboard_enabled","b",&clipboard_enabled);
p->clipboard_enabled=clipboard_enabled;
fprintf(stderr,"Portal clipboard permission: granted=%d\n",clipboard_enabled);
guint devices = 0; GVariant *streams = g_variant_lookup_value(results, "streams", G_VARIANT_TYPE("a(ua{sv})"));
gboolean has_devices=g_variant_lookup(results, "devices", "u", &devices);
fprintf(stderr,"Portal authorization result: devices_present=%d device_bits=%u stream_count=%zu\n",has_devices,devices,streams?(size_t)g_variant_n_children(streams):0);
if (!has_devices || (devices & 3) != 3 || !streams || g_variant_n_children(streams) != 1) {
*error = 6;
} else {
GVariant *entry = g_variant_get_child_value(streams, 0), *properties;
g_variant_get(entry, "(u@a{sv})", &p->node, &properties);
/* 'size' is compositor logical coordinates, not the pixel frame size. */
g_variant_lookup(properties, "size", "(ii)", &p->logical_width, &p->logical_height);
g_variant_unref(properties); g_variant_unref(entry);
}
*error = read_stream_result(p, results);
if (!*error) {
const char *next = NULL;
if (g_variant_lookup(results, "restore_token", "&s", &next) && next && strlen(next) <= 4096)
@@ -361,7 +380,6 @@ struct uu_portal *uu_portal_open_persist(const char *restore, void (*save_token)
version >= 2, restore && *restore, p->restore_token && *p->restore_token);
}
if (!*error && p->restore_token && save_token) save_token(p->restore_token, data);
if (streams) g_variant_unref(streams);
g_variant_unref(results);
if (*error) goto done;
p->main_loop = g_main_loop_new(p->context, FALSE);
@@ -372,7 +390,7 @@ struct uu_portal *uu_portal_open_persist(const char *restore, void (*save_token)
if (*error) { uu_portal_close(p); return NULL; }
fprintf(stderr, "Portal pointer geometry: frame=%ux%u compositor=%dx%d absolute=%s\n",
p->width, p->height, p->logical_width, p->logical_height,
p->absolute_stream_pixels ? "stream-pixels" : "compositor-logical");
p->absolute_stream_pixels ? "stream-pixels-or-eis" : "compositor-logical");
*width = p->width; *height = p->height;
return p;
done:
@@ -390,6 +408,7 @@ static gboolean quit_dbus_loop(gpointer data) { g_main_loop_quit(data); return G
void uu_portal_close(struct uu_portal *p) {
if (!p) return;
atomic_store(&p->closed, 1);
portal_eis_close(p);
if (p->bus && p->session) {
GVariant *reply = g_dbus_connection_call_sync(p->bus, DEST, p->session, SESSION, "Close",
NULL, NULL, G_DBUS_CALL_FLAGS_NONE, 3000, NULL, NULL);
@@ -414,6 +433,7 @@ void uu_portal_close(struct uu_portal *p) {
if (p->main_loop) g_main_loop_unref(p->main_loop);
if (p->context) g_main_context_unref(p->context);
if (p->bus) g_object_unref(p->bus);
g_free(p->mapping_id);
g_free(p->clipboard_text); g_free(p->clipboard_mime); g_free(p->restore_token); free(p->session); free(p->frame);
pthread_cond_destroy(&p->changed); pthread_mutex_destroy(&p->lock); free(p);
}
@@ -440,12 +460,42 @@ int uu_portal_capture_since(struct uu_portal *p, uint8_t *frame, size_t length,
pthread_mutex_unlock(&p->lock); return result;
}
int uu_portal_alive(struct uu_portal *p) {
if (!p || atomic_load(&p->closed)) return 0;
if (!p || atomic_load(&p->closed) || atomic_load(&p->ei_failed)) return 0;
pthread_mutex_lock(&p->lock);
int alive = !p->error;
pthread_mutex_unlock(&p->lock);
return alive;
}
void uu_portal_input_dispatch(struct uu_portal *p) {
if (p->ei) portal_eis_dispatch(p);
}
static int prepare_input(struct uu_portal *p) {
if (!uu_portal_alive(p)) return 9;
/* xdg-desktop-portal 1.21 checks Notify absolute positions against logical
* stream size, while GNOME 50 forwards them into Mutter's pixel transform.
* Initialize EIS only when native input is used, leaving capture/uinput
* independent of EIS support. ConnectToEIS disables all Notify* methods. */
if (!p->ei && !p->ei_unavailable && p->absolute_stream_pixels &&
p->logical_width > 0 && p->logical_height > 0 &&
(p->width != (uint32_t)p->logical_width || p->height != (uint32_t)p->logical_height)) {
int result = portal_eis_open(p);
if (result == PORTAL_EIS_UNSUPPORTED) {
p->ei_unavailable = 1;
fprintf(stderr, "Portal EIS unavailable; retaining legacy input\n");
return 0;
}
if (result) {
/* A timeout may have committed ConnectToEIS at the portal. Any
* failure except explicit lack of support needs a fresh session. */
atomic_store(&p->ei_failed, 1);
static atomic_uint failures;
if (atomic_fetch_add(&failures, 1) < 12)
fprintf(stderr, "Portal EIS input initialization failed: code=%d\n", result);
return result;
}
}
return 0;
}
static int notify(struct uu_portal *p, const char *method, GVariant *parameters) {
if (!uu_portal_alive(p)) { g_variant_ref_sink(parameters); g_variant_unref(parameters); return 9; }
GError *error = NULL;
@@ -462,18 +512,29 @@ static int notify(struct uu_portal *p, const char *method, GVariant *parameters)
}
g_variant_unref(reply); return 0;
}
void uu_portal_logical_size(struct uu_portal *p, uint32_t *width, uint32_t *height) {
/* Stream size is optional; unknown logical geometry keeps the existing
* pixel-sized inventory without preventing capture or uinput. */
int known = p->logical_width > 0 && p->logical_height > 0;
*width = known ? (uint32_t)p->logical_width : p->width;
*height = known ? (uint32_t)p->logical_height : p->height;
}
int uu_portal_move(struct uu_portal *p, double x, double y, int relative) {
if (!p || !isfinite(x) || !isfinite(y)) return 11;
if (p->logical_width <= 0 || p->logical_height <= 0 || !p->width || !p->height) return 11;
if (!relative && (x < 0 || y < 0 || x >= p->width || y >= p->height)) return 11;
int result = prepare_input(p); if (result) return result;
if (p->ei) return portal_eis_move(p, x, y, relative);
if (relative) return notify(p, "NotifyPointerMotion", g_variant_new("(o@a{sv}dd)", p->session, empty_options(),
x * p->logical_width / p->width, y * p->logical_height / p->height));
if (x < 0 || y < 0 || x >= p->width || y >= p->height) return 11;
return notify(p, "NotifyPointerMotionAbsolute", g_variant_new("(o@a{sv}udd)", p->session, empty_options(), p->node,
p->absolute_stream_pixels ? x : x * p->logical_width / p->width,
p->absolute_stream_pixels ? y : y * p->logical_height / p->height));
}
int uu_portal_button(struct uu_portal *p, int button, int pressed) {
if (!p) return 11;
int result = prepare_input(p); if (result) return result;
if (p->ei) return portal_eis_button(p, button, pressed);
if (button >= 4 && button <= 7) {
if (!pressed) return 0;
return notify(p, "NotifyPointerAxisDiscrete", g_variant_new("(o@a{sv}ui)", p->session, empty_options(),
@@ -483,7 +544,9 @@ int uu_portal_button(struct uu_portal *p, int button, int pressed) {
if (!code) return 11;
return notify(p, "NotifyPointerButton", g_variant_new("(o@a{sv}iu)", p->session, empty_options(), code, (guint)!!pressed));
}
int uu_portal_key(struct uu_portal *p, uint32_t symbol, int pressed) {
int uu_portal_key(struct uu_portal *p, uint32_t symbol, int keycode, int pressed) {
if (!p || !symbol || symbol > INT32_MAX) return 11;
int result = prepare_input(p); if (result) return result;
if (p->ei) return portal_eis_key(p, keycode, pressed);
return notify(p, "NotifyKeyboardKeysym", g_variant_new("(o@a{sv}iu)", p->session, empty_options(), (gint)symbol, (guint)!!pressed));
}
+3 -1
View File
@@ -14,10 +14,12 @@ int uu_portal_clipboard_ready(struct uu_portal *portal);
int uu_portal_clipboard_set(struct uu_portal *portal, const uint8_t *text, size_t length);
int uu_portal_clipboard_poll(struct uu_portal *portal, uint8_t *text, size_t capacity);
int uu_portal_alive(struct uu_portal *portal);
void uu_portal_input_dispatch(struct uu_portal *portal);
void uu_portal_logical_size(struct uu_portal *portal, uint32_t *width, uint32_t *height);
void uu_portal_reset_frame(struct uu_portal *portal);
int uu_portal_capture(struct uu_portal *portal, uint8_t *bgra, size_t length);
int uu_portal_capture_since(struct uu_portal *portal, uint8_t *bgra, size_t length, uint64_t *revision);
int uu_portal_move(struct uu_portal *portal, double x, double y, int relative);
int uu_portal_button(struct uu_portal *portal, int button, int pressed);
int uu_portal_key(struct uu_portal *portal, uint32_t keysym, int pressed);
int uu_portal_key(struct uu_portal *portal, uint32_t keysym, int keycode, int pressed);
#endif
+17
View File
@@ -0,0 +1,17 @@
支持 Ubuntu 22.04 自带的 FFmpeg 4.4。/ Works with Ubuntu 22.04's FFmpeg 4.4.
### 改进 / Improved
- **自动适配 FFmpeg 版本**(#22,感谢 @Guancheng-Li):启动编码前检测所用 FFmpeg 支持的参数。FFmpeg 5 及以上继续使用
`-fps_mode vfr -enc_time_base 1/<fps>`;FFmpeg 4.x(如 Ubuntu 22.04)改用 `-vsync 0`。检测失败时保持新版参数。
FFmpeg 4.x 下采集卡顿后的补帧会全部编码(新版会丢弃),属于已知降级。贡献者已在 FFmpeg 4.4.2 上验证。
The host probes the FFmpeg it uses and falls back to `-vsync 0` only on FFmpeg 4.x; probe failures keep the modern arguments.
### 其他 / Other
- 新增几条只记结构的诊断日志(收到的 SOAC offer 结构、SDP 段落属性名、ice_id 是否一致),用于排查与官方控制端的互通,
不记录 SDP 内容或任何 ID。
Structure-only diagnostics for incoming offers (no SDP contents or ids).
### 下载 / Download
`uu-remote-linux-v0.1.24-x86_64-linux.tar.gz`:X11 版可执行文件(x86_64,glibc ≥ 2.35),附带 `contrib/`。
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
+18
View File
@@ -0,0 +1,18 @@
GNOME Wayland 缩放下的鼠标修复。/ Pointer fix for scaled GNOME Wayland desktops.
### 修复 / Fixed
- **GNOME Wayland 开启桌面缩放后,远程鼠标只能控制左上部分**(#23、#24,感谢 @wanglz111):Portal 后端在同一授权会话里
改用 EIS 输入,按 `mapping_id` 匹配屏幕区域,并按实际帧尺寸映射坐标;缺少映射信息或 Portal 不支持 EIS 时保留原路径。
日志不记录输入内容。X11、原生 wlroots 和 uinput 路径不变。
⚠️ 贡献者在此前的迭代上实测过 Ubuntu 26.04 / GNOME 50、单屏 4K、200% 缩放;最终提交、其他缩放比例、锁屏恢复、
断线重连和多屏尚未实机验证。
Portal input uses EIS regions mapped to the captured frame; the final commit and other scales are not yet hardware-verified.
### 构建 / Build
- `--features wayland,portal` 现在需要 `libei >= 1.1` 开发包(Debian/Ubuntu:`libei-dev`)。预编译的 X11 包不受影响。
Portal builds now require libei >= 1.1.
### 下载 / Download
`uu-remote-linux-v0.1.25-x86_64-linux.tar.gz`:X11 版可执行文件(x86_64,glibc ≥ 2.35),附带 `contrib/`。
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
+131 -2
View File
@@ -148,7 +148,7 @@ fn apply_rpc(rpc: &[WireField], settings: &watch::Sender<VideoSettings>, native:
Some(CHROMA_420) => next.chroma = CHROMA_420,
_ => {}
}
// ChooseResolutionType 3 = follow remote (native); otherwise pixel size, else logical size.
// ChooseResolutionType 3 = follow remote (native); v4 uses pixels in both size pairs.
if number(&fields, 10) == Some(3) { next.output = None; }
else if let Some((w, h)) = number(&fields, 16).zip(number(&fields, 17)).or_else(|| number(&fields, 5).zip(number(&fields, 6))) {
next.output = clamp_output(native, w, h);
@@ -180,11 +180,13 @@ fn apply_rpc(rpc: &[WireField], settings: &watch::Sender<VideoSettings>, native:
Some(out)
}
/// Message 7 ScreenSources for the single desktop: native size, scaled choices, current size.
/// Message 7 ScreenSources in pixels for capture-setting v4: native, choices, current size.
pub fn screen_sources(seq: u64, timestamp: u64, native: (u32, u32), output: Option<(u32, u32)>, name: &str) -> Result<Vec<u8>, String> {
use crate::initialization::{Screen, WinRect};
let (w, h) = (native.0 as i32, native.1 as i32);
let scaled: Vec<(i32, i32)> = scaled_sizes(native).into_iter().map(|(w, h)| (w as i32, h as i32)).collect();
// DPI_SCALE starts at version 5; the observed v4 request uses fields 5/6 as pixels.
// Keep every advertised rectangle in that space; Portal/EIS maps input independently.
let resolution = WinRect { left: 0, top: 0, width: w, height: h, pixel_width: w, pixel_height: h };
let screens = [Screen { id: 0, fps: crate::video::FPS as i32, resolution, primary: true, dpr: 1.0,
display_name: name, video_track_index: 0, screen_type: 0, builtin_screen_type: 0,
@@ -300,6 +302,133 @@ mod tests {
assert_eq!(scaled_sizes((1920, 1080)), vec![(1600, 900), (1280, 720), (960, 540), (640, 360)]);
}
#[test]
fn version_four_native_inventory_roundtrips_without_downscaling() {
assert_eq!(FEATURE_VERSION, 4);
let native = (3840, 2160);
let inventory = screen_sources(1, 2, native, None, "test").unwrap();
let envelope = decode_wire(&inventory).unwrap();
let sources = decode_wire(message(&envelope, 7).unwrap()).unwrap();
let display = decode_wire(message(&sources, 1).unwrap()).unwrap();
let rect = decode_wire(message(&display, 4).unwrap()).unwrap();
let mut body = Vec::new();
put_varint(5, number(&rect, 3).unwrap(), &mut body);
put_varint(6, number(&rect, 4).unwrap(), &mut body);
put_varint(2, QUALITY_BLURAY, &mut body);
let (tx, rx) = watch::channel(VideoSettings::default());
handle_rpc(&decode_wire(&rpc(77, 2, &body)).unwrap(), &tx, native).unwrap();
assert_eq!(rx.borrow().output, None, "native selection must preserve the full frame");
let sync = sync_payload(&rx.borrow(), native);
let fields = decode_wire(&sync).unwrap();
assert_eq!(number(&fields, 5), Some(3840));
assert_eq!(number(&fields, 6), Some(2160));
}
fn advertised_display(native: (u32, u32), output: Option<(u32, u32)>) -> Vec<u8> {
let inventory = screen_sources(1, 2, native, output, "test").unwrap();
let envelope = decode_wire(&inventory).unwrap();
let sources = decode_wire(message(&envelope, 7).unwrap()).unwrap();
message(&sources, 1).unwrap().to_vec()
}
#[test]
fn version_four_resolution_choices_and_settings_roundtrip_in_pixels() {
assert_eq!(FEATURE_VERSION, 4);
for native in [(1920, 1080), (2560, 1440), (3840, 2160), (5120, 2880),
(7680, 4320), (3440, 1440), (2160, 3840), (2257, 1505)] {
let display = advertised_display(native, None);
let fields = decode_wire(&display).unwrap();
assert!(fields.iter().any(|f| f.number == 8 && f.value == WireValue::Fixed64(1.0f64.to_le_bytes())));
assert_eq!(message(&fields, 6), message(&fields, 4));
let choices: Vec<_> = fields.iter().filter_map(|f| match f.value {
WireValue::Bytes(rect) if f.number == 3 => Some(rect), _ => None,
}).collect();
assert_eq!(choices.len(), 1 + scaled_sizes(native).len());
assert_eq!(choices[0], message(&fields, 6).unwrap());
for rect in choices {
let rect = decode_wire(rect).unwrap();
let (w, h) = (number(&rect, 3).unwrap(), number(&rect, 4).unwrap());
assert_eq!(number(&rect, 5), Some(w));
assert_eq!(number(&rect, 6), Some(h));
let selected = (w as u32, h as u32);
let expected = (selected != native).then_some(selected);
// Exercise both the observed legacy capture request and the resolution-only RPC.
for case in [2, 6] {
let (tx, rx) = watch::channel(VideoSettings::default());
let mut body = Vec::new();
let (wf, hf) = if case == 2 { (5, 6) } else { (1, 2) };
put_varint(wf, w, &mut body); put_varint(hf, h, &mut body);
if case == 2 {
put_varint(2, QUALITY_GENERAL, &mut body);
put_varint(18, 30, &mut body);
}
let response = handle_rpc(&decode_wire(&rpc(77, case, &body)).unwrap(), &tx, native).unwrap();
let response = decode_wire(&response).unwrap();
assert_eq!(message(&response, 1), Some(&[8u8, 77][..]));
assert_eq!(message(&response, 2), Some(&[][..]));
assert_eq!(rx.borrow().output, expected);
if case == 2 {
assert_eq!(rx.borrow().quality, QUALITY_GENERAL);
assert_eq!(rx.borrow().fps, 30);
}
let sync = sync_payload(&rx.borrow(), native);
let sync = decode_wire(&sync).unwrap();
for (wf, hf) in [(5, 6), (9, 10)] {
assert_eq!(number(&sync, wf), Some(w));
assert_eq!(number(&sync, hf), Some(h));
}
let updated = advertised_display(native, rx.borrow().output);
let updated = decode_wire(&updated).unwrap();
assert_eq!(message(&updated, 6), message(&fields, 6));
assert_eq!(message(&updated, 3), message(&fields, 3));
let current = decode_wire(message(&updated, 4).unwrap()).unwrap();
for (wf, hf) in [(3, 4), (5, 6)] {
assert_eq!(number(&current, wf), Some(w));
assert_eq!(number(&current, hf), Some(h));
}
// Echo synchronized dimensions with a quality/fps change, then restore native.
let mut body = Vec::new();
put_varint(5, number(&sync, 5).unwrap(), &mut body);
put_varint(6, number(&sync, 6).unwrap(), &mut body);
put_varint(2, QUALITY_BLURAY, &mut body);
put_varint(18, 60, &mut body);
handle_rpc(&decode_wire(&rpc(78, 2, &body)).unwrap(), &tx, native).unwrap();
assert_eq!(rx.borrow().output, expected);
assert_eq!(rx.borrow().quality, QUALITY_BLURAY);
assert_eq!(rx.borrow().fps, 60);
let mut native_request = Vec::new();
put_varint(5, u64::from(native.0), &mut native_request);
put_varint(6, u64::from(native.1), &mut native_request);
handle_rpc(&decode_wire(&rpc(79, 2, &native_request)).unwrap(), &tx, native).unwrap();
assert_eq!(rx.borrow().output, None);
handle_rpc(&decode_wire(&rpc(80, 2, &body)).unwrap(), &tx, native).unwrap();
assert_eq!(rx.borrow().output, expected);
handle_rpc(&decode_wire(&rpc(81, 2, &[80, 3])).unwrap(), &tx, native).unwrap();
assert_eq!(rx.borrow().output, None);
}
}
}
}
#[test]
fn explicit_pixel_size_takes_precedence_and_follow_remote_restores_native() {
let native = (3840, 2160);
let (tx, rx) = watch::channel(VideoSettings { output: Some((1280, 720)), ..Default::default() });
let mut body = Vec::new();
for (field, value) in [(5, 1920), (6, 1080), (16, 2560), (17, 1440)] {
put_varint(field, value, &mut body);
}
handle_rpc(&decode_wire(&rpc(1, 2, &body)).unwrap(), &tx, native).unwrap();
assert_eq!(rx.borrow().output, Some((2560, 1440)));
put_varint(10, 3, &mut body);
handle_rpc(&decode_wire(&rpc(2, 2, &body)).unwrap(), &tx, native).unwrap();
assert_eq!(rx.borrow().output, None);
let sync = sync_payload(&rx.borrow(), native);
let fields = decode_wire(&sync).unwrap();
assert_eq!(number(&fields, 5), Some(3840));
assert_eq!(number(&fields, 6), Some(2160));
}
#[test]
fn auto_quality_keeps_constant_quality_encoding() {
assert_eq!(VideoSettings::default().max_kbps(), None);
+1 -1
View File
@@ -62,7 +62,7 @@ pub struct Screen<'a> {
pub fps: i32,
pub resolution: WinRect,
pub primary: bool,
/// Measured pixel/logical scale; never zero or guessed from a display name.
/// Pixel/logical scale of the advertised coordinate space (1.0 for capture-setting v4).
pub dpr: f64,
pub display_name: &'a str,
pub video_track_index: i32,
+79 -7
View File
@@ -18,11 +18,13 @@ mod native {
fn uu_portal_clipboard_poll(portal: *mut c_void, text: *mut u8, capacity: usize) -> i32;
fn uu_portal_close(portal: *mut c_void);
fn uu_portal_alive(portal: *mut c_void) -> i32;
fn uu_portal_input_dispatch(portal: *mut c_void);
fn uu_portal_logical_size(portal: *mut c_void, width: *mut u32, height: *mut u32);
fn uu_portal_reset_frame(portal: *mut c_void);
fn uu_portal_capture_since(portal: *mut c_void, bgra: *mut u8, length: usize, revision: *mut u64) -> i32;
fn uu_portal_move(portal: *mut c_void, x: f64, y: f64, relative: i32) -> i32;
fn uu_portal_button(portal: *mut c_void, button: i32, pressed: i32) -> i32;
fn uu_portal_key(portal: *mut c_void, keysym: u32, pressed: i32) -> i32;
fn uu_portal_key(portal: *mut c_void, keysym: u32, keycode: i32, pressed: i32) -> i32;
}
struct Handle(NonNull<c_void>);
// The engine owns callback threads; public calls are serialized by Mutex.
@@ -32,8 +34,17 @@ mod native {
if *version == Some(super::FrameVersion(0, 0)) { return false; }
super::blank(frame); *version = Some(super::FrameVersion(0, 0)); true
}
pub struct Session { handle: Mutex<Handle>, locked: tokio::sync::watch::Receiver<Option<bool>>, was_locked: std::sync::atomic::AtomicBool, retry_at: Mutex<Option<std::time::Instant>>, pub width: u32, pub height: u32 }
pub struct Session { handle: Mutex<Handle>, locked: tokio::sync::watch::Receiver<Option<bool>>, was_locked: std::sync::atomic::AtomicBool, retry_at: Mutex<Option<std::time::Instant>>, pub width: u32, pub height: u32, logical_size: (u32, u32) }
impl Session {
pub fn logical_size(&self) -> (u32, u32) { self.logical_size }
fn check_geometry(&self, replacement: &Self) -> Result<(), String> {
if (self.width, self.height) != (replacement.width, replacement.height)
|| self.logical_size != replacement.logical_size {
Err("Portal dimensions changed; reconnect required".into())
} else {
Ok(())
}
}
pub fn is_alive(&self) -> bool {
self.handle.lock().is_ok_and(|handle| unsafe { uu_portal_alive(handle.0.as_ptr()) != 0 })
}
@@ -56,10 +67,12 @@ mod native {
}
let pointer = unsafe { uu_portal_open_persist(token.as_ref().map_or(std::ptr::null(), |v| v.as_ptr()), save_token, &mut cache as *mut _ as *mut c_void, &mut error, &mut width, &mut height) };
let handle = NonNull::new(pointer).ok_or_else(|| super::error(error))?;
let (mut logical_width, mut logical_height) = (0, 0);
unsafe { uu_portal_logical_size(handle.as_ptr(), &mut logical_width, &mut logical_height) };
// A freshly opened session holds no lock-screen frame: only an observed lock (or a
// closed stream) must discard the cached frame. Starting "locked" cleared the first
// valid frame, and a static desktop sends no new one, so the viewer stayed black (#2).
Ok(Self { handle: Mutex::new(Handle(handle)), locked: crate::session_lock::watch_locked(), was_locked: std::sync::atomic::AtomicBool::new(false), retry_at: Mutex::new(None), width, height })
Ok(Self { handle: Mutex::new(Handle(handle)), locked: crate::session_lock::watch_locked(), was_locked: std::sync::atomic::AtomicBool::new(false), retry_at: Mutex::new(None), width, height, logical_size: (logical_width, logical_height) })
}
pub fn capture(&self, frame: &mut [u8]) -> Result<(), String> {
self.capture_changed(frame, &mut None).map(|_| ())
@@ -67,6 +80,9 @@ mod native {
pub fn capture_changed(&self, frame: &mut [u8], version: &mut Option<super::FrameVersion>) -> Result<bool, String> {
if frame.len() != self.width as usize * self.height as usize * 4 { return Err(super::error(11)); }
let mut handle = self.handle.lock().map_err(|_| "Portal session lock poisoned")?;
// Drain EIS even on a static desktop so pause/disconnect and sync
// events are processed without waiting for remote input.
unsafe { uu_portal_input_dispatch(handle.0.as_ptr()) };
let state = *self.locked.borrow();
if state != Some(false) {
// Unknown state (watcher not reported yet): show nothing but keep the cached frame.
@@ -101,9 +117,7 @@ mod native {
}
};
*retry = None;
if replacement.width != self.width || replacement.height != self.height {
return Err("Portal dimensions changed; reconnect required".into());
}
self.check_geometry(&replacement)?;
*handle = replacement.handle.into_inner().map_err(|_| "Portal session lock poisoned")?;
log::info!("Portal capture session restored after closure");
}
@@ -150,7 +164,64 @@ mod native {
if pressed && *self.locked.borrow() != Some(false) { return Err("Portal input blocked while locked".into()); }
let symbol = u32::try_from(symbol).map_err(|_| "Invalid Portal keysym")?;
let handle = self.handle.lock().map_err(|_| "Portal session lock poisoned")?;
super::check(unsafe { uu_portal_key(handle.0.as_ptr(), symbol, i32::from(pressed)) })
let keycode = crate::uinput::keysym_to_evdev(u64::from(symbol)).map_or(-1, i32::from);
super::check(unsafe { uu_portal_key(handle.0.as_ptr(), symbol, keycode, i32::from(pressed)) })
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::mem::ManuallyDrop;
struct Fixture(ManuallyDrop<Session>);
impl Fixture {
fn new(physical: (u32, u32), logical_size: (u32, u32)) -> Self {
let (_, locked) = tokio::sync::watch::channel(None);
Self(ManuallyDrop::new(Session {
handle: Mutex::new(Handle(NonNull::dangling())),
locked,
was_locked: std::sync::atomic::AtomicBool::new(false),
retry_at: Mutex::new(None),
width: physical.0,
height: physical.1,
logical_size,
}))
}
fn session(&self) -> &Session { &self.0 }
}
impl Drop for Fixture {
fn drop(&mut self) {
let Session { handle, locked, was_locked, retry_at, .. } =
unsafe { ManuallyDrop::take(&mut self.0) };
let handle = handle.into_inner().unwrap_or_else(std::sync::PoisonError::into_inner);
std::mem::forget(handle);
drop((locked, was_locked, retry_at));
}
}
#[test]
fn logical_size_does_not_depend_on_handle_mutex() {
let session = Fixture::new((1920, 1080), (1280, 720));
let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
let _handle = session.session().handle.lock().unwrap();
panic!("poison test handle mutex");
}));
assert_eq!(session.session().logical_size(), (1280, 720));
}
#[test]
fn recovery_rejects_physical_or_logical_geometry_changes() {
let original = Fixture::new((1920, 1080), (1280, 720));
let same = Fixture::new((1920, 1080), (1280, 720));
let physical_changed = Fixture::new((2560, 1440), (1280, 720));
let logical_changed = Fixture::new((1920, 1080), (1600, 900));
assert!(original.session().check_geometry(same.session()).is_ok());
assert!(original.session().check_geometry(physical_changed.session()).is_err());
assert!(original.session().check_geometry(logical_changed.session()).is_err());
}
}
}
@@ -175,6 +246,7 @@ pub use native::Session as PortalSession;
pub struct PortalSession { pub width: u32, pub height: u32 }
#[cfg(not(all(target_os = "linux", feature = "portal")))]
impl PortalSession {
pub fn logical_size(&self) -> (u32, u32) { (self.width, self.height) }
pub fn clipboard_supported(&self) -> bool { false }
pub fn clipboard_ready(&self) -> bool { false }
pub fn clipboard_set(&self, _: &str) -> Result<(), String> { Err(error(2)) }
+14
View File
@@ -180,6 +180,9 @@ impl SignalingClient {
let mut accepted_refresh=0;
// Socket.IO binary event awaiting attachments: (event name, header JSON).
let mut pending_binary: Option<(String, Value)> = None;
// Relation check only: the be-controlled ice_id versus the next offer's data.ice_id.
let mut last_connect_ice: Option<String> = None;
let mut last_connect_client: Option<String> = None;
// Engine.IO 4: a client treats the connection as dead when no ping arrives within
// pingInterval + pingTimeout. A half-open TCP socket (suspend, NAT drop) otherwise
// blocks the read forever and the host silently stays offline.
@@ -294,6 +297,15 @@ impl SignalingClient {
.await;
}
"soac" => {
// Offers only: structure (keys, types, lengths), never SDP text or ids.
let kind = data.get("data").unwrap_or(data).get("type").and_then(Value::as_str);
if kind == Some("offer") {
log::info!("SOAC offer shape: {}", crate::protocol::json_shape(data, 3));
let offer_ice = data.get("data").unwrap_or(data).get("ice_id").and_then(Value::as_str);
log::info!("SOAC offer ice_id equals be-controlled ice_id: {:?}", last_connect_ice.as_deref().zip(offer_ice).map(|(a, b)| a == b));
let offer_client = data.get("client_id").and_then(Value::as_str);
log::info!("SOAC offer client_id equals be-controlled client_id: {:?}", last_connect_client.as_deref().zip(offer_client).map(|(a, b)| a == b));
}
let (target_val, client_id_opt) = if let Some(inner) = data.get("data") {
(inner.clone(), data.get("client_id").and_then(|v| v.as_str()).map(|s| s.to_string()))
} else {
@@ -356,6 +368,8 @@ impl SignalingClient {
let ice_id = ["ice_id", "iceId"].iter().find_map(|k| header.get(*k).or_else(|| header.get("data").and_then(|d| d.get(*k))))
.and_then(|v| v.as_str()).map(str::to_owned);
log::info!("be-controlled connect request: capture_type={} header_keys={:?} ice_id_present={}", capture_type, keys, ice_id.is_some());
last_connect_ice = ice_id.clone();
last_connect_client = header.get("client_id").and_then(Value::as_str).map(str::to_owned);
// Structure only (numbers, types, lengths): documents what the viewer and cloud send.
let header_shape: String = crate::protocol::json_shape(&header, 7).chars().take(8000).collect();
log::info!("Connect request shape: app_data={} header={}", crate::protocol::wire_shape(data, 3), header_shape);
+177 -10
View File
@@ -1,4 +1,7 @@
use std::sync::Arc;
use std::collections::HashMap;
use std::ffi::OsString;
use std::path::PathBuf;
use std::sync::{Arc, Mutex, OnceLock};
use std::sync::atomic::AtomicBool;
use std::time::{Duration, Instant};
use tokio::io::AsyncReadExt;
@@ -173,14 +176,106 @@ fn encoder_options(settings: &VideoSettings, encoder: Encoder, gop: &str) -> Vec
options.into_iter().map(str::to_owned).collect()
}
fn ffmpeg_command() -> Command {
match crate::config::ffmpeg_root() {
Some(root) => { let mut command = Command::new(root.join("bin/ffmpeg"));
command.env("LD_LIBRARY_PATH", root.join("lib/x86_64-linux-gnu")); command }
None => Command::new("ffmpeg"),
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
struct FfmpegSpec {
program: PathBuf,
ld_library_path: Option<OsString>,
path: Option<OsString>,
}
impl FfmpegSpec {
fn command(&self) -> Command {
let mut command = Command::new(&self.program);
if let Some(path) = &self.ld_library_path { command.env("LD_LIBRARY_PATH", path); }
if let Some(path) = &self.path { command.env("PATH", path); }
command
}
}
fn ffmpeg_spec() -> FfmpegSpec {
match crate::config::ffmpeg_root() {
Some(root) => FfmpegSpec {
program: root.join("bin/ffmpeg"),
ld_library_path: Some(root.join("lib/x86_64-linux-gnu").into_os_string()),
path: None,
},
None => FfmpegSpec {
program: PathBuf::from("ffmpeg"),
ld_library_path: None,
path: std::env::var_os("PATH"),
},
}
}
fn ffmpeg_command() -> Command { ffmpeg_spec().command() }
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum FfmpegTimingMode { Modern, Legacy }
fn help_has_option(help: &str, option: &str) -> bool {
help.lines().filter_map(|line| line.split_whitespace().next()).any(|token| {
token == option || token.starts_with(&format!("{option}:") ) || token.starts_with(&format!("{option}["))
})
}
fn timing_mode_from_help(help: &str) -> FfmpegTimingMode {
if help_has_option(help, "-fps_mode") && help_has_option(help, "-enc_time_base") {
FfmpegTimingMode::Modern
} else {
FfmpegTimingMode::Legacy
}
}
fn timing_args(mode: FfmpegTimingMode, fps: u32) -> Vec<String> {
match mode {
FfmpegTimingMode::Modern => vec!["-fps_mode".into(), "vfr".into(), "-enc_time_base".into(), format!("1/{fps}")],
FfmpegTimingMode::Legacy => vec!["-vsync".into(), "0".into()],
}
}
/// Legacy is chosen only from a completed help dump that visibly lacks the
/// modern options. A failed probe (spawn error, non-zero exit, timeout, or no
/// parseable help text) must keep the modern args: `-vsync` is deprecated
/// since FFmpeg 5.1 and may not be accepted by newer builds, so falling back
/// to it on a failed probe would kill the encoder there — worse than guessing.
fn timing_mode_from_probe(success: bool, stdout: &[u8], stderr: &[u8]) -> FfmpegTimingMode {
let mut help = Vec::with_capacity(stdout.len() + stderr.len());
help.extend_from_slice(stdout);
help.extend_from_slice(stderr);
if !success || help.is_empty() { return FfmpegTimingMode::Modern; }
timing_mode_from_help(&String::from_utf8_lossy(&help))
}
async fn probe_timing_mode(spec: &FfmpegSpec) -> FfmpegTimingMode {
let mut command = spec.command();
command.args(["-hide_banner", "-nostdin", "-h", "full"])
.kill_on_drop(true)
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped());
match tokio::time::timeout(Duration::from_secs(3), command.output()).await {
Ok(Ok(output)) => timing_mode_from_probe(output.status.success(), &output.stdout, &output.stderr),
_ => timing_mode_from_probe(false, &[], &[]),
}
}
fn timing_cache() -> &'static Mutex<HashMap<FfmpegSpec, Arc<tokio::sync::OnceCell<FfmpegTimingMode>>>> {
static CACHE: OnceLock<Mutex<HashMap<FfmpegSpec, Arc<tokio::sync::OnceCell<FfmpegTimingMode>>>>> = OnceLock::new();
CACHE.get_or_init(|| Mutex::new(HashMap::new()))
}
fn timing_cell(
cache: &Mutex<HashMap<FfmpegSpec, Arc<tokio::sync::OnceCell<FfmpegTimingMode>>>>,
spec: &FfmpegSpec,
) -> Arc<tokio::sync::OnceCell<FfmpegTimingMode>> {
let mut cache = cache.lock().expect("FFmpeg timing cache poisoned");
cache.entry(spec.clone()).or_insert_with(|| Arc::new(tokio::sync::OnceCell::const_new())).clone()
}
async fn ffmpeg_timing_mode(spec: &FfmpegSpec) -> FfmpegTimingMode {
let cell = timing_cell(timing_cache(), spec);
*cell.get_or_init(|| probe_timing_mode(spec)).await
}
/// A compiled-in encoder name does not prove that its driver can initialize.
/// Probe one synthetic 4:2:0 frame once per process before advertising HEVC.
pub async fn hevc_available() -> bool {
@@ -366,7 +461,8 @@ async fn read_encoder_with(
let cq = settings.cq().to_string();
log::info!("Desktop encoder: display={} source={} output={:?} fps={} cq={} maxrate={} encoder={} pix_fmt={} low_latency=true",display,size,settings.output,settings.fps,cq,maxrate,encoder.name_for(settings.codec),if encoder == Encoder::Vaapi { "nv12" } else { chroma_args(&settings, encoder).1 });
// A bundled FFmpeg prefix (config ffmpeg_root / UU_FFMPEG_ROOT) or `ffmpeg` on PATH.
let mut command = ffmpeg_command();
let ffmpeg = ffmpeg_spec();
let mut command = ffmpeg.command();
command.args(["-hide_banner","-loglevel","error","-nostdin"]);
if encoder == Encoder::Vaapi { command.args(["-vaapi_device", &vaapi_device()]); }
if wayland {
@@ -386,8 +482,9 @@ async fn read_encoder_with(
command.args(encoder_options(&settings, encoder, &gop));
// x11grab paces against an absolute schedule; after a capture stall it grabs
// back-to-back to "catch up" (measured 69 frames in 200ms). vfr on a 1/FPS
// timebase drops those same-slot frames instead of encoding a burst.
let time_base = format!("1/{fps}");
// timebase drops those same-slot frames instead of encoding a burst. The
// legacy -vsync 0 path (FFmpeg 4.x) passes catch-up frames straight through
// and encodes the whole burst; a known degradation on old FFmpeg.
// Native Wayland: the capture process writes straight into the encoder's stdin;
// relaying 33 MB 4K frames through this process cost a full extra copy per frame.
let mut native_capture=None;
@@ -407,7 +504,10 @@ async fn read_encoder_with(
command.stdin(source);
native_capture=Some(capture);
} else if wayland { command.stdin(std::process::Stdio::piped()); }
let mut child=command.args(["-fps_mode","vfr","-enc_time_base",&time_base,"-f",if settings.codec == VideoCodec::H265 { "hevc" } else { "h264" },"pipe:1"])
let timing = timing_args(ffmpeg_timing_mode(&ffmpeg).await, settings.fps);
let mut output_args = timing;
output_args.extend(["-f".into(), if settings.codec == VideoCodec::H265 { "hevc".into() } else { "h264".into() }, "pipe:1".into()]);
let mut child=command.args(output_args)
.kill_on_drop(true)
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::inherit())
@@ -690,6 +790,73 @@ mod tests {
drop(permit);
assert_eq!(budget.available_permits(),2);
}
#[test]
fn timing_help_requires_both_modern_options() {
let modern = " -fps_mode mode video sync method\n -enc_time_base ratio set encoder timebase";
assert_eq!(timing_mode_from_help(modern), FfmpegTimingMode::Modern);
assert_eq!(timing_mode_from_help(" -vsync parameter\n"), FfmpegTimingMode::Legacy);
assert_eq!(timing_mode_from_help(" -fps_mode mode\n"), FfmpegTimingMode::Legacy);
assert_eq!(timing_mode_from_help(" -enc_time_base ratio\n"), FfmpegTimingMode::Legacy);
assert_eq!(timing_mode_from_help(" --not-fps_mode-test\n"), FfmpegTimingMode::Legacy);
}
#[test]
fn timing_args_match_ffmpeg_generation() {
assert_eq!(timing_args(FfmpegTimingMode::Modern, 60),
vec!["-fps_mode", "vfr", "-enc_time_base", "1/60"]);
assert_eq!(timing_args(FfmpegTimingMode::Legacy, 30), vec!["-vsync", "0"]);
assert!(!timing_args(FfmpegTimingMode::Modern, 60).contains(&"-r".to_owned()));
}
#[test]
fn timing_probe_failure_keeps_modern_args() {
let modern = b" -fps_mode mode\n -enc_time_base ratio\n";
// Legacy is only confirmed from a completed help dump that lacks the options.
assert_eq!(timing_mode_from_probe(true, b"", b" -fps_mode mode\n"), FfmpegTimingMode::Legacy);
// Any probe failure keeps the modern args (-vsync is deprecated on new FFmpeg).
assert_eq!(timing_mode_from_probe(false, modern, &[]), FfmpegTimingMode::Modern);
assert_eq!(timing_mode_from_probe(false, &[], &[]), FfmpegTimingMode::Modern);
assert_eq!(timing_mode_from_probe(true, &[], &[]), FfmpegTimingMode::Modern);
assert_eq!(timing_mode_from_probe(true, modern, &[]), FfmpegTimingMode::Modern);
}
#[tokio::test]
async fn timing_cache_initializer_runs_once_for_concurrent_requests() {
use std::sync::atomic::{AtomicUsize, Ordering};
let cell = Arc::new(tokio::sync::OnceCell::new());
let calls = Arc::new(AtomicUsize::new(0));
let first = cell.clone();
let first_calls = calls.clone();
let second = cell.clone();
let second_calls = calls.clone();
let (first_mode, second_mode) = tokio::join!(
async move { *first.get_or_init(|| async {
first_calls.fetch_add(1, Ordering::SeqCst);
tokio::task::yield_now().await;
FfmpegTimingMode::Legacy
}).await },
async move { *second.get_or_init(|| async {
second_calls.fetch_add(1, Ordering::SeqCst);
tokio::task::yield_now().await;
FfmpegTimingMode::Modern
}).await },
);
assert_eq!(first_mode, second_mode);
assert_eq!(calls.load(Ordering::SeqCst), 1);
}
#[test]
fn ffmpeg_specs_separate_executable_environments() {
let path = FfmpegSpec { program: PathBuf::from("ffmpeg"), ld_library_path: None,
path: Some(OsString::from("/one")) };
let other_path = FfmpegSpec { program: PathBuf::from("ffmpeg"), ld_library_path: None,
path: Some(OsString::from("/two")) };
let bundled = FfmpegSpec { program: PathBuf::from("/opt/ffmpeg/bin/ffmpeg"),
ld_library_path: Some(OsString::from("/opt/ffmpeg/lib/x86_64-linux-gnu")), path: None };
assert_ne!(path, other_path);
assert_ne!(path, bundled);
}
#[test]
fn x264_buffer_fits_keyframes() {
assert_eq!(buffer_kbits(2000, Encoder::Nvenc), 250);
+23
View File
@@ -895,6 +895,29 @@ impl WebRtcSession {
.filter_map(|c| c.split('/').next()).collect();
codecs.dedup();
log::info!("Offer codecs: {:?}", codecs);
// SDP structure only: attribute names per section and public extmap URIs; never ufrag,
// password, fingerprint, candidate or fmtp values.
let mut sections: Vec<String> = Vec::new();
let mut current = String::from("session");
let mut names: std::collections::BTreeSet<String> = Default::default();
let mut flush = |current: &str, names: &mut std::collections::BTreeSet<String>, sections: &mut Vec<String>| {
sections.push(format!("{current}[{}]", names.iter().cloned().collect::<Vec<_>>().join(",")));
names.clear();
};
for line in sdp_str.lines() {
if let Some(m) = line.strip_prefix("m=") {
flush(&current, &mut names, &mut sections);
let mut parts = m.split_whitespace();
let kind = parts.next().unwrap_or("?");
current = format!("{kind}/{}pt", parts.skip(2).count());
} else if let Some(a) = line.strip_prefix("a=") {
let name = a.split([':', ' ']).next().unwrap_or("");
if name == "extmap" { if let Some(uri) = a.split_whitespace().nth(1) { names.insert(format!("extmap={}", uri.rsplit('/').next().unwrap_or(uri))); } }
else if !name.is_empty() && name.len() <= 32 { names.insert(name.to_owned()); }
}
}
flush(&current, &mut names, &mut sections);
log::info!("Offer SDP structure: {}", sections.join(" | "));
let offer = RTCSessionDescription::offer(sdp_str)
.map_err(|e| format!("Invalid offer: {}", e))?;
+448
View File
@@ -0,0 +1,448 @@
#define _GNU_SOURCE
#include <gio/gio.h>
#include <gio/gunixfdlist.h>
#include <assert.h>
#include <fcntl.h>
#include <poll.h>
#include <pthread.h>
#include <unistd.h>
struct harness;
static struct harness *active_harness;
static void *pump_server_during_open(void *data);
static GVariant *test_call_with_unix_fd_list_sync(GDBusConnection *connection,
const gchar *bus_name, const gchar *object_path, const gchar *interface_name,
const gchar *method_name, GVariant *parameters, const GVariantType *reply_type,
GDBusCallFlags flags, gint timeout_msec, GUnixFDList *fd_list,
GUnixFDList **out_fd_list, GCancellable *cancellable, GError **error);
#define g_dbus_connection_call_with_unix_fd_list_sync test_call_with_unix_fd_list_sync
#include "../c_engine/portal_engine.c"
#undef g_dbus_connection_call_with_unix_fd_list_sync
#include <libeis.h>
#define CAP_MASK (EI_DEVICE_CAP_POINTER | EI_DEVICE_CAP_POINTER_ABSOLUTE | \
EI_DEVICE_CAP_BUTTON | EI_DEVICE_CAP_SCROLL | EI_DEVICE_CAP_KEYBOARD)
#define EVENT_CAP_MASK (EIS_DEVICE_CAP_POINTER | EIS_DEVICE_CAP_POINTER_ABSOLUTE | \
EIS_DEVICE_CAP_BUTTON | EIS_DEVICE_CAP_SCROLL | EIS_DEVICE_CAP_KEYBOARD)
static const unsigned capabilities[] = {
EIS_DEVICE_CAP_POINTER,
EIS_DEVICE_CAP_POINTER_ABSOLUTE,
EIS_DEVICE_CAP_BUTTON,
EIS_DEVICE_CAP_SCROLL,
EIS_DEVICE_CAP_KEYBOARD,
};
struct received {
enum eis_event_type type;
double x, y;
uint32_t code;
int pressed, dx, dy;
};
struct geometry {
uint32_t width, height, logical_width, logical_height, x, y;
};
struct harness {
const struct geometry *geometry;
struct uu_portal *portal;
struct eis *server;
struct eis_client *client;
struct eis_seat *seat;
struct eis_device *device;
struct received events[64];
size_t n_events;
unsigned frames, starts, stops, diagnostics;
unsigned connect_calls;
atomic_int stop_server_pump;
pthread_t server_pump_thread;
};
static GVariant *test_call_with_unix_fd_list_sync(GDBusConnection *connection,
const gchar *bus_name, const gchar *object_path, const gchar *interface_name,
const gchar *method_name, GVariant *parameters, const GVariantType *reply_type,
GDBusCallFlags flags, gint timeout_msec, GUnixFDList *fd_list,
GUnixFDList **out_fd_list, GCancellable *cancellable, GError **error) {
(void)cancellable;
(void)error;
assert(active_harness);
assert(connection == active_harness->portal->bus);
assert(!strcmp(bus_name, "org.freedesktop.portal.Desktop"));
assert(!strcmp(object_path, "/org/freedesktop/portal/desktop"));
assert(!strcmp(interface_name, "org.freedesktop.portal.RemoteDesktop"));
assert(!strcmp(method_name, "ConnectToEIS"));
assert(g_variant_is_of_type(parameters, G_VARIANT_TYPE("(oa{sv})")));
assert(g_variant_type_equal(reply_type, G_VARIANT_TYPE("(h)")));
assert(flags == G_DBUS_CALL_FLAGS_NONE && timeout_msec == 3000);
assert(!fd_list && out_fd_list);
const char *session;
GVariant *options;
g_variant_get(parameters, "(&o@a{sv})", &session, &options);
assert(!strcmp(session, "/synthetic/session"));
assert(g_variant_n_children(options) == 0);
g_variant_unref(options);
int client_fd = eis_backend_fd_add_client(active_harness->server);
assert(client_fd >= 0);
GUnixFDList *fds = g_unix_fd_list_new();
int index = g_unix_fd_list_append(fds, client_fd, NULL);
close(client_fd);
assert(index == 0);
*out_fd_list = fds;
active_harness->connect_calls++;
g_variant_ref_sink(parameters); g_variant_unref(parameters);
/* Hand off the server only after creating the socket; libeis contexts
* must never be dispatched and mutated by different threads at once. */
assert(pthread_create(&active_harness->server_pump_thread, NULL,
pump_server_during_open, active_harness) == 0);
return g_variant_ref_sink(g_variant_new("(h)", index));
}
static void test_diagnostic(struct ei *ei, enum ei_log_priority priority,
const char *message, struct ei_log_context *context) {
(void)ei;
(void)priority;
(void)message;
(void)context;
if (active_harness) active_harness->diagnostics++;
}
static void add_device(struct harness *h) {
if (h->device) return;
h->device = eis_seat_new_device(h->seat);
assert(h->device);
eis_device_configure_type(h->device, EIS_DEVICE_TYPE_VIRTUAL);
eis_device_configure_name(h->device, "synthetic portal EIS device");
for (size_t i = 0; i < sizeof(capabilities) / sizeof(capabilities[0]); i++)
eis_device_configure_capability(h->device, capabilities[i]);
/* The first region belongs to another stream. Matching by order would
* produce valid EIS events on the wrong screen. */
struct eis_region *region = eis_device_new_region(h->device);
assert(region);
eis_region_set_offset(region, 0, 0);
eis_region_set_size(region, 100, 100);
eis_region_set_mapping_id(region, "another-screen");
eis_region_add(region);
eis_region_unref(region);
region = eis_device_new_region(h->device);
assert(region);
eis_region_set_offset(region, h->geometry->x, h->geometry->y);
eis_region_set_size(region, h->geometry->logical_width, h->geometry->logical_height);
eis_region_set_mapping_id(region, "synthetic-screen");
eis_region_add(region);
eis_region_unref(region);
eis_device_add(h->device);
eis_device_resume(h->device);
}
static void handle_server_events(struct harness *h) {
struct eis_event *event;
while ((event = eis_get_event(h->server))) {
enum eis_event_type type = eis_event_get_type(event);
if (type == EIS_EVENT_CLIENT_CONNECT) {
h->client = eis_client_ref(eis_event_get_client(event));
eis_client_connect(h->client);
h->seat = eis_client_new_seat(h->client, "synthetic-seat");
assert(h->seat);
for (size_t i = 0; i < sizeof(capabilities) / sizeof(capabilities[0]); i++)
eis_seat_configure_capability(h->seat, capabilities[i]);
eis_seat_add(h->seat);
} else if (type == EIS_EVENT_SEAT_BIND) {
unsigned bound = 0;
for (size_t i = 0; i < sizeof(capabilities) / sizeof(capabilities[0]); i++) {
if (eis_event_seat_has_capability(event, capabilities[i])) bound |= capabilities[i];
}
if (!h->device) {
assert(bound == EVENT_CAP_MASK);
add_device(h);
}
} else if (type == EIS_EVENT_FRAME) {
h->frames++;
} else if (type == EIS_EVENT_DEVICE_START_EMULATING) {
h->starts++;
} else if (type == EIS_EVENT_DEVICE_STOP_EMULATING) {
h->stops++;
} else if (type == EIS_EVENT_POINTER_MOTION || type == EIS_EVENT_POINTER_MOTION_ABSOLUTE ||
type == EIS_EVENT_BUTTON_BUTTON || type == EIS_EVENT_SCROLL_DISCRETE ||
type == EIS_EVENT_KEYBOARD_KEY) {
assert(h->n_events < sizeof(h->events) / sizeof(h->events[0]));
struct received *got = &h->events[h->n_events++];
got->type = type;
switch (type) {
case EIS_EVENT_POINTER_MOTION:
got->x = eis_event_pointer_get_dx(event);
got->y = eis_event_pointer_get_dy(event);
break;
case EIS_EVENT_POINTER_MOTION_ABSOLUTE:
got->x = eis_event_pointer_get_absolute_x(event);
got->y = eis_event_pointer_get_absolute_y(event);
break;
case EIS_EVENT_BUTTON_BUTTON:
got->code = eis_event_button_get_button(event);
got->pressed = eis_event_button_get_is_press(event);
break;
case EIS_EVENT_SCROLL_DISCRETE:
got->dx = eis_event_scroll_get_discrete_dx(event);
got->dy = eis_event_scroll_get_discrete_dy(event);
break;
case EIS_EVENT_KEYBOARD_KEY:
got->code = eis_event_keyboard_get_key(event);
got->pressed = eis_event_keyboard_get_key_is_press(event);
break;
default:
break;
}
}
eis_event_unref(event);
}
}
static void pump_server(struct harness *h) {
eis_dispatch(h->server);
handle_server_events(h);
}
static void pump(struct harness *h) {
pump_server(h);
uu_portal_input_dispatch(h->portal);
pump_server(h);
}
static void *pump_server_during_open(void *data) {
struct harness *h = data;
while (!atomic_load(&h->stop_server_pump)) {
pump_server(h);
g_usleep(1000);
}
return NULL;
}
static int ready(struct harness *h) {
return h->portal->ei_devices && h->device && h->starts > 0;
}
static int paused(struct harness *h) {
return !h->portal->ei_devices;
}
static int disconnected(struct harness *h) {
return atomic_load(&h->portal->ei_failed);
}
static void wait_for(struct harness *h, int (*condition)(struct harness *)) {
gint64 deadline = g_get_monotonic_time() + 3000000;
while (!condition(h) && g_get_monotonic_time() < deadline) {
pump(h);
g_usleep(1000);
}
assert(condition(h));
}
static void clear_events(struct harness *h) {
h->n_events = 0;
h->frames = 0;
}
static void wait_for_input(struct harness *h) {
gint64 deadline = g_get_monotonic_time() + 1000000;
while (!h->n_events && g_get_monotonic_time() < deadline) {
pump(h);
g_usleep(1000);
}
assert(h->n_events);
assert(h->frames > 0);
}
static void pause_resume(struct harness *h) {
/* libeis 1.5 pauses only a resumed device; pause while emulating is a
* no-op. End the client transaction before exercising pause/resume. */
assert(h->portal->ei_devices);
ei_device_stop_emulating(h->portal->ei_devices->data);
gint64 deadline = g_get_monotonic_time() + 3000000;
while (!h->stops && g_get_monotonic_time() < deadline) {
pump(h);
g_usleep(1000);
}
assert(h->stops == 1);
eis_device_pause(h->device);
deadline = g_get_monotonic_time() + 3000000;
while (h->portal->ei_devices && g_get_monotonic_time() < deadline) {
pump(h);
g_usleep(1000);
}
assert(!h->portal->ei_devices);
eis_device_resume(h->device);
deadline = g_get_monotonic_time() + 3000000;
while ((!h->portal->ei_devices || h->starts < 2) && g_get_monotonic_time() < deadline) {
pump(h);
g_usleep(1000);
}
assert(h->portal->ei_devices && h->starts == 2 && !h->diagnostics);
}
static void run_geometry(const struct geometry *geometry) {
struct harness h = {.geometry = geometry};
h.portal = calloc(1, sizeof(*h.portal));
assert(h.portal);
pthread_mutex_init(&h.portal->lock, NULL);
pthread_cond_init(&h.portal->changed, NULL);
h.portal->width = geometry->width;
h.portal->height = geometry->height;
h.portal->logical_width = geometry->logical_width;
h.portal->logical_height = geometry->logical_height;
h.portal->mapping_id = g_strdup("synthetic-screen");
h.portal->session = strdup("/synthetic/session");
h.portal->absolute_stream_pixels = 1;
h.server = eis_new(NULL);
assert(h.server && eis_setup_backend_fd(h.server) == 0);
active_harness = &h;
int scaled = geometry->width != geometry->logical_width || geometry->height != geometry->logical_height;
int open_result = scaled ? prepare_input(h.portal) : portal_eis_open(h.portal);
atomic_store(&h.stop_server_pump, 1);
assert(pthread_join(h.server_pump_thread, NULL) == 0);
assert(open_result == 0 && h.connect_calls == 1);
ei_log_set_priority(h.portal->ei, EI_LOG_PRIORITY_ERROR);
ei_log_set_handler(h.portal->ei, test_diagnostic);
wait_for(&h, ready);
assert(h.portal->ei_devices);
struct ei_device *device = h.portal->ei_devices->data;
assert(((ei_device_has_capability(device, EI_DEVICE_CAP_POINTER) ? EI_DEVICE_CAP_POINTER : 0) |
(ei_device_has_capability(device, EI_DEVICE_CAP_POINTER_ABSOLUTE) ? EI_DEVICE_CAP_POINTER_ABSOLUTE : 0) |
(ei_device_has_capability(device, EI_DEVICE_CAP_BUTTON) ? EI_DEVICE_CAP_BUTTON : 0) |
(ei_device_has_capability(device, EI_DEVICE_CAP_SCROLL) ? EI_DEVICE_CAP_SCROLL : 0) |
(ei_device_has_capability(device, EI_DEVICE_CAP_KEYBOARD) ? EI_DEVICE_CAP_KEYBOARD : 0)) == CAP_MASK);
struct ei_region *region = ei_device_get_region(device, 1);
assert(region && !strcmp(ei_region_get_mapping_id(region), "synthetic-screen"));
assert(ei_region_get_x(region) == geometry->x && ei_region_get_y(region) == geometry->y);
assert(ei_region_get_width(region) == geometry->logical_width && ei_region_get_height(region) == geometry->logical_height);
clear_events(&h);
assert(uu_portal_move(h.portal, 0, 0, 0) == 0);
wait_for_input(&h);
assert(h.events[0].type == EIS_EVENT_POINTER_MOTION_ABSOLUTE);
assert(h.events[0].x == geometry->x && h.events[0].y == geometry->y);
clear_events(&h);
assert(uu_portal_move(h.portal, geometry->width / 2.0, geometry->height / 2.0, 0) == 0);
wait_for_input(&h);
assert(h.events[0].type == EIS_EVENT_POINTER_MOTION_ABSOLUTE);
assert(h.events[0].x == geometry->x + geometry->logical_width / 2.0);
assert(h.events[0].y == geometry->y + geometry->logical_height / 2.0);
clear_events(&h);
assert(uu_portal_move(h.portal, geometry->width - 1, geometry->height - 1, 0) == 0);
wait_for_input(&h);
assert(h.events[0].type == EIS_EVENT_POINTER_MOTION_ABSOLUTE);
double right = geometry->x + geometry->logical_width -
(double)geometry->logical_width / geometry->width;
double bottom = geometry->y + geometry->logical_height -
(double)geometry->logical_height / geometry->height;
assert(fabs(h.events[0].x - right) < 0.001 && fabs(h.events[0].y - bottom) < 0.001);
clear_events(&h);
assert(uu_portal_move(h.portal, geometry->width - 1, 0, 0) == 0);
wait_for_input(&h);
assert(h.events[0].type == EIS_EVENT_POINTER_MOTION_ABSOLUTE);
assert(fabs(h.events[0].x - right) < 0.001 && h.events[0].y == geometry->y);
clear_events(&h);
assert(uu_portal_move(h.portal, 0, geometry->height - 1, 0) == 0);
wait_for_input(&h);
assert(h.events[0].type == EIS_EVENT_POINTER_MOTION_ABSOLUTE);
assert(h.events[0].x == geometry->x && fabs(h.events[0].y - bottom) < 0.001);
assert(uu_portal_move(h.portal, geometry->width, geometry->height, 0) == 11);
assert(uu_portal_move(h.portal, -1, -1, 0) == 11);
clear_events(&h);
assert(uu_portal_move(h.portal, geometry->width / 8.0, geometry->height / 8.0, 1) == 0);
wait_for_input(&h);
assert(h.events[0].type == EIS_EVENT_POINTER_MOTION);
assert(h.events[0].x == geometry->logical_width / 8.0);
assert(h.events[0].y == geometry->logical_height / 8.0);
clear_events(&h);
assert(uu_portal_key(h.portal, 'a', 30, 1) == 0);
wait_for_input(&h);
assert(h.events[0].type == EIS_EVENT_KEYBOARD_KEY);
assert(h.events[0].code == 30 && h.events[0].pressed);
clear_events(&h);
assert(uu_portal_button(h.portal, 1, 1) == 0);
wait_for_input(&h);
assert(h.events[0].type == EIS_EVENT_BUTTON_BUTTON);
assert(h.events[0].code == 0x110 && h.events[0].pressed);
clear_events(&h);
assert(uu_portal_button(h.portal, 4, 1) == 0);
wait_for_input(&h);
assert(h.events[0].type == EIS_EVENT_SCROLL_DISCRETE);
assert(h.events[0].dx == 0 && h.events[0].dy == -120);
clear_events(&h);
assert(uu_portal_key(h.portal, 'a', 30, 0) == 0);
wait_for_input(&h);
assert(h.events[0].type == EIS_EVENT_KEYBOARD_KEY);
assert(h.events[0].code == 30 && !h.events[0].pressed);
clear_events(&h);
assert(uu_portal_button(h.portal, 1, 0) == 0);
wait_for_input(&h);
assert(h.events[0].type == EIS_EVENT_BUTTON_BUTTON);
assert(h.events[0].code == 0x110 && !h.events[0].pressed);
pause_resume(&h);
clear_events(&h);
assert(uu_portal_move(h.portal, geometry->width - 1, geometry->height - 1, 0) == 0);
wait_for_input(&h);
assert(h.events[0].type == EIS_EVENT_POINTER_MOTION_ABSOLUTE);
assert(fabs(h.events[0].x - right) < 0.001 && fabs(h.events[0].y - bottom) < 0.001);
eis_device_remove(h.device);
wait_for(&h, paused);
clear_events(&h);
assert(uu_portal_move(h.portal, 100, 100, 0) == 9);
assert(uu_portal_key(h.portal, 'a', 30, 1) == 9);
assert(uu_portal_button(h.portal, 1, 1) == 9);
pump(&h);
assert(h.n_events == 0);
eis_client_disconnect(h.client);
wait_for(&h, disconnected);
assert(!uu_portal_alive(h.portal));
clear_events(&h);
assert(uu_portal_move(h.portal, 100, 100, 0) == 9);
assert(uu_portal_key(h.portal, 'a', 30, 1) == 9);
assert(uu_portal_button(h.portal, 1, 1) == 9);
pump(&h);
assert(h.n_events == 0);
assert(!h.diagnostics);
uu_portal_close(h.portal);
active_harness = NULL;
if (h.device) eis_device_unref(h.device);
if (h.seat) eis_seat_unref(h.seat);
if (h.client) eis_client_unref(h.client);
eis_unref(h.server);
}
int main(void) {
const struct geometry cases[] = {
{1920, 1080, 1920, 1080, 0, 0}, /* 100% */
{2560, 1440, 2048, 1152, 320, 90}, /* 125% */
{2560, 1440, 1707, 960, 0, 0}, /* 150%, rounded logical size */
{3840, 2160, 2560, 1440, 100, 200}, /* 150% */
{3840, 2160, 2194, 1234, 0, 0}, /* 175%, rounded logical size */
{3840, 2160, 1920, 1080, 320, 90}, /* 200% */
{5120, 2880, 2560, 1440, 0, 0}, /* 5K */
{7680, 4320, 3840, 2160, 7680, 0}, /* 8K, nonzero origin */
{3440, 1440, 2293, 960, 0, 1080}, /* ultrawide */
{2160, 3840, 1080, 1920, 1920, 0}, /* portrait */
{2257, 1505, 1806, 1204, 0, 0}, /* odd frame dimensions */
};
for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) run_geometry(&cases[i]);
puts("Portal EIS integration checks passed: 11 geometries");
return 0;
}
+55 -2
View File
@@ -1,7 +1,7 @@
#define _GNU_SOURCE
/* Protocol-independent C bounds/lifecycle checks; never requests consent. */
#include <assert.h>
#include "portal_engine.c"
#include "../c_engine/portal_engine.c"
static void clipboard_bounds(void) {
int fds[2]; uint8_t bytes[8]={0};
assert(pipe2(fds,O_NONBLOCK)==0);
@@ -14,8 +14,61 @@ static void clipboard_bounds(void) {
assert(clipboard_io(fds[1],bytes,1,1)==-1); close(fds[1]);
assert(clipboard_io(-1,bytes,0,1)==0);
}
static void capture_with_optional_geometry(int has_size) {
struct uu_portal *p = calloc(1, sizeof(*p));
assert(p);
pthread_mutex_init(&p->lock, NULL);
pthread_cond_init(&p->changed, NULL);
p->width = p->height = 2;
p->absolute_stream_pixels = 1;
GVariantBuilder properties, streams, result;
g_variant_builder_init(&properties, G_VARIANT_TYPE_VARDICT);
if (has_size) g_variant_builder_add(&properties, "{sv}", "size", g_variant_new("(ii)", 1, 1));
g_variant_builder_init(&streams, G_VARIANT_TYPE("a(ua{sv})"));
g_variant_builder_add(&streams, "(u@a{sv})", 42u, g_variant_builder_end(&properties));
g_variant_builder_init(&result, G_VARIANT_TYPE_VARDICT);
g_variant_builder_add(&result, "{sv}", "devices", g_variant_new_uint32(3));
g_variant_builder_add(&result, "{sv}", "streams", g_variant_builder_end(&streams));
GVariant *reply = g_variant_ref_sink(g_variant_builder_end(&result));
assert(read_stream_result(p, reply) == 0 && p->node == 42);
g_variant_unref(reply);
p->frame_length = 16;
p->frame = calloc(1, p->frame_length);
assert(p->frame);
p->sequence = 1;
uint8_t pixels[16];
/* Optional compositor metadata must not gate capture/uinput. */
uu_portal_input_dispatch(p);
assert(!p->ei && uu_portal_alive(p));
assert(uu_portal_capture(p, pixels, sizeof(pixels)) == 0);
uint32_t width, height;
uu_portal_logical_size(p, &width, &height);
assert(width == (has_size ? 1 : 2) && height == width);
if (!has_size) assert(uu_portal_move(p, 1, 1, 0) == 11);
assert(!p->ei && uu_portal_alive(p));
uu_portal_close(p);
}
static void authorization_still_required(void) {
const unsigned cases[][2] = {{0,1}, {1,1}, {2,1}, {3,0}, {3,2}};
for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {
GVariantBuilder streams, result;
g_variant_builder_init(&streams, G_VARIANT_TYPE("a(ua{sv})"));
for (unsigned n = 0; n < cases[i][1]; n++)
g_variant_builder_add(&streams, "(u@a{sv})", n + 42, empty_options());
g_variant_builder_init(&result, G_VARIANT_TYPE_VARDICT);
g_variant_builder_add(&result, "{sv}", "devices", g_variant_new_uint32(cases[i][0]));
g_variant_builder_add(&result, "{sv}", "streams", g_variant_builder_end(&streams));
GVariant *reply = g_variant_ref_sink(g_variant_builder_end(&result));
struct uu_portal p = {0};
assert(read_stream_result(&p, reply) == 6);
g_variant_unref(reply);
}
}
int main(void) {
clipboard_bounds();
capture_with_optional_geometry(0);
capture_with_optional_geometry(1);
authorization_still_required();
struct uu_portal *p = calloc(1, sizeof(*p));
assert(p);
pthread_mutex_init(&p->lock, NULL);
@@ -88,7 +141,7 @@ int main(void) {
assert(uu_portal_clipboard_poll(p,NULL,CLIP_LIMIT)==-1);
p->error=8;
assert(!uu_portal_alive(p));
assert(uu_portal_key(p, 'a', 1)==9); /* no input into an unusable stream */
assert(uu_portal_key(p, 'a', 30, 1)==9); /* no input into an unusable stream */
p->error=0;
p->clipboard_enabled=1;
assert(uu_portal_clipboard_supported(p));
+141
View File
@@ -0,0 +1,141 @@
#define _GNU_SOURCE
/* Stub only the D-Bus I/O boundary; no real session bus or consent requests. */
#include <assert.h>
#include <gio/gio.h>
#include <sys/socket.h>
static GVariant *test_call(GDBusConnection *, const gchar *, const gchar *, const gchar *,
const gchar *, GVariant *, const GVariantType *, GDBusCallFlags, gint, GCancellable *, GError **);
static GVariant *test_connect(GDBusConnection *, const gchar *, const gchar *, const gchar *,
const gchar *, GVariant *, const GVariantType *, GDBusCallFlags, gint,
GUnixFDList *, GUnixFDList **, GCancellable *, GError **);
#define g_dbus_connection_call_sync test_call
#define g_dbus_connection_call_with_unix_fd_list_sync test_connect
#include "../c_engine/portal_engine.c"
#undef g_dbus_connection_call_sync
#undef g_dbus_connection_call_with_unix_fd_list_sync
enum response_mode { UNKNOWN_METHOD, NOT_SUPPORTED, TEMPORARY_FAILURE, NO_FDS, BAD_INDEX, DISCONNECTED };
static enum response_mode mode;
static unsigned connects, legacy_calls;
static double last_x, last_y;
static GVariant *test_call(GDBusConnection *bus, const gchar *dest, const gchar *path,
const gchar *interface, const gchar *method, GVariant *parameters,
const GVariantType *type, GDBusCallFlags flags, gint timeout,
GCancellable *cancel, GError **error) {
assert(!strcmp(interface, REMOTE));
assert(!strcmp(method, "NotifyKeyboardKeysym") || !strcmp(method, "NotifyPointerButton") ||
!strcmp(method, "NotifyPointerAxisDiscrete") || !strcmp(method, "NotifyPointerMotion") ||
!strcmp(method, "NotifyPointerMotionAbsolute"));
if (!strcmp(method, "NotifyPointerMotion") || !strcmp(method, "NotifyPointerMotionAbsolute")) {
unsigned offset = !strcmp(method, "NotifyPointerMotion") ? 2 : 3;
GVariant *x = g_variant_get_child_value(parameters, offset);
GVariant *y = g_variant_get_child_value(parameters, offset + 1);
last_x = g_variant_get_double(x); last_y = g_variant_get_double(y);
g_variant_unref(x); g_variant_unref(y);
}
legacy_calls++;
g_variant_ref_sink(parameters); g_variant_unref(parameters);
return g_variant_ref_sink(g_variant_new("()"));
}
static GVariant *test_connect(GDBusConnection *bus, const gchar *dest, const gchar *path,
const gchar *interface, const gchar *method, GVariant *parameters,
const GVariantType *type, GDBusCallFlags flags, gint timeout,
GUnixFDList *in_fds, GUnixFDList **out_fds, GCancellable *cancel, GError **error) {
assert(!strcmp(method, "ConnectToEIS") && !strcmp(interface, REMOTE));
assert(g_variant_is_of_type(parameters, G_VARIANT_TYPE("(oa{sv})")));
assert(g_variant_type_equal(type, G_VARIANT_TYPE("(h)")));
connects++;
g_variant_ref_sink(parameters); g_variant_unref(parameters);
if (mode <= TEMPORARY_FAILURE) {
int code = mode == UNKNOWN_METHOD ? G_DBUS_ERROR_UNKNOWN_METHOD :
mode == NOT_SUPPORTED ? G_DBUS_ERROR_NOT_SUPPORTED : G_DBUS_ERROR_TIMED_OUT;
g_set_error_literal(error, G_DBUS_ERROR, code, "synthetic EIS response");
return NULL;
}
if (mode != NO_FDS) *out_fds = g_unix_fd_list_new();
if (mode == DISCONNECTED) {
int sockets[2];
assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sockets) == 0);
close(sockets[1]);
assert(g_unix_fd_list_append(*out_fds, sockets[0], NULL) == 0);
close(sockets[0]);
}
return g_variant_ref_sink(g_variant_new("(h)", 0));
}
static struct uu_portal *session(int scaled, int gnome, int mapping) {
struct uu_portal *p = calloc(1, sizeof(*p));
assert(p);
pthread_mutex_init(&p->lock, NULL); pthread_cond_init(&p->changed, NULL);
p->width = 3840; p->height = 2160;
p->logical_width = scaled ? 1920 : 3840; p->logical_height = scaled ? 1080 : 2160;
p->absolute_stream_pixels = gnome;
p->session = g_strdup("/synthetic/session");
if (mapping) p->mapping_id = g_strdup("synthetic-screen");
connects = legacy_calls = 0;
return p;
}
static void legacy_input(struct uu_portal *p) {
assert(uu_portal_key(p, 'a', 30, 1) == 0);
assert(uu_portal_key(p, 'a', 30, 0) == 0);
assert(uu_portal_button(p, 1, 1) == 0);
assert(uu_portal_button(p, 1, 0) == 0);
assert(uu_portal_button(p, 4, 1) == 0);
assert(uu_portal_move(p, 8, 4, 1) == 0);
assert(last_x == (double)8 * p->logical_width / p->width);
assert(last_y == (double)4 * p->logical_height / p->height);
assert(uu_portal_move(p, 1920, 1080, 0) == 0);
assert(last_x == (p->absolute_stream_pixels ? 1920 : 960));
assert(last_y == (p->absolute_stream_pixels ? 1080 : 540));
assert(legacy_calls == 7 && uu_portal_alive(p) && !p->ei);
}
int main(void) {
struct uu_portal *p = session(1, 1, 0);
legacy_input(p);
assert(!connects && p->ei_unavailable);
uu_portal_close(p);
for (int response = UNKNOWN_METHOD; response <= NOT_SUPPORTED; response++) {
mode = response;
p = session(1, 1, 1);
legacy_input(p);
assert(connects == 1 && p->ei_unavailable);
uu_portal_close(p);
}
p = session(0, 1, 1); /* Unscaled GNOME keeps Notify*. */
legacy_input(p);
assert(!connects);
uu_portal_close(p);
p = session(1, 0, 1); /* KDE keeps its compositor-logical mapping. */
legacy_input(p);
assert(!connects);
uu_portal_close(p);
mode = TEMPORARY_FAILURE;
p = session(1, 1, 1);
assert(uu_portal_key(p, 'a', 30, 1) == 9);
assert(connects == 1 && !legacy_calls && !uu_portal_alive(p) && !p->ei_unavailable);
assert(uu_portal_key(p, 'a', 30, 0) == 9 && connects == 1);
uu_portal_close(p);
mode = UNKNOWN_METHOD; /* A replacement session can select its input backend afresh. */
p = session(1, 1, 1);
legacy_input(p);
assert(connects == 1);
uu_portal_close(p);
for (int response = NO_FDS; response <= DISCONNECTED; response++) {
mode = response;
p = session(1, 1, 1);
assert(uu_portal_move(p, 10, 10, 0) == 9);
assert(!uu_portal_alive(p));
assert(uu_portal_key(p, 'a', 30, 1) == 9);
assert(uu_portal_button(p, 1, 1) == 9);
assert(connects == 1 && !legacy_calls); /* Never mix Notify* after success. */
uu_portal_close(p);
}
puts("Portal input capability/failure checks passed");
return 0;
}