mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-17 01:00:41 +01:00
* feat(host): KDE Wayland 被控端防窥模式(隐私 / 关屏) viewer RPC 7 打开防窥时,采集和输入切到 KWin 虚拟输出(portal ScreenCast VIRTUAL), 再用 kscreen-doctor 禁用物理屏;隐私模式随后重新启用物理屏并全屏覆盖桌面壁纸。 防窥期间通过 KWin InputDevice 禁用本地键鼠,指针/按键/文字改走 uinput (KDE 不处理虚拟输出共享上的 portal 输入)。 - privacy_type 实测:1 关闭、2 隐私(壁纸)、3 关屏;SettingMetric 4/7 上报真实状态 - 恢复记录 + privacy-guard 子进程:主机以任何方式结束(含 SIGKILL)都恢复屏幕和输入 - src/privacy_screen/ 分层:控制器/协议/记录/守护/遮挡窗口共享,桌面实现走 Backend trait(kde/) - portal:Session::set_virtual,闭包恢复按当前源重开;编码器随 portal 尺寸变化重建 Refs #140 * fix(privacy): 按 Mac 客户端协议应答防窥请求,修复授权竞态 - FeatureFlag ff_private_screen=2(ENHANCED_PRIVACY),声明支持关屏 - 先回 RPC 7 应答再切换,避免客户端超时报 9998;切换失败发 ReportError -7 - 应答 RPC 25 update_screen_saver_req(RpcResponse 21),隐私模式不再被中止 - SettingMetric 4/7 上报开关与最近一次模式(host_settings.json privacy_type),状态变化推送 SystemStateChange 5 - portal 会话串行打开,打开失败回填一次性授权:快速重连时防窥切换与闭包恢复并发曾清空保存的授权 字段号与枚举取自官方 Mac 客户端的 SwiftProtobuf name map。 已知限制:Mac 客户端防窥菜单切换后仍显示"不启用",实际模式正确。 Refs #140 * fix(privacy): 处理 #146 评审意见 - 预检 uinput:injector 未打开 uinput(/dev/uinput 不可用或 UU_INPUT_BACKEND=native)时, 在改动输出和设备之前拒绝防窥(虚拟输出共享上 KDE 忽略 portal 输入) - leave() 中输入设备恢复失败在恢复输出后向上返回,保留 privacy-power.json 与 guard - record::ownership() 只缓存成功持锁,guard 轮询和 recover() 可重试 - 遮挡窗口就绪握手:privacy-wallpaper 建好窗口后输出 ready,5 秒内未就绪则报错并回滚 - rebase 到 main(#145):DMA-BUF 打开路径跳过虚拟输出、失败同样回填授权; #145 的 uinput 指针路径也按隐私模式的虚拟输出区域换算坐标 - README 表格压缩为一句,细节在 docs/privacy-screen.md Refs #140 * docs(privacy): 注明 ff_system_metrics=3 对应的枚举 Refs #140 * fix(privacy): resolve lifecycle and restoration review findings
86 lines
4.1 KiB
C
86 lines
4.1 KiB
C
// Privacy screen, wallpaper mode: a fullscreen keep-above window on each physical monitor showing
|
|
// a picture and a notice, while the remote session works on a KWin virtual output. Runs in its own
|
|
// process (`uuremote-server privacy-wallpaper`), which the host kills on restore.
|
|
#include <gtk/gtk.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "i18n.h"
|
|
|
|
typedef struct { int x, y, w, h; } Rect;
|
|
static GdkPixbuf *picture;
|
|
|
|
static gboolean host_closed(GIOChannel *channel, GIOCondition condition, gpointer data) {
|
|
(void)channel; (void)condition; (void)data;
|
|
gtk_main_quit();
|
|
return G_SOURCE_REMOVE;
|
|
}
|
|
|
|
static gboolean draw(GtkWidget *widget, cairo_t *cr, gpointer data) {
|
|
(void)data;
|
|
int w = gtk_widget_get_allocated_width(widget), h = gtk_widget_get_allocated_height(widget);
|
|
cairo_set_source_rgb(cr, 0, 0, 0); cairo_paint(cr);
|
|
if (picture) {
|
|
// Cover: scale to fill, crop the overflow, keep the aspect ratio.
|
|
double pw = gdk_pixbuf_get_width(picture), ph = gdk_pixbuf_get_height(picture);
|
|
double s = w / pw > h / ph ? w / pw : h / ph;
|
|
cairo_save(cr);
|
|
cairo_translate(cr, (w - pw * s) / 2, (h - ph * s) / 2);
|
|
cairo_scale(cr, s, s);
|
|
gdk_cairo_set_source_pixbuf(cr, picture, 0, 0);
|
|
cairo_paint(cr);
|
|
cairo_restore(cr);
|
|
}
|
|
PangoLayout *layout = gtk_widget_create_pango_layout(widget, L("此设备正在被远程控制", "This device is being remotely controlled"));
|
|
PangoFontDescription *font = pango_font_description_from_string("Sans 20");
|
|
pango_layout_set_font_description(layout, font);
|
|
int tw, th; pango_layout_get_pixel_size(layout, &tw, &th);
|
|
cairo_set_source_rgba(cr, 0, 0, 0, 0.45);
|
|
cairo_rectangle(cr, (w - tw) / 2.0 - 24, h - th - 96, tw + 48, th + 32); cairo_fill(cr);
|
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
|
cairo_move_to(cr, (w - tw) / 2.0, h - th - 80);
|
|
pango_cairo_show_layout(cr, layout);
|
|
pango_font_description_free(font); g_object_unref(layout);
|
|
return TRUE;
|
|
}
|
|
|
|
/* `rects` are the physical outputs in logical coordinates; monitors elsewhere (the virtual output)
|
|
* stay uncovered. Returns when every window is closed or the process is killed. */
|
|
int uu_privacy_wallpaper_run(const char *image, const int *rects, int count) {
|
|
if (!gtk_init_check(NULL, NULL)) return 1;
|
|
if (image && *image) picture = gdk_pixbuf_new_from_file(image, NULL);
|
|
GdkDisplay *display = gdk_display_get_default();
|
|
int shown = 0;
|
|
for (int i = 0; i < gdk_display_get_n_monitors(display); i++) {
|
|
GdkMonitor *monitor = gdk_display_get_monitor(display, i);
|
|
GdkRectangle g; gdk_monitor_get_geometry(monitor, &g);
|
|
int physical = 0;
|
|
for (int r = 0; r < count; r++) {
|
|
const int *c = rects + r * 4;
|
|
if (c[0] == g.x && c[1] == g.y && c[2] == g.width && c[3] == g.height) physical = 1;
|
|
}
|
|
if (!physical) continue;
|
|
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
gtk_window_set_title(GTK_WINDOW(window), "uu-remote-linux privacy");
|
|
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
|
|
gtk_window_set_keep_above(GTK_WINDOW(window), TRUE);
|
|
gtk_window_set_skip_taskbar_hint(GTK_WINDOW(window), TRUE);
|
|
gtk_window_set_skip_pager_hint(GTK_WINDOW(window), TRUE);
|
|
gtk_window_set_default_size(GTK_WINDOW(window), g.width, g.height);
|
|
g_signal_connect(window, "draw", G_CALLBACK(draw), NULL);
|
|
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
|
|
gtk_window_fullscreen_on_monitor(GTK_WINDOW(window), gtk_widget_get_screen(window), i);
|
|
gtk_widget_show_all(window);
|
|
shown++;
|
|
}
|
|
if (!shown) return 2;
|
|
/* EOF follows the host process, including crashes, rather than its spawning worker thread. */
|
|
GIOChannel *host = g_io_channel_unix_new(0);
|
|
guint watch = g_io_add_watch(host, G_IO_HUP | G_IO_ERR | G_IO_NVAL, host_closed, NULL);
|
|
/* Readiness handshake: the host treats picture mode as on only after this line. */
|
|
fputs("ready\n", stdout); fflush(stdout);
|
|
gtk_main();
|
|
if (g_main_context_find_source_by_id(NULL, watch)) g_source_remove(watch);
|
|
g_io_channel_unref(host);
|
|
return 0;
|
|
}
|