mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 08:50:40 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9c43897c7 | ||
|
|
9fe1351de1 | ||
|
|
c0b0ca6afb | ||
|
|
11097b5847 | ||
|
|
6a0cd5bda6 |
No files matched your search
@@ -125,6 +125,7 @@ viewer does not reconnect them automatically.
|
||||
| `UU_X11_MULTISCREEN=1`, `UU_X11_OUTPUT` | X11: advertise each RandR monitor (`xrandr --listmonitors`, read once at start; primary or `UU_X11_OUTPUT` is id 0) through the same screen-switch path as `UU_WAYLAND_MULTISCREEN` (`wayland::outputs`/`select`). x11grab reads `display+x,y` at the monitor size, XTest/uinput absolute input adds the monitor offset, the in-process engine and `desktop_mode` resize are skipped (分辨率 scales). Needs two or more monitors |
|
||||
| `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_TOUCH_INPUT` | Android/iOS controllers (connect header `controller_platform` 2/3) send a finger as a left-button drag at absolute positions. Default on the portal backend (gesture): per press, moving past 12 px within 450 ms scrolls (`NotifyPointerAxis` / EIS scroll, content follows the finger, `finish` on release), holding still selects with button 1 down, a short press clicks; needs no touchscreen consent. `touch`: replay as one finger on the portal touchscreen (`NotifyTouch*` / EIS touch; requested where `AvailableDeviceTypes` offers it; consents saved before touch support restore keyboard+pointer only, so the first mobile drag asks once per run in the background via `PortalSession::upgrade_touch`, swapped in only with the touchscreen granted for the same monitor; the saved consent is never removed first). `0`: plain mouse drags |
|
||||
| `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) |
|
||||
|
||||
Generated
+1
-1
@@ -2772,7 +2772,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "uu-remote-linux"
|
||||
version = "0.2.40"
|
||||
version = "0.2.41"
|
||||
dependencies = [
|
||||
"ab_glyph",
|
||||
"async-trait",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "uu-remote-linux"
|
||||
version = "0.2.40"
|
||||
version = "0.2.41"
|
||||
edition = "2021"
|
||||
default-run = "uuremote-server"
|
||||
authors = ["uu-remote-linux contributors"]
|
||||
|
||||
+3
-1
@@ -100,7 +100,9 @@ plugins, permissions and encoders only, no account data, tokens or addresses) an
|
||||
Wayland limits: captures one screen by default; Hyprland can enable monitor switching as described below. Resolution is fixed. The native Hyprland backend now pipelines two shm screencopy buffers and passes the viewer's requested fps to both capture pacing and the encoder. Actual fps remains limited by the compositor, rendering and readback (the old serial path measured about 16–22 fps at 2560x1600; the pipeline is VM-measured only, not a hardware guarantee). The portal backend does not support dynamic resolution; see below for GNOME wake and lock recovery; 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.
|
||||
|
||||
**Mobile IME typing and clipboard on Wayland**: Mobile IME text (`text_input`) on Wayland is typed through spare keycodes on wlroots compositors. On Portal (GNOME / KDE) or compositors where keycodes are exhausted, it automatically falls back to typing via "system clipboard write + `Shift+Insert` (or `UU_WAYLAND_PASTE_KEY=ctrl_v`)". **Note**: This fallback replaces the host's existing clipboard contents and may echo back to the viewer's clipboard via two-way sync; set `UU_WAYLAND_TEXT=0` to completely disable Wayland mobile text input and clipboard paste fallback.
|
||||
**Touch from mobile viewers (GNOME)**: in touch mode the Android/iOS viewers send a finger as a left-button drag, which on a desktop selects text. On the portal backend the host decides per press: a finger that moves more than a few pixels within 0.45 s scrolls smoothly (`NotifyPointerAxis`; the content follows the finger, also in terminals, and the last event lets clients coast), one held still selects like a mouse drag, and a short press clicks. This needs no touchscreen consent. `UU_TOUCH_INPUT=touch` instead replays drags as one finger on the portal touchscreen, which the host requests where the portal offers it; a consent saved before touch support restores keyboard and pointer only, so the first drag then asks the host once more in the background (the GNOME share dialog, which the phone also sees; it closes after the consent timeout), and an approval for the same monitor switches to touch without reconnecting. The saved consent is never removed beforehand, and the host asks at most once per run. `UU_TOUCH_INPUT=0` keeps mouse drags.
|
||||
|
||||
**Mobile IME typing and clipboard on Wayland**: Mobile IME text (`text_input`) on Wayland is typed through spare keycodes on wlroots compositors. On GNOME (Portal) printable ASCII is typed as keysyms when the active input source is a Latin xkb layout (Mutter picks the key and Shift level); other text, KDE and compositors where keycodes are exhausted fall back to "system clipboard write + `Shift+Insert` (or `UU_WAYLAND_PASTE_KEY=ctrl_v`)". VTE terminals paste the PRIMARY selection on `Shift+Insert`, which is why ASCII is typed instead. **Note**: This fallback replaces the host's existing clipboard contents and may echo back to the viewer's clipboard via two-way sync; set `UU_WAYLAND_TEXT=0` to completely disable Wayland mobile text input and clipboard paste fallback.
|
||||
|
||||
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 keeps the encoder frame dimensions fixed but accepts logical-size changes after scaling. On GNOME, a display-change notification enables earlier recovery when previously streaming Portal capture remains paused without a valid format for a 200 ms grace after both conditions are present. Healthy renegotiation cancels the early check; repeated notifications do not postpone the same interruption. The five-second fallback remains without a related notification. Static video and valid-format pauses do not trigger recovery. Tested while connected on Ubuntu 26.04, GNOME Wayland, one 3840x2160 display: 200% -> 166.67% -> 200%, with continuously updating video and full-screen pointer control after recovery. Switching briefly freezes and goes black before recovering; five seconds is the fallback threshold, not total recovery time. See [#35](../../pull/35) for timing measurements and validation limits. 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.
|
||||
|
||||
|
||||
@@ -90,7 +90,9 @@ GNOME Wayland 的 Portal/EIS 路径已在 Ubuntu 26.04、GNOME 50、单屏 4K/20
|
||||
|
||||
Wayland 下的限制:默认采集单屏,Hyprland 可按上文启用切屏;分辨率固定;Hyprland 原生后端默认使用双缓冲流水线 shm screencopy,控制端帧率设置会同步到采集节拍和编码器,但实际帧率仍受合成器、渲染和读回速度限制(旧串行路径在 2560x1600 曾测得约 16~22 帧;流水线只在虚拟机里测量过,不代表实机保证);portal 后端暂不支持动态分辨率;GNOME 的屏幕唤醒与锁屏恢复见下;剪贴板只在控制端的远控窗口处于前台时同步。
|
||||
|
||||
**Wayland 手机输入法打字与剪贴板**:Wayland 下手机端输入法提交的文字(`text_input`)优先通过虚拟键盘空闲键码上屏;在 Portal(GNOME / KDE)或键码耗尽的环境下,自动通过「写系统剪贴板 + 触发 `Shift+Insert`(或 `UU_WAYLAND_PASTE_KEY=ctrl_v`)」兜底粘贴。**注意**:此兜底过程会覆盖被控端原有的剪贴板内容,且会被双向同步回传到控制端剪贴板;设置 `UU_WAYLAND_TEXT=0` 可完全关闭 Wayland 文字输入及该粘贴兜底。
|
||||
**手机控制端触控(GNOME)**:Android/iOS 控制端在触控模式下把手指当作左键拖动发送,在桌面上会选中文字。Portal 后端下被控端按每次按下判断:0.45 秒内移动超过几个像素即平滑滚动(`NotifyPointerAxis`,内容跟随手指,终端里同样有效,最后一个事件让客户端可以惯性滑动);按住不动则像鼠标拖动一样选中;短按为点击。此模式无需触摸屏授权。`UU_TOUCH_INPUT=touch` 改为把拖动按单指触控在 Portal 触摸屏上重放,门户提供触摸屏设备类型时被控端会一并申请;此前保存的授权只恢复键盘和指针,因此第一次拖动时会在后台再申请一次(GNOME 共享对话框,手机画面中也能看到,授权超时后自动关闭),同意同一显示器后无需重连即切换为触控。不会预先删除已保存的授权,每次运行最多申请一次。`UU_TOUCH_INPUT=0` 保持鼠标拖动。
|
||||
|
||||
**Wayland 手机输入法打字与剪贴板**:Wayland 下手机端输入法提交的文字(`text_input`)优先通过虚拟键盘空闲键码上屏;GNOME(Portal)下,当前输入源为拉丁 xkb 布局时,可打印 ASCII 直接以 keysym 输入(由 Mutter 选择按键和 Shift 层级);其他文字、KDE 以及键码耗尽的环境自动通过「写系统剪贴板 + 触发 `Shift+Insert`(或 `UU_WAYLAND_PASTE_KEY=ctrl_v`)」兜底粘贴。VTE 终端的 `Shift+Insert` 粘贴的是 PRIMARY 选区,因此 ASCII 改为直接输入。**注意**:此兜底过程会覆盖被控端原有的剪贴板内容,且会被双向同步回传到控制端剪贴板;设置 `UU_WAYLAND_TEXT=0` 可完全关闭 Wayland 文字输入及该粘贴兜底。
|
||||
|
||||
GNOME 缩放桌面在使用 Portal 原生键鼠时,若支持 `ConnectToEIS` 和屏幕 `mapping_id`,通过同一授权会话的 EIS 接口注入输入,按匹配的区域与实际帧尺寸分别映射横纵坐标,没有固定分辨率或缩放倍率,可避免 `NotifyPointerMotionAbsolute` 在缩放时拒绝坐标。Portal 构建需要 libei ≥ 1.1。缺少 EIS 支持时保留旧输入路径及其既有缩放限制;其他初始化错误会明确报告并触发会话恢复。EIS 连接成功后全部输入统一使用 EIS。只采集画面或使用 uinput 时不会初始化 EIS;缺少可选的逻辑尺寸也不阻断采集。键盘沿用项目现有的 Windows VK → evdev 映射。恢复时保持编码器的采集帧尺寸不变,允许缩放后的逻辑尺寸变化。GNOME 显示配置变化后,已推流的 Portal 采集若持续「暂停且无有效格式」,会在关联通知后的 200 毫秒宽限结束后提前进入现有恢复流程;正常重协商恢复会取消提前判定,连续通知不会推迟同次异常的判定。未收到相关通知时保留五秒兜底;静态画面或有效格式下的暂停不会触发恢复。Ubuntu 26.04、GNOME Wayland 单屏 3840×2160 已实测保持连接切换 200%→166.67%→200%,恢复后画面持续更新且鼠标可控制全屏;切换期间会短暂停顿、黑屏后恢复,五秒是兜底判定阈值,并非总恢复时间。提前恢复的测量结果和验证范围见 [#35](../../pull/35)。此路径仍需实机验证锁屏恢复;多屏、连接中改变分辨率及旋转/镜像变换不属于本次修复范围。 捕获设置协议仍为版本 4:对客户端上报的分辨率统一使用像素坐标、DPR 为 1;Portal 逻辑尺寸仅用于本地输入映射。
|
||||
|
||||
|
||||
+39
-3
@@ -17,7 +17,7 @@ static int portal_eis_dispatch(struct uu_portal *p) {
|
||||
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);
|
||||
EI_DEVICE_CAP_BUTTON, EI_DEVICE_CAP_SCROLL, EI_DEVICE_CAP_KEYBOARD, EI_DEVICE_CAP_TOUCH, NULL);
|
||||
break;
|
||||
case EI_EVENT_DEVICE_RESUMED:
|
||||
if (!g_list_find(p->ei_devices, device)) {
|
||||
@@ -55,15 +55,19 @@ static struct ei_region *portal_eis_region(struct uu_portal *p, struct ei_device
|
||||
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) {
|
||||
static struct ei_device *portal_eis_mapped(struct uu_portal *p, enum ei_device_capability capability, 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) &&
|
||||
if (ei_device_has_capability(device, capability) &&
|
||||
(*region = portal_eis_region(p, device))) return device;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
static struct ei_device *portal_eis_absolute(struct uu_portal *p, struct ei_region **region) {
|
||||
return portal_eis_mapped(p, EI_DEVICE_CAP_POINTER_ABSOLUTE, region);
|
||||
}
|
||||
static void portal_eis_close(struct uu_portal *p) {
|
||||
if (p->ei_touch) p->ei_touch = ei_touch_unref(p->ei_touch);
|
||||
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);
|
||||
@@ -157,6 +161,38 @@ static int portal_eis_button(struct uu_portal *p, int button, int pressed) {
|
||||
ei_device_button_button(device, code, !!pressed);
|
||||
return portal_eis_frame(p, device);
|
||||
}
|
||||
static int portal_eis_scroll(struct uu_portal *p, double dx, double dy, int finish) {
|
||||
if (portal_eis_available(p)) return 9;
|
||||
struct ei_device *device = portal_eis_device(p, EI_DEVICE_CAP_SCROLL);
|
||||
if (!device) return 9;
|
||||
if (dx != 0 || dy != 0) ei_device_scroll_delta(device, dx, dy);
|
||||
if (finish) ei_device_scroll_stop(device, true, true);
|
||||
return portal_eis_frame(p, device);
|
||||
}
|
||||
static int portal_eis_touch(struct uu_portal *p, int phase, double x, double y) {
|
||||
if (portal_eis_available(p)) return 9;
|
||||
if (phase == 2) {
|
||||
if (!p->ei_touch) return 0;
|
||||
struct ei_device *device = ei_touch_get_device(p->ei_touch);
|
||||
ei_touch_up(p->ei_touch);
|
||||
p->ei_touch = ei_touch_unref(p->ei_touch);
|
||||
return portal_eis_frame(p, device);
|
||||
}
|
||||
struct ei_region *region = NULL;
|
||||
struct ei_device *device = portal_eis_mapped(p, EI_DEVICE_CAP_TOUCH, ®ion);
|
||||
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;
|
||||
if (phase == 0) {
|
||||
if (p->ei_touch) { ei_touch_up(p->ei_touch); p->ei_touch = ei_touch_unref(p->ei_touch); }
|
||||
if (!(p->ei_touch = ei_device_touch_new(device))) return 9;
|
||||
ei_touch_down(p->ei_touch, target_x, target_y);
|
||||
} else {
|
||||
if (!p->ei_touch) return 11;
|
||||
ei_touch_motion(p->ei_touch, target_x, target_y);
|
||||
}
|
||||
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;
|
||||
|
||||
+47
-10
@@ -58,8 +58,10 @@ struct uu_portal {
|
||||
uint32_t node, width, height;
|
||||
int logical_width, logical_height, position_x, position_y, has_position;
|
||||
int absolute_stream_pixels;
|
||||
uint32_t devices, available;
|
||||
struct ei *ei;
|
||||
GList *ei_devices;
|
||||
struct ei_touch *ei_touch;
|
||||
char *mapping_id;
|
||||
uint32_t ei_sequence;
|
||||
atomic_int ei_failed;
|
||||
@@ -81,6 +83,19 @@ static int open_cancelled(struct uu_portal *p) {
|
||||
}
|
||||
static int wait_for_first_frame(struct uu_portal *p);
|
||||
#include "portal_eis.inc"
|
||||
/* A uint32 RemoteDesktop property (version, AvailableDeviceTypes); 0 when unreadable. */
|
||||
static guint remote_property(struct uu_portal *p, const char *name) {
|
||||
GVariant *reply = g_dbus_connection_call_sync(p->bus, DEST, PATH,
|
||||
"org.freedesktop.DBus.Properties", "Get", g_variant_new("(ss)", REMOTE, name),
|
||||
G_VARIANT_TYPE("(v)"), G_DBUS_CALL_FLAGS_NONE, 3000, NULL, NULL);
|
||||
guint result = 0;
|
||||
if (reply) {
|
||||
GVariant *value; g_variant_get(reply, "(v)", &value);
|
||||
if (g_variant_is_of_type(value, G_VARIANT_TYPE_UINT32)) result = g_variant_get_uint32(value);
|
||||
g_variant_unref(value); g_variant_unref(reply);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
static void fail(struct uu_portal *p, int error) {
|
||||
pthread_mutex_lock(&p->lock);
|
||||
if (!p->error) p->error = error;
|
||||
@@ -365,6 +380,7 @@ static int read_stream_result(struct uu_portal *p, GVariant *results) {
|
||||
if (!has_devices || (devices & 3) != 3 || !streams || g_variant_n_children(streams) != 1) {
|
||||
error = 6;
|
||||
} else {
|
||||
p->devices = devices;
|
||||
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. */
|
||||
@@ -413,16 +429,10 @@ static struct uu_portal *open_persist(const char *restore, void (*save_token)(co
|
||||
p->closed_subscription = g_dbus_connection_signal_subscribe(p->bus, DEST, SESSION, "Closed", p->session,
|
||||
NULL, G_DBUS_SIGNAL_FLAGS_NONE, session_closed, p, NULL);
|
||||
g_variant_builder_init(&options, G_VARIANT_TYPE_VARDICT);
|
||||
g_variant_builder_add(&options, "{sv}", "types", g_variant_new_uint32(3));
|
||||
GVariant *version_reply = g_dbus_connection_call_sync(p->bus, DEST, PATH,
|
||||
"org.freedesktop.DBus.Properties", "Get", g_variant_new("(ss)", REMOTE, "version"),
|
||||
G_VARIANT_TYPE("(v)"), G_DBUS_CALL_FLAGS_NONE, 3000, NULL, NULL);
|
||||
guint version = 0;
|
||||
if (version_reply) {
|
||||
GVariant *value; g_variant_get(version_reply, "(v)", &value);
|
||||
if (g_variant_is_of_type(value, G_VARIANT_TYPE_UINT32)) version = g_variant_get_uint32(value);
|
||||
g_variant_unref(value); g_variant_unref(version_reply);
|
||||
}
|
||||
/* Keyboard and pointer, plus the touchscreen (4) where the portal offers one (mobile viewers). */
|
||||
p->available = remote_property(p, "AvailableDeviceTypes");
|
||||
g_variant_builder_add(&options, "{sv}", "types", g_variant_new_uint32(3 | (p->available & 4)));
|
||||
guint version = remote_property(p, "version");
|
||||
if (version >= 2) {
|
||||
g_variant_builder_add(&options, "{sv}", "persist_mode", g_variant_new_uint32(2));
|
||||
if (restore && *restore) g_variant_builder_add(&options, "{sv}", "restore_token", g_variant_new_string(restore));
|
||||
@@ -670,6 +680,33 @@ 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));
|
||||
}
|
||||
/* Smooth scroll in stream pixels (positive scrolls down/right, like a touchpad); `finish` ends the
|
||||
* gesture so clients may coast. */
|
||||
int uu_portal_scroll(struct uu_portal *p, double dx, double dy, int finish) {
|
||||
if (!p || !isfinite(dx) || !isfinite(dy)) return 11;
|
||||
if (p->logical_width <= 0 || p->logical_height <= 0 || !p->width || !p->height) return 11;
|
||||
int result = prepare_input(p); if (result) return result;
|
||||
double lx = dx * p->logical_width / p->width, ly = dy * p->logical_height / p->height;
|
||||
if (p->ei) return portal_eis_scroll(p, lx, ly, finish);
|
||||
GVariantBuilder options; g_variant_builder_init(&options, G_VARIANT_TYPE_VARDICT);
|
||||
if (finish) g_variant_builder_add(&options, "{sv}", "finish", g_variant_new_boolean(TRUE));
|
||||
return notify(p, "NotifyPointerAxis", g_variant_new("(oa{sv}dd)", p->session, &options, lx, ly));
|
||||
}
|
||||
/* One finger (slot 0) in stream pixels: phase 0 down, 1 motion, 2 up. */
|
||||
int uu_portal_touch_supported(struct uu_portal *p) { return p && (p->devices & 4); }
|
||||
/* The portal offers a touchscreen this session's consent did not grant (restored from before touch). */
|
||||
int uu_portal_touch_available(struct uu_portal *p) { return p && (p->available & 4); }
|
||||
int uu_portal_touch(struct uu_portal *p, int phase, double x, double y) {
|
||||
if (!uu_portal_touch_supported(p) || phase < 0 || phase > 2) return 11;
|
||||
if (phase != 2 && (!isfinite(x) || !isfinite(y) || p->logical_width <= 0 || p->logical_height <= 0 ||
|
||||
!p->width || !p->height || 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_touch(p, phase, x, y);
|
||||
if (phase == 2) return notify(p, "NotifyTouchUp", g_variant_new("(o@a{sv}u)", p->session, empty_options(), 0u));
|
||||
return notify(p, phase ? "NotifyTouchMotion" : "NotifyTouchDown", g_variant_new("(o@a{sv}uudd)", p->session, empty_options(), p->node, 0u,
|
||||
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_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;
|
||||
|
||||
@@ -25,6 +25,10 @@ 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_scroll(struct uu_portal *portal, double dx, double dy, int finish);
|
||||
int uu_portal_touch_supported(struct uu_portal *portal);
|
||||
int uu_portal_touch_available(struct uu_portal *portal);
|
||||
int uu_portal_touch(struct uu_portal *portal, int phase, double x, double y);
|
||||
int uu_portal_key(struct uu_portal *portal, uint32_t keysym, int keycode, int pressed);
|
||||
int uu_portal_stream_position(struct uu_portal *portal, int32_t *x, int32_t *y);
|
||||
int uu_portal_monitors(char *out, size_t length);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
修复原生控制端连 Mac 无画面,GNOME 手机控制端新增手势滚动,控制端记住画质设置。/ Fixes the native viewer showing no picture from Mac hosts, adds gesture scrolling for phone viewers on GNOME, and remembers viewer quality settings.
|
||||
|
||||
### 修复 / Fixed
|
||||
- **原生控制端连 Mac 被控端一直“连接中”、无画面(#136,感谢 @coolxll 二分定位)**:v0.2.40 在本地重置后只等 IDR,Mac 对 PLI 不回 IDR 时会一直丢帧。现在 H.264 I 片和恢复点 SEI 也可作为重启点,最多等待 1.5 秒后照常解码。
|
||||
Native viewer: after a local reset it accepted only IDR frames, so a Mac host that answers PLI without one stayed blank. I slices and recovery-point SEI now count, and the wait is capped at 1.5 s.
|
||||
|
||||
### 新增 / Added
|
||||
- **GNOME(Portal)手机控制端手势(#134、#131,感谢 @spixyy7)**:触控模式下拖动即平滑滚动(终端里也能滚),按住 0.45 秒后拖动为选中,短按为点击;默认不再需要触摸屏授权。`UU_TOUCH_INPUT=touch` 改用真触控,`=0` 保持鼠标拖动。输入法 ASCII 直接按键输入。
|
||||
GNOME Portal phone viewers: drag scrolls smoothly (also in terminals), hold-then-drag selects, tap clicks, with no touchscreen consent by default; `UU_TOUCH_INPUT=touch` / `=0` select real touch or mouse drags.
|
||||
- **控制端跨会话记住画质、帧率和真彩设置(#133,感谢 @spixyy7)**。/ The viewer remembers quality, frame rate and true-color choices.
|
||||
|
||||
### 验证范围 / Validation
|
||||
单元测试与 CI。手机手势由贡献者在 Fedora 44 / GNOME 50.6 + 官方 Android 控制端实机验证;#136 的修复尚未连真实 Mac 被控端验证。
|
||||
|
||||
### 下载 / Download
|
||||
`uu-remote-linux_0.2.41_<amd64|arm64>.deb`,或 `uu-remote-linux-v0.2.41-<x86_64|aarch64>-linux.tar.gz`(解压后运行 `./install.sh`),或 `docker pull ghcr.io/vallierdev/uu-remote-linux:v0.2.41`(x86_64)。
|
||||
|
||||
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
|
||||
+279
-10
@@ -46,12 +46,60 @@ struct HeldInput { buttons: std::collections::BTreeSet<i32>, keys: std::collecti
|
||||
/// Held modifier VKs (bit 0 Ctrl, 1 Shift, 2 Alt, 3 Win) and keys that got a synthetic Shift.
|
||||
#[derive(Default)]
|
||||
struct Shortcuts { modifiers: u8, shifted: std::collections::BTreeSet<i32> }
|
||||
/// Mobile viewers in touch mode send a finger as a left-button drag at absolute positions (observed:
|
||||
/// Android sends press, a stream of mouse_move_absolute, release), which on a desktop selects text
|
||||
/// instead of scrolling. By default (`Gesture`) the host decides per press: moving past `SLOP` before
|
||||
/// `HOLD` scrolls smoothly (content follows the finger, also in terminals), holding still selects
|
||||
/// like a mouse drag, and a short press is a click. `UU_TOUCH_INPUT=touch` replays drags as one finger
|
||||
/// on the portal touchscreen instead; `=0` keeps mouse buttons. `at` is the last absolute position;
|
||||
/// relative motion (the viewers' trackpad mode) clears it and keeps mouse buttons.
|
||||
#[derive(Default)]
|
||||
struct TouchDrag { mode: TouchMode, at: Option<(i32,i32)>, down: bool, finger: Finger }
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||
enum TouchMode { #[default] Mouse, Gesture, Touch }
|
||||
/// A mobile left press in gesture mode: not decided yet, scrolling, or selecting with button 1 down.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||
enum Finger { #[default] Up, Pending { start: (i32,i32), at: std::time::Instant }, Scroll { last: (i32,i32) }, Select }
|
||||
/// Pixels a finger may wander before a press becomes a scroll, and how long it holds still to select.
|
||||
const SLOP: i32 = 12;
|
||||
const HOLD: std::time::Duration = std::time::Duration::from_millis(450);
|
||||
/// What an absolute position does to the finger: the next state and a scroll from→to or a pointer move.
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum FingerStep { Scroll((i32,i32),(i32,i32)), Move(i32,i32), Stay }
|
||||
fn finger_motion(finger: Finger, to: (i32,i32)) -> (Finger, FingerStep) {
|
||||
match finger {
|
||||
Finger::Pending { start, .. } if (to.0-start.0).abs().max((to.1-start.1).abs()) > SLOP => (Finger::Scroll { last: to }, FingerStep::Scroll(start, to)),
|
||||
Finger::Pending { .. } => (finger, FingerStep::Stay),
|
||||
Finger::Scroll { last } => (Finger::Scroll { last: to }, FingerStep::Scroll(last, to)),
|
||||
Finger::Select | Finger::Up => (finger, FingerStep::Move(to.0, to.1)),
|
||||
}
|
||||
}
|
||||
/// A pending press held still for `HOLD`: where the selection starts.
|
||||
fn finger_held(finger: Finger, now: std::time::Instant) -> Option<(i32,i32)> {
|
||||
match finger { Finger::Pending { start, at } if now.duration_since(at) >= HOLD => Some(start), _ => None }
|
||||
}
|
||||
/// Viewer platform from the connect header `controller_platform` (website enum: 1 windows, 2 android,
|
||||
/// 3 ios, 4 macos, 5 tv).
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub enum Controller { #[default] Other, Mac, Mobile }
|
||||
impl Controller {
|
||||
pub fn from_platform(platform: Option<&serde_json::Value>) -> Self {
|
||||
let Some(v) = platform else { return Self::Other };
|
||||
let text = v.as_str().map(str::to_ascii_lowercase);
|
||||
match v.as_i64().or_else(|| text.as_deref().and_then(|s| s.parse().ok())) {
|
||||
Some(4) => Self::Mac,
|
||||
Some(2 | 3) => Self::Mobile,
|
||||
_ if text.is_some_and(|s| s.contains("mac") || s.contains("darwin")) => Self::Mac,
|
||||
_ => Self::Other,
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Mac viewer with 「使用 macOS 快捷键」 off sends Cmd as VK_LWIN (verified: Cmd 0x5B, Option 0xA4,
|
||||
/// Ctrl 0xA2). Cmd is held back until we know whether it starts a Mac shortcut.
|
||||
#[derive(Default)]
|
||||
struct CmdState { held: bool, pending: bool, passthrough: bool, combos: std::collections::BTreeMap<i32, bool> }
|
||||
|
||||
pub struct InputInjector { mac_controller: std::sync::atomic::AtomicBool, cmd: std::sync::Mutex<CmdState>, serial:std::sync::Mutex<()>, owner:std::sync::Mutex<DesktopOwner>, shortcuts: std::sync::Mutex<Shortcuts>, uinput: Option<crate::uinput::Devices>, screen: std::sync::Mutex<(u32,u32)>, portal_failures: std::sync::atomic::AtomicUsize, portal_outcomes: [std::sync::atomic::AtomicUsize; 3], portal:std::sync::Mutex<Option<std::sync::Arc<crate::portal::PortalSession>>>, backend: crate::desktop_backend::DesktopBackend, pending: std::sync::Mutex<PendingPointer>, held: std::sync::Mutex<HeldInput> }
|
||||
pub struct InputInjector { mac_controller: std::sync::atomic::AtomicBool, cmd: std::sync::Mutex<CmdState>, serial:std::sync::Mutex<()>, owner:std::sync::Mutex<DesktopOwner>, shortcuts: std::sync::Mutex<Shortcuts>, uinput: Option<crate::uinput::Devices>, screen: std::sync::Mutex<(u32,u32)>, portal_failures: std::sync::atomic::AtomicUsize, portal_outcomes: [std::sync::atomic::AtomicUsize; 3], portal:std::sync::Mutex<Option<std::sync::Arc<crate::portal::PortalSession>>>, backend: crate::desktop_backend::DesktopBackend, pending: std::sync::Mutex<PendingPointer>, held: std::sync::Mutex<HeldInput>, touch: std::sync::Mutex<TouchDrag> }
|
||||
|
||||
impl InputInjector {
|
||||
pub fn new() -> Self {
|
||||
@@ -62,7 +110,7 @@ impl InputInjector {
|
||||
Err(e) => { log::warn!("uinput unavailable ({}); using the desktop input path. See README for the udev rule.", e.kind()); None }
|
||||
}
|
||||
} else { None };
|
||||
Self { mac_controller: std::sync::atomic::AtomicBool::new(false), cmd: std::sync::Mutex::new(CmdState::default()), serial:std::sync::Mutex::new(()), owner:std::sync::Mutex::new(DesktopOwner::default()), shortcuts: std::sync::Mutex::new(Shortcuts::default()), uinput, screen: std::sync::Mutex::new((0,0)), portal_failures: std::sync::atomic::AtomicUsize::new(0), portal_outcomes: std::array::from_fn(|_| std::sync::atomic::AtomicUsize::new(0)), portal:std::sync::Mutex::new(None), backend:crate::desktop_backend::detect().unwrap_or(crate::desktop_backend::DesktopBackend::X11), pending: std::sync::Mutex::new(PendingPointer::default()), held:std::sync::Mutex::new(HeldInput::default()) }
|
||||
Self { mac_controller: std::sync::atomic::AtomicBool::new(false), cmd: std::sync::Mutex::new(CmdState::default()), serial:std::sync::Mutex::new(()), owner:std::sync::Mutex::new(DesktopOwner::default()), shortcuts: std::sync::Mutex::new(Shortcuts::default()), uinput, screen: std::sync::Mutex::new((0,0)), portal_failures: std::sync::atomic::AtomicUsize::new(0), portal_outcomes: std::array::from_fn(|_| std::sync::atomic::AtomicUsize::new(0)), portal:std::sync::Mutex::new(None), backend:crate::desktop_backend::detect().unwrap_or(crate::desktop_backend::DesktopBackend::X11), pending: std::sync::Mutex::new(PendingPointer::default()), held:std::sync::Mutex::new(HeldInput::default()), touch:std::sync::Mutex::new(TouchDrag::default()) }
|
||||
}
|
||||
|
||||
pub fn bind_portal(&self,session:Option<std::sync::Arc<crate::portal::PortalSession>>) {
|
||||
@@ -114,8 +162,29 @@ impl InputInjector {
|
||||
let mut pending = self.pending.lock().unwrap();
|
||||
let motion = std::mem::take(&mut *pending);
|
||||
pending.scroll = (motion.scroll.0 % 120, motion.scroll.1 % 120);
|
||||
if let Some((x,y)) = motion.absolute { self.inject_move(x,y,false); }
|
||||
if motion.relative != (0,0) { self.inject_move(motion.relative.0 as i32,motion.relative.1 as i32,true); }
|
||||
let mut touch = self.touch.lock().unwrap();
|
||||
if let Some((x,y)) = motion.absolute {
|
||||
if touch.down { self.inject_touch(1,x,y); } else {
|
||||
let (finger, step) = finger_motion(touch.finger, (x,y));
|
||||
touch.finger = finger;
|
||||
match step {
|
||||
FingerStep::Scroll(from,to) => { self.inject_scroll(from,to,false); },
|
||||
FingerStep::Move(x,y) => { self.inject_move(x,y,false); },
|
||||
FingerStep::Stay => {},
|
||||
}
|
||||
}
|
||||
touch.at = Some((x,y));
|
||||
}
|
||||
// Held still: select from where the finger went down, like a mouse drag.
|
||||
if let Some((x,y)) = finger_held(touch.finger, std::time::Instant::now()) {
|
||||
self.inject_move(x,y,false);
|
||||
touch.finger = if self.inject_button(1,true) == 0 { Finger::Select } else { Finger::Up };
|
||||
}
|
||||
drop(touch);
|
||||
if motion.relative != (0,0) {
|
||||
self.touch.lock().unwrap().at = None;
|
||||
self.inject_move(motion.relative.0 as i32,motion.relative.1 as i32,true);
|
||||
}
|
||||
for (value, positive, negative) in [(motion.scroll.1,4,5),(motion.scroll.0,7,6)] {
|
||||
let count = value / 120;
|
||||
let button = if count > 0 { positive } else { negative };
|
||||
@@ -136,6 +205,7 @@ impl InputInjector {
|
||||
pub fn mouse_button(&self, button: i32, is_press: bool) {
|
||||
let _serial=self.serial.lock().unwrap();
|
||||
self.flush_pointer_locked();
|
||||
if button == 1 && self.touch_button(is_press) { return; }
|
||||
let result = self.inject_button(button,is_press);
|
||||
if result == 0 {
|
||||
let mut held = self.held.lock().unwrap();
|
||||
@@ -174,10 +244,92 @@ impl InputInjector {
|
||||
shift
|
||||
}
|
||||
|
||||
/// The current desktop controller is the macOS viewer (connect header controller_platform).
|
||||
pub fn set_mac_controller(&self, mac: bool) {
|
||||
self.mac_controller.store(mac, std::sync::atomic::Ordering::Relaxed);
|
||||
/// The current desktop controller's platform (connect header controller_platform).
|
||||
/// Mobile drags follow `UU_TOUCH_INPUT`: unset = gesture, `touch` = portal touchscreen, `0` = mouse.
|
||||
pub fn set_controller(&self, controller: Controller) {
|
||||
self.mac_controller.store(controller == Controller::Mac, std::sync::atomic::Ordering::Relaxed);
|
||||
*self.cmd.lock().unwrap() = CmdState::default();
|
||||
let mut touch = self.touch.lock().unwrap();
|
||||
self.lift_finger(&mut touch);
|
||||
let mode = if controller != Controller::Mobile { TouchMode::Mouse } else {
|
||||
match std::env::var("UU_TOUCH_INPUT").as_deref() { Ok("0") => TouchMode::Mouse, Ok("touch") => TouchMode::Touch, _ => TouchMode::Gesture }
|
||||
};
|
||||
*touch = TouchDrag { mode, ..TouchDrag::default() };
|
||||
}
|
||||
/// Ends whatever a finger holds: the touch point, a selection's button, a scroll gesture.
|
||||
fn lift_finger(&self, touch: &mut TouchDrag) {
|
||||
if std::mem::take(&mut touch.down) { self.inject_touch(2,0,0); }
|
||||
match std::mem::take(&mut touch.finger) {
|
||||
Finger::Select => { self.inject_button(1,false); },
|
||||
Finger::Scroll { last } => { self.inject_scroll(last,last,true); },
|
||||
Finger::Pending { .. } | Finger::Up => {},
|
||||
}
|
||||
}
|
||||
/// Left button of a mobile controller: a finger down at the last absolute position, or up.
|
||||
/// False leaves the button to the mouse path (no touchscreen, trackpad mode, other viewers).
|
||||
fn touch_button(&self, pressed: bool) -> bool {
|
||||
let mut touch = self.touch.lock().unwrap();
|
||||
if touch.mode == TouchMode::Gesture { return self.gesture_button(&mut touch, pressed) }
|
||||
if !pressed {
|
||||
if !touch.down { return false; }
|
||||
touch.down = false;
|
||||
self.inject_touch(2,0,0);
|
||||
return true;
|
||||
}
|
||||
if touch.down { return true; }
|
||||
let Some((x,y)) = touch.at.filter(|_| touch.mode == TouchMode::Touch) else { return false };
|
||||
let supported = self.backend == crate::desktop_backend::DesktopBackend::Portal
|
||||
&& self.portal.lock().unwrap().as_ref().is_some_and(|portal| portal.touch_supported());
|
||||
static REPORTED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||
if !REPORTED.swap(true, std::sync::atomic::Ordering::Relaxed) {
|
||||
log::info!("Mobile controller drag input: touchscreen={supported}");
|
||||
}
|
||||
if !supported { self.offer_touch_consent(); }
|
||||
touch.down = supported && self.inject_touch(0,x,y) == 0;
|
||||
touch.down
|
||||
}
|
||||
/// Gesture mode (portal only, for its smooth scroll): a press waits for `finger_motion`/`finger_held`
|
||||
/// to decide; releasing an undecided press is a click.
|
||||
fn gesture_button(&self, touch: &mut TouchDrag, pressed: bool) -> bool {
|
||||
if !pressed {
|
||||
return match std::mem::take(&mut touch.finger) {
|
||||
Finger::Up => false,
|
||||
Finger::Pending { start, .. } => {
|
||||
self.inject_move(start.0,start.1,false);
|
||||
if self.inject_button(1,true) == 0 { self.inject_button(1,false); }
|
||||
true
|
||||
},
|
||||
finger => { touch.finger = finger; self.lift_finger(touch); true },
|
||||
};
|
||||
}
|
||||
if touch.finger != Finger::Up { return true }
|
||||
let bound = self.backend == crate::desktop_backend::DesktopBackend::Portal && self.portal.lock().unwrap().is_some();
|
||||
let Some(start) = touch.at.filter(|_| bound) else { return false };
|
||||
static REPORTED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||
if !REPORTED.swap(true, std::sync::atomic::Ordering::Relaxed) { log::info!("Mobile controller drag input: gesture (drag scrolls, hold selects)"); }
|
||||
touch.finger = Finger::Pending { start, at: std::time::Instant::now() };
|
||||
true
|
||||
}
|
||||
/// Content follows the finger: moving it up scrolls down.
|
||||
fn inject_scroll(&self, from: (i32,i32), to: (i32,i32), finish: bool) -> i32 {
|
||||
let Some(portal) = self.portal.lock().unwrap().clone() else { return -1 };
|
||||
self.portal_result("scroll", portal.scroll(f64::from(from.0 - to.0), f64::from(from.1 - to.1), finish))
|
||||
}
|
||||
/// The portal offers a touchscreen the restored consent lacks: ask the host once per run, in the
|
||||
/// background (GNOME's share dialog, visible to the phone too); drags stay mouse drags meanwhile.
|
||||
fn offer_touch_consent(&self) {
|
||||
static ASKED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||
let Some(portal) = self.portal.lock().unwrap().clone() else { return };
|
||||
if ASKED.swap(true, std::sync::atomic::Ordering::Relaxed) { return }
|
||||
std::thread::spawn(move || match portal.upgrade_touch() {
|
||||
Ok(true) => log::info!("Touch consent upgraded: mobile drags are touch from now on"),
|
||||
Ok(false) => log::info!("Touch consent upgrade not needed or not offered by the portal"),
|
||||
Err(reason) => log::info!("Touch consent upgrade not granted: {reason}"),
|
||||
});
|
||||
}
|
||||
fn inject_touch(&self, phase: i32, x: i32, y: i32) -> i32 {
|
||||
let Some(portal) = self.portal.lock().unwrap().clone() else { return -1 };
|
||||
self.portal_result("touch", portal.touch(phase, f64::from(x), f64::from(y)))
|
||||
}
|
||||
|
||||
fn terminal_focused(&self) -> bool {
|
||||
@@ -269,6 +421,7 @@ impl InputInjector {
|
||||
pub fn release_held(&self) {
|
||||
let _serial=self.serial.lock().unwrap();
|
||||
self.discard_pointer();
|
||||
{ let mut touch=self.touch.lock().unwrap(); self.lift_finger(&mut touch); }
|
||||
let mut held=self.held.lock().unwrap();
|
||||
if let Some(uinput)=&self.uinput {
|
||||
Self::uinput_result(uinput.release_all());
|
||||
@@ -494,8 +647,16 @@ impl InputInjector {
|
||||
}
|
||||
} else if self.backend==crate::desktop_backend::DesktopBackend::Portal {
|
||||
if std::env::var("UU_WAYLAND_TEXT").is_ok_and(|v|v=="0") { return; }
|
||||
if self.paste_text_via_clipboard(text) {
|
||||
log::info!("Desktop text input (Portal clipboard paste): chars={} result=ok", text.chars().count());
|
||||
// Shift+Insert pastes the PRIMARY selection in VTE terminals, not the clipboard just set:
|
||||
// type what the active layout has as keys and paste only the rest.
|
||||
let typed=self.type_portal_keysyms(text);
|
||||
if typed==text.chars().count() {
|
||||
log::info!("Desktop text input (Portal keysyms): chars={typed}");
|
||||
return;
|
||||
}
|
||||
let rest:String=text.chars().skip(typed).collect();
|
||||
if self.paste_text_via_clipboard(&rest) {
|
||||
log::info!("Desktop text input (Portal clipboard paste): chars={} typed={typed} result=ok", text.chars().count());
|
||||
return;
|
||||
}
|
||||
static WARNED:std::sync::atomic::AtomicBool=std::sync::atomic::AtomicBool::new(false);
|
||||
@@ -509,6 +670,14 @@ impl InputInjector {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Types `text` as portal keysyms when it is all printable ASCII (or newline/tab) and GNOME's
|
||||
/// active input source is a Latin xkb layout; returns how many characters were typed.
|
||||
fn type_portal_keysyms(&self, text: &str) -> usize {
|
||||
let Some(symbols)=ascii_keysyms(text) else { return 0 };
|
||||
if !gnome_layout_types_ascii() { return 0; }
|
||||
let Some(portal)=self.portal.lock().unwrap().clone() else { return 0 };
|
||||
symbols.iter().take_while(|&&symbol| portal.type_keysym(symbol).is_ok()).count()
|
||||
}
|
||||
pub fn key_event(&self, keycode: i32, is_press: bool) {
|
||||
let _serial=self.serial.lock().unwrap();
|
||||
if self.backend!=crate::desktop_backend::DesktopBackend::X11 { return; }
|
||||
@@ -645,7 +814,107 @@ impl InputInjector {
|
||||
uinput:None, screen:std::sync::Mutex::new((0,0)), portal_failures:std::sync::atomic::AtomicUsize::new(0),
|
||||
portal_outcomes:std::array::from_fn(|_|std::sync::atomic::AtomicUsize::new(0)),
|
||||
portal:std::sync::Mutex::new(None), backend:crate::desktop_backend::DesktopBackend::Portal,
|
||||
pending:std::sync::Mutex::new(PendingPointer::default()), held:std::sync::Mutex::new(HeldInput::default()) }
|
||||
pending:std::sync::Mutex::new(PendingPointer::default()), held:std::sync::Mutex::new(HeldInput::default()),
|
||||
touch:std::sync::Mutex::new(TouchDrag::default()) }
|
||||
}
|
||||
}
|
||||
|
||||
/// Keysyms for mobile IME text: printable ASCII is its own keysym, newline is Return, tab is Tab.
|
||||
fn ascii_keysyms(text: &str) -> Option<Vec<u32>> {
|
||||
text.chars().map(|c| match c { '\n' => Some(0xff0d), '\t' => Some(0xff09), ' '..='~' => Some(c as u32), _ => None }).collect()
|
||||
}
|
||||
/// Whether an `org.gnome.desktop.input-sources` source list starts with an xkb layout that has
|
||||
/// printable ASCII in its first group. Mutter drops keysyms the active layout lacks, and an IBus
|
||||
/// engine (pinyin, ...) would compose the keys instead.
|
||||
fn first_source_types_ascii(sources: &str) -> bool {
|
||||
let Some(start)=sources.find('(') else { return false };
|
||||
let Some(end)=sources[start..].find(')') else { return false };
|
||||
let fields:Vec<&str>=sources[start+1..start+end].split(',').map(|f| f.trim().trim_matches('\'')).collect();
|
||||
let [kind, layout]=fields[..] else { return false };
|
||||
let (base, variant)=layout.split_once('+').unwrap_or((layout, ""));
|
||||
const NON_LATIN: &[&str]=&["af","am","ara","bd","bg","bt","by","eg","et","ge","gr","il","in","iq","ir","kg","kh","kz","la","lk","mk","mm","mn","mv","np","ru","sy","th","tj","ua"];
|
||||
kind=="xkb" && !NON_LATIN.contains(&base) && !variant.contains("cyrillic") && (base!="rs" || variant.contains("latin"))
|
||||
}
|
||||
/// GNOME's active input source is the first of `mru-sources` (else of `sources`). Cached for 2 s.
|
||||
fn gnome_layout_types_ascii() -> bool {
|
||||
#[cfg(test)]
|
||||
{ false }
|
||||
#[cfg(not(test))]
|
||||
{
|
||||
static CACHE: std::sync::Mutex<Option<(std::time::Instant,bool)>> = std::sync::Mutex::new(None);
|
||||
let mut cache=CACHE.lock().unwrap();
|
||||
if let Some((at,value))=*cache { if at.elapsed()<std::time::Duration::from_secs(2) { return value; } }
|
||||
let read=|key: &str| std::process::Command::new("gsettings").args(["get","org.gnome.desktop.input-sources",key])
|
||||
.stderr(std::process::Stdio::null()).output().ok().filter(|o| o.status.success())
|
||||
.map(|o| String::from_utf8_lossy(&o.stdout).into_owned()).filter(|s| s.contains('('));
|
||||
let value=read("mru-sources").or_else(|| read("sources")).is_some_and(|s| first_source_types_ascii(&s));
|
||||
*cache=Some((std::time::Instant::now(),value));
|
||||
value
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod text_keysym_tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn ascii_text_becomes_keysyms_and_other_text_does_not() {
|
||||
assert_eq!(ascii_keysyms("Hi!\n\t~"), Some(vec![0x48,0x69,0x21,0xff0d,0xff09,0x7e]));
|
||||
assert_eq!(ascii_keysyms("čaj"), None);
|
||||
assert_eq!(ascii_keysyms("测试"), None);
|
||||
}
|
||||
#[test]
|
||||
fn only_latin_xkb_layouts_type_ascii() {
|
||||
assert!(first_source_types_ascii("[('xkb', 'us'), ('ibus', 'libpinyin'), ('xkb', 'rs+latin')]"));
|
||||
assert!(first_source_types_ascii("[('xkb', 'rs+latin')]"));
|
||||
assert!(first_source_types_ascii("[('xkb', 'de+nodeadkeys')]"));
|
||||
assert!(!first_source_types_ascii("[('ibus', 'libpinyin'), ('xkb', 'us')]"));
|
||||
assert!(!first_source_types_ascii("[('xkb', 'rs')]"));
|
||||
assert!(!first_source_types_ascii("[('xkb', 'ru')]"));
|
||||
assert!(first_source_types_ascii("[('xkb', 'ba+unicodeus')]"));
|
||||
assert!(!first_source_types_ascii("[('xkb', 'me+cyrillic')]"));
|
||||
assert!(!first_source_types_ascii("@a(ss) []"));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod touch_tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn controller_from_platform_numbers_and_mac_strings() {
|
||||
use serde_json::json;
|
||||
assert_eq!(Controller::from_platform(Some(&json!(2))), Controller::Mobile);
|
||||
assert_eq!(Controller::from_platform(Some(&json!("3"))), Controller::Mobile);
|
||||
assert_eq!(Controller::from_platform(Some(&json!(4))), Controller::Mac);
|
||||
assert_eq!(Controller::from_platform(Some(&json!("MacOS"))), Controller::Mac);
|
||||
assert_eq!(Controller::from_platform(Some(&json!(1))), Controller::Other);
|
||||
assert_eq!(Controller::from_platform(None), Controller::Other);
|
||||
}
|
||||
#[test]
|
||||
fn a_press_scrolls_past_the_slop_and_selects_when_held() {
|
||||
let t0=std::time::Instant::now();
|
||||
let pending=Finger::Pending{start:(100,100),at:t0};
|
||||
// Small wander stays undecided; past SLOP the content follows the finger from the start.
|
||||
assert_eq!(finger_motion(pending,(105,110)),(pending,FingerStep::Stay));
|
||||
assert_eq!(finger_motion(pending,(100,100+SLOP+1)),(Finger::Scroll{last:(100,113)},FingerStep::Scroll((100,100),(100,113))));
|
||||
assert_eq!(finger_motion(Finger::Scroll{last:(100,113)},(100,90)),(Finger::Scroll{last:(100,90)},FingerStep::Scroll((100,113),(100,90))));
|
||||
assert_eq!(finger_motion(Finger::Select,(7,8)),(Finger::Select,FingerStep::Move(7,8)));
|
||||
assert_eq!(finger_motion(Finger::Up,(7,8)),(Finger::Up,FingerStep::Move(7,8)));
|
||||
assert_eq!(finger_held(pending,t0+HOLD-std::time::Duration::from_millis(1)),None);
|
||||
assert_eq!(finger_held(pending,t0+HOLD),Some((100,100)));
|
||||
assert_eq!(finger_held(Finger::Scroll{last:(1,1)},t0+HOLD*4),None);
|
||||
}
|
||||
#[test]
|
||||
fn mobile_drag_without_touchscreen_stays_a_mouse_button() {
|
||||
let input=InputInjector::without_desktop();
|
||||
input.set_controller(Controller::Mobile);
|
||||
input.mouse_absolute_normalized(0.5,0.5,(100,100)); input.flush_pointer();
|
||||
assert!(input.touch.lock().unwrap().at.is_some());
|
||||
assert!(!input.touch_button(true) && !input.touch.lock().unwrap().down);
|
||||
assert!(!input.touch_button(false));
|
||||
input.mouse_relative(1,1); input.flush_pointer();
|
||||
assert!(input.touch.lock().unwrap().at.is_none());
|
||||
input.set_controller(Controller::Other);
|
||||
assert_eq!(input.touch.lock().unwrap().mode,TouchMode::Mouse);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -763,8 +763,8 @@ async fn serve(mut capture: Arc<ScreenCapture>, input: Arc<InputInjector>, shutd
|
||||
// One peer per viewer connection (desktop, file transfer, terminal...), keyed by ice_id.
|
||||
let mut next_capture_type: Option<(u64,crate::session_ice::SessionIce)> = None;
|
||||
let mut capture_types: HashMap<String, (u64,crate::session_ice::SessionIce)> = HashMap::new();
|
||||
let mut mac_by_ice: HashMap<String, bool> = HashMap::new();
|
||||
let mut next_mac = false;
|
||||
let mut controller_by_ice: HashMap<String, crate::input::Controller> = HashMap::new();
|
||||
let mut next_controller = crate::input::Controller::Other;
|
||||
// Tool peers ask here to become the desktop (capture_desktop on an existing connection, #99).
|
||||
let (desktop_requests, mut desktop_requested) = mpsc::unbounded_channel::<String>();
|
||||
|
||||
@@ -951,9 +951,9 @@ async fn serve(mut capture: Arc<ScreenCapture>, input: Arc<InputInjector>, shutd
|
||||
.and_then(|s| s.as_str())
|
||||
);
|
||||
}
|
||||
SignalingEvent::ConnectRequest { capture_type, ice_id, transport, controller_mac } => {
|
||||
if mac_by_ice.len()>=32 { mac_by_ice.clear(); }
|
||||
match ice_id.clone() { Some(id) => { mac_by_ice.insert(id, controller_mac); } None => next_mac = controller_mac }
|
||||
SignalingEvent::ConnectRequest { capture_type, ice_id, transport, controller } => {
|
||||
if controller_by_ice.len()>=32 { controller_by_ice.clear(); }
|
||||
match ice_id.clone() { Some(id) => { controller_by_ice.insert(id, controller); } None => next_controller = controller }
|
||||
// Pending cloud credentials live only within this room; cap
|
||||
// requests that never receive an offer rather than retain them.
|
||||
if capture_types.len()>=32 { capture_types.clear(); }
|
||||
@@ -984,8 +984,8 @@ async fn serve(mut capture: Arc<ScreenCapture>, input: Arc<InputInjector>, shutd
|
||||
let (capture_type,transport) = capture_types.remove(&ice).or_else(|| next_capture_type.take()).unwrap_or((1,crate::session_ice::SessionIce::default()));
|
||||
// CaptureType: 0 unknown, 1 desktop, 2 window; 5 file transfer, 8 terminal, 9 port mapping.
|
||||
let desktop = capture_type <= 2;
|
||||
let controller_mac = mac_by_ice.remove(&ice).unwrap_or(next_mac);
|
||||
if desktop { input.set_mac_controller(controller_mac); }
|
||||
let controller = controller_by_ice.remove(&ice).unwrap_or(next_controller);
|
||||
if desktop { input.set_controller(controller); }
|
||||
log::info!("Offer for connection: capture_type={} desktop={} active_peers={}", capture_type, desktop, sessions.len());
|
||||
// An expired NVENC failure is re-probed in the background. This offer keeps the cached encoder.
|
||||
if desktop { video::warm_auto_probe(); video::check_ffmpeg_usable(); }
|
||||
@@ -1017,7 +1017,7 @@ async fn serve(mut capture: Arc<ScreenCapture>, input: Arc<InputInjector>, shutd
|
||||
match WebRtcSession::new(session_capture, input.clone(), signaling_client.clone(), desktop, transport,
|
||||
if desktop { portal_desktop.clone() } else { None }).await {
|
||||
Ok(mut sess) => {
|
||||
sess.controller_mac = controller_mac;
|
||||
sess.controller = controller;
|
||||
if !desktop {
|
||||
let (requests, peer) = (desktop_requests.clone(), ice.clone());
|
||||
sess.on_desktop_request(move || { let _ = requests.send(peer.clone()); });
|
||||
@@ -1084,7 +1084,7 @@ async fn serve(mut capture: Arc<ScreenCapture>, input: Arc<InputInjector>, shutd
|
||||
log::info!("Desktop request on a tool connection not supported with the Portal backend; open the desktop before port mapping");
|
||||
continue;
|
||||
}
|
||||
let controller_mac = peer.controller_mac;
|
||||
let controller = peer.controller;
|
||||
let current = peer.desktop_capture();
|
||||
// Same recovery as a desktop offer: the display may have come up or been resized after this peer.
|
||||
let resized = current.init_error.is_none() && current.backend == desktop_backend::DesktopBackend::X11
|
||||
@@ -1098,7 +1098,7 @@ async fn serve(mut capture: Arc<ScreenCapture>, input: Arc<InputInjector>, shutd
|
||||
}
|
||||
} else { None };
|
||||
video::warm_auto_probe(); video::check_ffmpeg_usable();
|
||||
input.set_mac_controller(controller_mac);
|
||||
input.set_controller(controller);
|
||||
input.bind_portal(screen.as_ref().map_or_else(|| sessions[&ice].capture.portal.clone(), |screen| screen.portal.clone()));
|
||||
// One desktop at a time, as for a new desktop offer. Peers offered as desktops
|
||||
// close; a promoted tool peer only stops its desktop and keeps its tools.
|
||||
|
||||
+59
-6
@@ -38,6 +38,10 @@ mod native {
|
||||
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, keycode: i32, pressed: i32) -> i32;
|
||||
fn uu_portal_scroll(portal: *mut c_void, dx: f64, dy: f64, finish: i32) -> i32;
|
||||
fn uu_portal_touch_supported(portal: *mut c_void) -> i32;
|
||||
fn uu_portal_touch_available(portal: *mut c_void) -> i32;
|
||||
fn uu_portal_touch(portal: *mut c_void, phase: i32, x: f64, y: f64) -> i32;
|
||||
fn uu_portal_stream_position(portal: *mut c_void, x: *mut i32, y: *mut i32) -> i32;
|
||||
fn uu_portal_monitors(out: *mut libc::c_char, length: usize) -> i32;
|
||||
fn uu_portal_end(portal: *mut c_void);
|
||||
@@ -114,7 +118,8 @@ mod native {
|
||||
}
|
||||
/// Opens a session for `monitor` (a Mutter connector) with that monitor's saved consent;
|
||||
/// None means the screen currently selected, or the only monitor.
|
||||
fn open_inner(cancelled: Option<&std::sync::atomic::AtomicBool>, monitor: Option<&str>) -> Result<Self, super::PortalError> {
|
||||
/// `fresh` asks the host again instead of restoring the saved consent (which stays saved).
|
||||
fn open_inner(cancelled: Option<&std::sync::atomic::AtomicBool>, monitor: Option<&str>, fresh: bool) -> Result<Self, super::PortalError> {
|
||||
extern "C" fn is_cancelled(data: *mut c_void) -> i32 {
|
||||
let cancelled = unsafe { &*(data as *const std::sync::atomic::AtomicBool) };
|
||||
i32::from(cancelled.load(std::sync::atomic::Ordering::Acquire))
|
||||
@@ -129,7 +134,7 @@ mod native {
|
||||
let key = super::permissions::desktop_key();
|
||||
let wanted = monitor.map(str::to_owned).or_else(crate::wayland::portal_monitor);
|
||||
// Each monitor has its own consent; the desktop-wide key is the single-monitor one.
|
||||
let token = directory.as_deref().and_then(|dir| {
|
||||
let token = directory.as_deref().filter(|_| !fresh).and_then(|dir| {
|
||||
wanted.as_deref().and_then(|name| super::permissions::take(dir, &super::permissions::monitor_key(name)))
|
||||
.or_else(|| super::permissions::take(dir, key))
|
||||
}).and_then(|value| std::ffi::CString::new(value).ok());
|
||||
@@ -188,7 +193,7 @@ mod native {
|
||||
/// time GNOME asks on the host) and swap it in, so every holder of this Arc follows.
|
||||
pub fn switch_to(&self, connector: &str) -> Result<(), String> {
|
||||
if self.monitor().as_deref() == Some(connector) { return Ok(()); }
|
||||
let replacement = Self::open_inner(None, Some(connector)).map_err(|error| error.to_string())?;
|
||||
let replacement = Self::open_inner(None, Some(connector), false).map_err(|error| error.to_string())?;
|
||||
if replacement.monitor().as_deref() != Some(connector) {
|
||||
return Err("Another monitor was shared; choose this monitor in the host dialog".into());
|
||||
}
|
||||
@@ -204,10 +209,29 @@ mod native {
|
||||
Ok(())
|
||||
}
|
||||
pub fn open() -> Result<Self, String> {
|
||||
Self::open_inner(None, None).map_err(|error| error.to_string())
|
||||
Self::open_inner(None, None, false).map_err(|error| error.to_string())
|
||||
}
|
||||
/// A consent saved before touch support restores keyboard and pointer only. Ask the host once
|
||||
/// more (GNOME shows its share dialog; the consent timeout closes it) and swap the new session
|
||||
/// in when it grants the touchscreen for this monitor at this size; until then, and on any
|
||||
/// refusal, this session and its saved consent stay as they are. Ok(false): nothing to do.
|
||||
pub fn upgrade_touch(&self) -> Result<bool, String> {
|
||||
let available = self.handle.lock().is_ok_and(|handle| unsafe { uu_portal_touch_available(handle.0.as_ptr()) } != 0);
|
||||
if !available || self.touch_supported() { return Ok(false); }
|
||||
log::info!("Portal touch consent: asking the host again for the touchscreen");
|
||||
let monitor = self.monitor();
|
||||
let replacement = Self::open_inner(None, monitor.as_deref(), true).map_err(|error| error.to_string())?;
|
||||
// The new consent is saved for whichever monitor was granted, so a later connection uses it.
|
||||
if replacement.monitor() != monitor { return Err("another monitor was shared".into()); }
|
||||
if !replacement.touch_supported() { return Err("the touchscreen was not granted".into()); }
|
||||
self.check_geometry(&replacement).map_err(|error| error.to_string())?;
|
||||
let next = replacement.handle.into_inner().map_err(|_| "Portal session lock poisoned")?;
|
||||
let previous = std::mem::replace(&mut *self.handle.lock().map_err(|_| "Portal session lock poisoned")?, next);
|
||||
drop(previous);
|
||||
Ok(true)
|
||||
}
|
||||
pub fn open_cancellable(cancelled: &std::sync::atomic::AtomicBool) -> Result<Self, super::PortalError> {
|
||||
Self::open_inner(Some(cancelled), None)
|
||||
Self::open_inner(Some(cancelled), None, false)
|
||||
}
|
||||
pub fn recover(&self, cancelled: &std::sync::atomic::AtomicBool) -> Result<bool, super::PortalError> {
|
||||
use std::sync::atomic::Ordering;
|
||||
@@ -305,7 +329,7 @@ mod native {
|
||||
self.was_locked.store(true, std::sync::atomic::Ordering::Release);
|
||||
false
|
||||
}) { return Ok(None); }
|
||||
let replacement = match Self::open_inner(None, self.monitor().as_deref()) {
|
||||
let replacement = match Self::open_inner(None, self.monitor().as_deref(), false) {
|
||||
Ok(value) => value,
|
||||
Err(error) => {
|
||||
log::warn!("Portal capture recovery deferred: {error}");
|
||||
@@ -372,6 +396,30 @@ mod native {
|
||||
let handle = self.handle.lock().map_err(|_| "Portal session lock poisoned")?;
|
||||
super::check(unsafe { uu_portal_button(handle.0.as_ptr(), button, i32::from(pressed)) })
|
||||
}
|
||||
/// Press and release a keysym through Notify*: the compositor picks the key and level of
|
||||
/// the active layout. Under EIS (keycodes only) it fails before typing anything.
|
||||
pub fn type_keysym(&self, symbol: u32) -> Result<(), String> {
|
||||
if *self.locked.borrow() != Some(false) { return Err("Portal input blocked while locked".into()); }
|
||||
let handle = self.handle.lock().map_err(|_| "Portal session lock poisoned")?;
|
||||
super::check(unsafe { uu_portal_key(handle.0.as_ptr(), symbol, -1, 1) })?;
|
||||
super::check(unsafe { uu_portal_key(handle.0.as_ptr(), symbol, -1, 0) })
|
||||
}
|
||||
/// Smooth scroll in stream pixels (positive scrolls down/right); `finish` ends the gesture.
|
||||
pub fn scroll(&self, dx: f64, dy: f64, finish: bool) -> Result<(), String> {
|
||||
if *self.locked.borrow() != Some(false) { return Err("Portal input blocked while locked".into()); }
|
||||
let handle = self.handle.lock().map_err(|_| "Portal session lock poisoned")?;
|
||||
super::check(unsafe { uu_portal_scroll(handle.0.as_ptr(), dx, dy, i32::from(finish)) })
|
||||
}
|
||||
/// The portal granted the touchscreen device type (requested where available).
|
||||
pub fn touch_supported(&self) -> bool {
|
||||
self.handle.lock().is_ok_and(|handle| unsafe { uu_portal_touch_supported(handle.0.as_ptr()) } != 0)
|
||||
}
|
||||
/// One finger in stream pixels: phase 0 down, 1 motion, 2 up.
|
||||
pub fn touch(&self, phase: i32, x: f64, y: f64) -> Result<(), String> {
|
||||
if phase != 2 && *self.locked.borrow() != Some(false) { return Err("Portal input blocked while locked".into()); }
|
||||
let handle = self.handle.lock().map_err(|_| "Portal session lock poisoned")?;
|
||||
super::check(unsafe { uu_portal_touch(handle.0.as_ptr(), phase, x, y) })
|
||||
}
|
||||
pub fn key(&self, symbol: u64, pressed: bool) -> Result<(), String> {
|
||||
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")?;
|
||||
@@ -693,6 +741,11 @@ impl PortalSession {
|
||||
pub fn capture_changed(&self, _: &mut [u8], _: &mut Option<FrameVersion>) -> Result<bool, String> { Err(error(15)) }
|
||||
pub fn move_pointer(&self, _: f64, _: f64, _: bool) -> Result<(), String> { Err(error(15)) }
|
||||
pub fn button(&self, _: i32, _: bool) -> Result<(), String> { Err(error(15)) }
|
||||
pub fn touch_supported(&self) -> bool { false }
|
||||
pub fn scroll(&self, _: f64, _: f64, _: bool) -> Result<(), String> { Err(error(15)) }
|
||||
pub fn upgrade_touch(&self) -> Result<bool, String> { Err(error(15)) }
|
||||
pub fn type_keysym(&self, _: u32) -> Result<(), String> { Err(error(15)) }
|
||||
pub fn touch(&self, _: i32, _: f64, _: f64) -> Result<(), String> { Err(error(15)) }
|
||||
pub fn key(&self, _: u64, _: bool) -> Result<(), String> { Err(error(15)) }
|
||||
}
|
||||
|
||||
|
||||
+4
-5
@@ -51,7 +51,7 @@ pub enum SignalingEvent {
|
||||
BeControlled(Value),
|
||||
/// be-controlled with its binary app_data (ConnectOptions): capture type and the
|
||||
/// ice_id it announces, when present.
|
||||
ConnectRequest { capture_type: u64, ice_id: Option<String>, transport:crate::session_ice::SessionIce, controller_mac: bool },
|
||||
ConnectRequest { capture_type: u64, ice_id: Option<String>, transport:crate::session_ice::SessionIce, controller: crate::input::Controller },
|
||||
Soac(SoacMessage),
|
||||
Released(Value),
|
||||
Left(Value),
|
||||
@@ -513,10 +513,9 @@ impl SignalingClient {
|
||||
if !caps.is_empty() { log::info!("Viewer decoder caps (fps,codec,w,h,chroma fields): {:?}", caps); }
|
||||
// Viewer platform (website enum: 1 windows, 2 android, 3 ios, 4 macos, 5 tv).
|
||||
let platform = header.get("controller_platform").or_else(|| header.get("data").and_then(|d| d.get("controller_platform")));
|
||||
let controller_mac = platform.is_some_and(|v| v.as_i64() == Some(4)
|
||||
|| v.as_str().is_some_and(|s| s == "4" || s.to_ascii_lowercase().contains("mac") || s.to_ascii_lowercase().contains("darwin")));
|
||||
log::info!("Controller platform: {} mac={}", platform.map(|v| v.to_string()).unwrap_or_default().chars().take(24).collect::<String>(), controller_mac);
|
||||
if !send_event(&event_sender, SignalingEvent::ConnectRequest { capture_type, ice_id, transport:crate::session_ice::SessionIce::from_header(&header), controller_mac }).await { break; }
|
||||
let controller = crate::input::Controller::from_platform(platform);
|
||||
log::info!("Controller platform: {} controller={:?}", platform.map(|v| v.to_string()).unwrap_or_default().chars().take(24).collect::<String>(), controller);
|
||||
if !send_event(&event_sender, SignalingEvent::ConnectRequest { capture_type, ice_id, transport:crate::session_ice::SessionIce::from_header(&header), controller }).await { break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+45
-3
@@ -15,13 +15,42 @@ pub trait FrameSink { fn present(&mut self,frame:&Frame)->Result<(),String>; }
|
||||
/// Counts only (access units, presented frames, decode errors) for the periodic stats line.
|
||||
pub static STATS:[std::sync::atomic::AtomicU64;3]=[std::sync::atomic::AtomicU64::new(0),std::sync::atomic::AtomicU64::new(0),std::sync::atomic::AtomicU64::new(0)];
|
||||
fn wants_key_frame(units:u64,presented:u64)->bool {presented==0 && units%30==0}
|
||||
/// True when an Annex-B access unit carries an IDR/IRAP slice the decoder can restart from.
|
||||
/// True when an Annex-B access unit carries a picture the decoder can restart from: an IDR/IRAP,
|
||||
/// an H.264 recovery-point SEI or an H.264 I slice (some hosts answer PLI without an IDR, #136).
|
||||
pub fn is_key_frame(codec:super::media::Codec,au:&[u8])->bool {
|
||||
au.windows(4).enumerate().filter(|(_,w)|w[..3]==[0,0,1]).any(|(_,w)|match codec {
|
||||
super::media::Codec::H264=>w[3]&0x1f==5,
|
||||
au.windows(4).enumerate().filter(|(_,w)|w[..3]==[0,0,1]).any(|(i,w)|match codec {
|
||||
super::media::Codec::H264=>match w[3]&0x1f {5=>true,6=>au.get(i+4)==Some(&6),1=>h264_i_slice(&au[i+4..]),_=>false},
|
||||
super::media::Codec::H265=>(16..=21).contains(&((w[3]>>1)&0x3f)),
|
||||
})
|
||||
}
|
||||
/// Reads first_mb_in_slice and slice_type (both ue(v)) from a slice header; I = 2 or 7.
|
||||
fn h264_i_slice(rbsp:&[u8])->bool {
|
||||
let mut bit=0usize;
|
||||
let mut ue=||->Option<u32>{
|
||||
let mut zeros=0;
|
||||
while (rbsp.get(bit/8)?>>(7-bit%8))&1==0 {zeros+=1;bit+=1;if zeros>31 {return None}}
|
||||
bit+=1;let mut v=0u32;
|
||||
for _ in 0..zeros {v=(v<<1)|u32::from((rbsp.get(bit/8)?>>(7-bit%8))&1);bit+=1;}
|
||||
Some((1u32<<zeros)-1+v)
|
||||
};
|
||||
ue().is_some() && matches!(ue(),Some(2|7))
|
||||
}
|
||||
/// After a local reset, holds back pictures until a restart point arrives, but never longer
|
||||
/// than `limit`: a host that ignores PLI must not leave the window blank (#136).
|
||||
pub struct KeyGate { since:Option<std::time::Instant>, limit:std::time::Duration }
|
||||
impl KeyGate {
|
||||
pub fn new()->Self {Self{since:None,limit:std::time::Duration::from_millis(1500)}}
|
||||
pub fn arm(&mut self) {self.since.get_or_insert_with(std::time::Instant::now);}
|
||||
/// False = drop this unit and keep asking for a key frame.
|
||||
pub fn admit(&mut self,codec:super::media::Codec,au:&[u8])->bool {
|
||||
let Some(since)=self.since else {return true};
|
||||
let timed_out=since.elapsed()>=self.limit;
|
||||
if timed_out || is_key_frame(codec,au) {
|
||||
if timed_out {log::debug!("Viewer desktop: no key frame within {:?} after reset; decoding on",self.limit);}
|
||||
self.since=None;true
|
||||
} else {false}
|
||||
}
|
||||
}
|
||||
/// Shows the newest frame a decoder finished between access units.
|
||||
pub fn drain(decoder:&mut dyn Decoder,sink:&mut dyn FrameSink)->Result<(),String> {
|
||||
if let Some(frame)=decoder.poll().pop() {STATS[1].fetch_add(1,Ordering::Relaxed);sink.present(&frame)?;}
|
||||
@@ -56,6 +85,19 @@ pub fn display(decoder:&mut dyn Decoder,sink:&mut dyn FrameSink,au:&[u8],codec:s
|
||||
assert!(!super::is_key_frame(Codec::H264,&[0,0,0,1,0x61,1]));
|
||||
assert!(super::is_key_frame(Codec::H265,&[0,0,0,1,0x40,1,0,0,1,0x26,1,3]));
|
||||
assert!(!super::is_key_frame(Codec::H265,&[0,0,0,1,0x02,1]));
|
||||
// I slice (first_mb=0 '1', slice_type=7 '0001000') and P slice (slice_type=5 '00110').
|
||||
assert!(super::is_key_frame(Codec::H264,&[0,0,0,1,0x41,0b1000_1000,0]));
|
||||
assert!(!super::is_key_frame(Codec::H264,&[0,0,0,1,0x41,0b1001_1000]));
|
||||
// Recovery-point SEI (payload type 6).
|
||||
assert!(super::is_key_frame(Codec::H264,&[0,0,0,1,0x06,0x06,1,0x80]));
|
||||
}
|
||||
#[test] fn key_gate_waits_then_gives_up(){
|
||||
use crate::viewer::media::Codec;
|
||||
let mut g=super::KeyGate::new();let p=[0,0,0,1,0x41,0b1001_1000];
|
||||
assert!(g.admit(Codec::H264,&p));
|
||||
g.arm();assert!(!g.admit(Codec::H264,&p));
|
||||
assert!(g.admit(Codec::H264,&[0,0,0,1,0x65,0x88]));assert!(g.admit(Codec::H264,&p));
|
||||
g.limit=std::time::Duration::ZERO;g.arm();assert!(g.admit(Codec::H264,&p));
|
||||
}
|
||||
use super::*;
|
||||
struct Mock(bool);impl Decoder for Mock {fn set_codec(&mut self,_:crate::viewer::media::Codec)->Result<(),String>{Ok(())} fn decode(&mut self,_:&[u8])->Result<Vec<Frame>,String>{if self.0{Err("synthetic".into())}else{Ok(vec![Frame{width:1,height:1,rgb:vec![0;3],content:None}])}} fn reset(&mut self){self.0=false;}}
|
||||
|
||||
+7
-3
@@ -137,8 +137,8 @@ pub enum Command {
|
||||
Quality(u64), Fps(u32), Chroma(u32), FollowRemote(bool), OneToOne(bool), Volume(u8),
|
||||
AutoLock(bool), HostMute(bool), GrabKeys(bool), Files, Watch(bool), Stats(bool), HideTab(bool), Fullscreen, Disconnect,
|
||||
}
|
||||
/// What the menu shows as selected. Remote settings start at the official viewer's defaults and
|
||||
/// reflect only this session's choices; the host does not report them back.
|
||||
/// What the menu shows as selected. The host does not report remote settings back; quality, frame
|
||||
/// rate and color are saved and sent again when the next session's CONTROL is ready.
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct State {
|
||||
pub quality: u64, pub fps: u32, pub chroma: u32, pub follow_remote: bool, pub one_to_one: bool, pub volume: u8,
|
||||
@@ -328,11 +328,15 @@ pub fn load_prefs(st: &mut State) {
|
||||
if let Some(b) = v["hide_tab_fullscreen"].as_bool() { st.hide_tab = b; }
|
||||
if let Some(b) = v["one_to_one"].as_bool() { st.one_to_one = b; }
|
||||
if let Some(n) = v["volume"].as_u64() { st.volume = n.min(100) as u8; }
|
||||
if let Some(q) = v["quality"].as_u64().filter(|q| (2..=5).contains(q)) { st.quality = q; }
|
||||
if let Some(f) = v["fps"].as_u64().filter(|f| [30, 60, 90, 144].contains(f)) { st.fps = f as u32; }
|
||||
if let Some(c) = v["chroma"].as_u64().filter(|c| [1, 3].contains(c)) { st.chroma = c as u32; }
|
||||
}
|
||||
pub fn save_prefs(st: &State) {
|
||||
let path = prefs_path();
|
||||
if let Some(dir) = path.parent() { let _ = std::fs::create_dir_all(dir); }
|
||||
let v = serde_json::json!({"stats": st.stats, "hide_tab_fullscreen": st.hide_tab, "one_to_one": st.one_to_one, "volume": st.volume});
|
||||
let v = serde_json::json!({"stats": st.stats, "hide_tab_fullscreen": st.hide_tab, "one_to_one": st.one_to_one, "volume": st.volume,
|
||||
"quality": st.quality, "fps": st.fps, "chroma": st.chroma});
|
||||
let _ = std::fs::write(path, v.to_string());
|
||||
}
|
||||
fn prefs_path() -> std::path::PathBuf { crate::config::path().parent().map_or_else(|| "viewer.json".into(), |d| d.join("viewer.json")) }
|
||||
|
||||
+14
-6
@@ -139,7 +139,8 @@ impl Window {
|
||||
fn command(&mut self,command:hud::Command){
|
||||
let st=&mut self.chrome.state;
|
||||
match command {
|
||||
hud::Command::Quality(q)=>st.quality=q, hud::Command::Fps(f)=>st.fps=f, hud::Command::Chroma(c)=>st.chroma=c,
|
||||
hud::Command::Quality(q)=>{st.quality=q;hud::save_prefs(st)}, hud::Command::Fps(f)=>{st.fps=f;hud::save_prefs(st)},
|
||||
hud::Command::Chroma(c)=>{st.chroma=c;hud::save_prefs(st)},
|
||||
hud::Command::FollowRemote(b)=>st.follow_remote=b, hud::Command::Volume(v)=>st.volume=v,
|
||||
hud::Command::AutoLock(b)=>st.auto_lock=b, hud::Command::HostMute(b)=>st.host_mute=b, hud::Command::Watch(b)=>st.watch=b,
|
||||
hud::Command::OneToOne(b)=>{st.one_to_one=b;hud::save_prefs(st)},
|
||||
@@ -156,6 +157,13 @@ impl Window {
|
||||
self.chrome.commands.push(command);
|
||||
}
|
||||
pub fn take_commands(&mut self)->Vec<hud::Command>{std::mem::take(&mut self.chrome.commands)}
|
||||
/// The host starts every session at the official defaults; repeat the saved choices that differ.
|
||||
pub fn restore_remote_settings(&mut self){
|
||||
let(st,d)=(&self.chrome.state,hud::State::default());let c=&mut self.chrome.commands;
|
||||
if st.quality!=d.quality {c.push(hud::Command::Quality(st.quality));}
|
||||
if st.fps!=d.fps {c.push(hud::Command::Fps(st.fps));}
|
||||
if st.chroma!=d.chroma {c.push(hud::Command::Chroma(st.chroma));}
|
||||
}
|
||||
pub fn state(&self)->&hud::State{&self.chrome.state}
|
||||
pub fn sync_chroma(&mut self,chroma:u32){if chroma!=0 {self.chrome.state.chroma=chroma;}}
|
||||
pub fn set_stage(&mut self,stage:&str){self.chrome.stage=stage.into();}
|
||||
@@ -391,7 +399,7 @@ pub async fn run(session:&mut Session,window:&mut Window,decoder:&mut dyn super:
|
||||
}
|
||||
Err(e)=>{ log::warn!("Type IPC not started: {e}"); None }
|
||||
};
|
||||
let mut command_open=true;let mut requested=false;let mut type_requested=false;
|
||||
let mut command_open=true;let mut requested=false;let mut type_requested=false;let mut restored=false;
|
||||
let mut type_job:Option<TypeJob>=None;
|
||||
let mut terminate=tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate()).map_err(|_|"Cannot watch termination")?;
|
||||
let mut audio=super::audio::Playback::new(&window._sdl,session.peer.audio.clone());
|
||||
@@ -405,7 +413,7 @@ pub async fn run(session:&mut Session,window:&mut Window,decoder:&mut dyn super:
|
||||
let mut last=(0u64,0u64,0u64,0u64,std::time::Instant::now());
|
||||
let mut codec_name="--";
|
||||
// After a local drop the decoder has no reference picture; P-frames would only smear blocks.
|
||||
let mut await_key=false;
|
||||
let mut key_gate=super::desktop::KeyGate::new();
|
||||
let mut next_thumb=std::time::Instant::now()+std::time::Duration::from_secs(5);
|
||||
let result=async {
|
||||
loop {tokio::select!{
|
||||
@@ -464,6 +472,7 @@ pub async fn run(session:&mut Session,window:&mut Window,decoder:&mut dyn super:
|
||||
if let Some(playback)=audio.as_mut(){if playback.pump().is_err(){log::warn!("Viewer audio playback stopped");audio=None;}}
|
||||
let (quit,mut messages)=window.poll(&mut input);
|
||||
if !window.has_picture() {window.loading_frame(false);}
|
||||
if !restored && session.peer.ready(super::rtc::ReadyPolicy::EchoOnly,false) {restored=true;window.restore_remote_settings();}
|
||||
for command in window.take_commands() {
|
||||
seq+=1;
|
||||
let control=match command {
|
||||
@@ -533,10 +542,9 @@ pub async fn run(session:&mut Session,window:&mut Window,decoder:&mut dyn super:
|
||||
if quit{return Ok(())}
|
||||
// At most one AU per iteration keeps local event polling responsive.
|
||||
if let Some(au)=session.peer.desktop.units.pop(){
|
||||
if session.peer.desktop.reset.swap(false,std::sync::atomic::Ordering::AcqRel){decoder.reset();await_key=true;}
|
||||
if await_key && !super::desktop::is_key_frame(au.codec,&au.data) {session.peer.desktop.pli.store(true,std::sync::atomic::Ordering::Release);}
|
||||
if session.peer.desktop.reset.swap(false,std::sync::atomic::Ordering::AcqRel){decoder.reset();key_gate.arm();}
|
||||
if !key_gate.admit(au.codec,&au.data) {session.peer.desktop.pli.store(true,std::sync::atomic::Ordering::Release);super::desktop::drain(decoder,window)?;}
|
||||
else {
|
||||
await_key=false;
|
||||
decoder.set_codec(au.codec)?;
|
||||
codec_name=if au.codec==super::media::Codec::H265 {"H.265"} else {"H.264"};
|
||||
super::desktop::display(decoder,window,&au.data,au.codec,&session.peer.desktop.pli)?;
|
||||
|
||||
+2
-2
@@ -111,7 +111,7 @@ pub struct WebRtcSession {
|
||||
/// The role this peer was offered with; `role` also covers a later capture_desktop.
|
||||
pub desktop: bool,
|
||||
pub role: Arc<DesktopRole>,
|
||||
pub controller_mac: bool,
|
||||
pub controller: crate::input::Controller,
|
||||
pub context: Arc<Mutex<SessionContext>>,
|
||||
actions: Arc<crate::system_actions::PeerActions>,
|
||||
}
|
||||
@@ -1454,7 +1454,7 @@ impl WebRtcSession {
|
||||
input,
|
||||
desktop,
|
||||
role,
|
||||
controller_mac: false,
|
||||
controller: crate::input::Controller::Other,
|
||||
context,
|
||||
actions: session_actions,
|
||||
})
|
||||
|
||||
+63
-2
@@ -23,7 +23,7 @@ static GVariant *test_call_with_unix_fd_list_sync(GDBusConnection *connection,
|
||||
#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)
|
||||
EIS_DEVICE_CAP_BUTTON | EIS_DEVICE_CAP_SCROLL | EIS_DEVICE_CAP_KEYBOARD | EIS_DEVICE_CAP_TOUCH)
|
||||
|
||||
static const unsigned capabilities[] = {
|
||||
EIS_DEVICE_CAP_POINTER,
|
||||
@@ -31,6 +31,7 @@ static const unsigned capabilities[] = {
|
||||
EIS_DEVICE_CAP_BUTTON,
|
||||
EIS_DEVICE_CAP_SCROLL,
|
||||
EIS_DEVICE_CAP_KEYBOARD,
|
||||
EIS_DEVICE_CAP_TOUCH,
|
||||
};
|
||||
|
||||
struct received {
|
||||
@@ -166,7 +167,9 @@ static void handle_server_events(struct harness *h) {
|
||||
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) {
|
||||
type == EIS_EVENT_KEYBOARD_KEY || type == EIS_EVENT_TOUCH_DOWN ||
|
||||
type == EIS_EVENT_TOUCH_MOTION || type == EIS_EVENT_TOUCH_UP ||
|
||||
type == EIS_EVENT_SCROLL_DELTA || type == EIS_EVENT_SCROLL_STOP) {
|
||||
assert(h->n_events < sizeof(h->events) / sizeof(h->events[0]));
|
||||
struct received *got = &h->events[h->n_events++];
|
||||
got->type = type;
|
||||
@@ -187,6 +190,15 @@ static void handle_server_events(struct harness *h) {
|
||||
got->dx = eis_event_scroll_get_discrete_dx(event);
|
||||
got->dy = eis_event_scroll_get_discrete_dy(event);
|
||||
break;
|
||||
case EIS_EVENT_SCROLL_DELTA:
|
||||
got->x = eis_event_scroll_get_dx(event);
|
||||
got->y = eis_event_scroll_get_dy(event);
|
||||
break;
|
||||
case EIS_EVENT_TOUCH_DOWN:
|
||||
case EIS_EVENT_TOUCH_MOTION:
|
||||
got->x = eis_event_touch_get_x(event);
|
||||
got->y = eis_event_touch_get_y(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);
|
||||
@@ -255,6 +267,15 @@ static void wait_for_input(struct harness *h) {
|
||||
assert(h->frames > 0);
|
||||
}
|
||||
|
||||
static int input_within(struct harness *h, gint64 microseconds) {
|
||||
gint64 deadline = g_get_monotonic_time() + microseconds;
|
||||
while (!h->n_events && g_get_monotonic_time() < deadline) {
|
||||
pump(h);
|
||||
g_usleep(1000);
|
||||
}
|
||||
return h->n_events > 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. */
|
||||
@@ -295,6 +316,7 @@ static void run_geometry(const struct geometry *geometry) {
|
||||
h.portal->mapping_id = g_strdup("synthetic-screen");
|
||||
h.portal->session = strdup("/synthetic/session");
|
||||
h.portal->absolute_stream_pixels = 1;
|
||||
h.portal->devices = 7;
|
||||
|
||||
h.server = eis_new(NULL);
|
||||
assert(h.server && eis_setup_backend_fd(h.server) == 0);
|
||||
@@ -380,6 +402,45 @@ static void run_geometry(const struct geometry *geometry) {
|
||||
assert(h.events[0].type == EIS_EVENT_SCROLL_DISCRETE);
|
||||
assert(h.events[0].dx == 0 && h.events[0].dy == -120);
|
||||
|
||||
/* Smooth scroll maps like relative motion; finish ends the gesture with a scroll stop. */
|
||||
clear_events(&h);
|
||||
assert(uu_portal_scroll(h.portal, geometry->width / 8.0, -(double)geometry->height / 8.0, 1) == 0);
|
||||
wait_for_input(&h);
|
||||
assert(h.events[0].type == EIS_EVENT_SCROLL_DELTA);
|
||||
assert(fabs(h.events[0].x - geometry->logical_width / 8.0) < 0.001 && fabs(h.events[0].y + geometry->logical_height / 8.0) < 0.001);
|
||||
for (gint64 until = g_get_monotonic_time() + 300000; h.n_events < 2 && g_get_monotonic_time() < until; g_usleep(1000)) pump(&h);
|
||||
assert(h.n_events == 2 && h.events[1].type == EIS_EVENT_SCROLL_STOP);
|
||||
|
||||
/* A touch drag lands in the stream's region; motion without a finger down is refused. */
|
||||
assert(uu_portal_touch(h.portal, 1, 1, 1) == 11);
|
||||
clear_events(&h);
|
||||
unsigned diagnostics = h.diagnostics;
|
||||
assert(uu_portal_touch(h.portal, 0, geometry->width / 2.0, geometry->height / 2.0) == 0);
|
||||
if (!input_within(&h, 300000)) {
|
||||
/* libei before 1.3.0 accepts a touch only inside every region of the device (later:
|
||||
* any region). This device also has a region for another screen, so an older library
|
||||
* rejects the point with a client-bug diagnostic; a real one-stream session has one region. */
|
||||
assert(h.diagnostics > diagnostics);
|
||||
assert(uu_portal_touch(h.portal, 2, 0, 0) == 0 && !h.portal->ei_touch);
|
||||
h.diagnostics = diagnostics; /* expected: the rejected touch and its release */
|
||||
goto touched;
|
||||
}
|
||||
assert(h.events[0].type == EIS_EVENT_TOUCH_DOWN);
|
||||
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_touch(h.portal, 1, 0, 0) == 0);
|
||||
wait_for_input(&h);
|
||||
assert(h.events[0].type == EIS_EVENT_TOUCH_MOTION);
|
||||
assert(h.events[0].x == geometry->x && h.events[0].y == geometry->y);
|
||||
assert(uu_portal_touch(h.portal, 1, geometry->width, 0) == 11);
|
||||
clear_events(&h);
|
||||
assert(uu_portal_touch(h.portal, 2, 0, 0) == 0);
|
||||
wait_for_input(&h);
|
||||
assert(h.events[0].type == EIS_EVENT_TOUCH_UP && !h.portal->ei_touch);
|
||||
assert(uu_portal_touch(h.portal, 2, 0, 0) == 0);
|
||||
touched:;
|
||||
|
||||
uint8_t storage[256];
|
||||
struct spa_pod_builder builder = SPA_POD_BUILDER_INIT(storage, sizeof(storage));
|
||||
const struct spa_pod *format = spa_format_video_raw_build(&builder, SPA_PARAM_Format,
|
||||
|
||||
+45
-1
@@ -18,6 +18,7 @@ enum response_mode { UNKNOWN_METHOD, NOT_SUPPORTED, TEMPORARY_FAILURE, NO_FDS, B
|
||||
static enum response_mode mode;
|
||||
static unsigned connects, legacy_calls;
|
||||
static double last_x, last_y;
|
||||
static int last_finish;
|
||||
|
||||
static GVariant *test_call(GDBusConnection *bus, const gchar *dest, const gchar *path,
|
||||
const gchar *interface, const gchar *method, GVariant *parameters,
|
||||
@@ -26,7 +27,24 @@ static GVariant *test_call(GDBusConnection *bus, const gchar *dest, const gchar
|
||||
assert(!strcmp(interface, REMOTE));
|
||||
assert(!strcmp(method, "NotifyKeyboardKeysym") || !strcmp(method, "NotifyPointerButton") ||
|
||||
!strcmp(method, "NotifyPointerAxisDiscrete") || !strcmp(method, "NotifyPointerMotion") ||
|
||||
!strcmp(method, "NotifyPointerMotionAbsolute"));
|
||||
!strcmp(method, "NotifyPointerMotionAbsolute") || !strcmp(method, "NotifyTouchDown") ||
|
||||
!strcmp(method, "NotifyTouchMotion") || !strcmp(method, "NotifyTouchUp") || !strcmp(method, "NotifyPointerAxis"));
|
||||
if (!strcmp(method, "NotifyPointerAxis")) {
|
||||
assert(g_variant_is_of_type(parameters, G_VARIANT_TYPE("(oa{sv}dd)")));
|
||||
GVariant *options = g_variant_get_child_value(parameters, 1);
|
||||
GVariant *x = g_variant_get_child_value(parameters, 2), *y = g_variant_get_child_value(parameters, 3);
|
||||
last_x = g_variant_get_double(x); last_y = g_variant_get_double(y);
|
||||
gboolean finish = FALSE; last_finish = g_variant_lookup(options, "finish", "b", &finish) && finish;
|
||||
g_variant_unref(options); g_variant_unref(x); g_variant_unref(y);
|
||||
}
|
||||
if (!strcmp(method, "NotifyTouchDown") || !strcmp(method, "NotifyTouchMotion")) {
|
||||
assert(g_variant_is_of_type(parameters, G_VARIANT_TYPE("(oa{sv}uudd)")));
|
||||
GVariant *x = g_variant_get_child_value(parameters, 4);
|
||||
GVariant *y = g_variant_get_child_value(parameters, 5);
|
||||
last_x = g_variant_get_double(x); last_y = g_variant_get_double(y);
|
||||
g_variant_unref(x); g_variant_unref(y);
|
||||
}
|
||||
if (!strcmp(method, "NotifyTouchUp")) assert(g_variant_is_of_type(parameters, G_VARIANT_TYPE("(oa{sv}u)")));
|
||||
if (!strcmp(method, "NotifyPointerMotion") || !strcmp(method, "NotifyPointerMotionAbsolute")) {
|
||||
unsigned offset = !strcmp(method, "NotifyPointerMotion") ? 2 : 3;
|
||||
GVariant *x = g_variant_get_child_value(parameters, offset);
|
||||
@@ -93,6 +111,28 @@ static void legacy_input(struct uu_portal *p) {
|
||||
assert(legacy_calls == 7 && uu_portal_alive(p) && !p->ei);
|
||||
}
|
||||
|
||||
/* Smooth scroll maps like relative motion; only the last event of a gesture carries "finish". */
|
||||
static void legacy_scroll(struct uu_portal *p) {
|
||||
unsigned before = legacy_calls;
|
||||
assert(uu_portal_scroll(p, 20, -40, 0) == 0);
|
||||
assert(last_x == 20. * p->logical_width / p->width && last_y == -40. * p->logical_height / p->height && !last_finish);
|
||||
assert(uu_portal_scroll(p, 0, 0, 1) == 0 && last_finish && last_x == 0 && last_y == 0);
|
||||
assert(uu_portal_scroll(p, NAN, 0, 0) == 11 && legacy_calls == before + 2);
|
||||
}
|
||||
/* Touch needs the granted touchscreen type and uses the same stream mapping as absolute motion. */
|
||||
static void legacy_touch(struct uu_portal *p) {
|
||||
p->devices = 3;
|
||||
assert(uu_portal_touch(p, 0, 10, 10) == 11 && legacy_calls == 7);
|
||||
p->devices = 7;
|
||||
assert(uu_portal_touch(p, 0, 1920, 1080) == 0);
|
||||
assert(last_x == (p->absolute_stream_pixels ? 1920 : 960));
|
||||
assert(last_y == (p->absolute_stream_pixels ? 1080 : 540));
|
||||
assert(uu_portal_touch(p, 1, 3840, 0) == 11);
|
||||
assert(uu_portal_touch(p, 1, 0, 0) == 0 && last_x == 0 && last_y == 0);
|
||||
assert(uu_portal_touch(p, 2, 0, 0) == 0);
|
||||
assert(legacy_calls == 10 && !p->ei);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
struct uu_portal *p = session(1, 1, 0);
|
||||
legacy_input(p);
|
||||
@@ -107,10 +147,14 @@ int main(void) {
|
||||
}
|
||||
p = session(0, 1, 1); /* Unscaled GNOME keeps Notify*. */
|
||||
legacy_input(p);
|
||||
legacy_touch(p);
|
||||
legacy_scroll(p);
|
||||
assert(!connects);
|
||||
uu_portal_close(p);
|
||||
p = session(1, 0, 1); /* KDE keeps its compositor-logical mapping. */
|
||||
legacy_input(p);
|
||||
legacy_touch(p);
|
||||
legacy_scroll(p);
|
||||
assert(!connects);
|
||||
uu_portal_close(p);
|
||||
|
||||
|
||||
Reference in new issue
Block a user