mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 16:50:41 +01:00
GNOME Portal:多显示器切换、精确触控、断开后停止共享 (#128)
* portal: switch monitors on GNOME, precise touch, stop sharing when idle GNOME grants one monitor per portal consent and refuses multi-select, so each Mutter monitor gets its own saved consent (gnome@<connector>). The monitors are advertised as screens; a switch opens that monitor's session (silently once consented, GNOME asks on the host the first time) and swaps it into the shared PortalSession, whose frame size follows the monitor. Absolute motion and clicks go through the portal session: a uinput tablet spans every monitor, and clicks on the separate uinput queue could land before the compositor moved the pointer. An idle watch ends the portal session (screen-share indicator off) once no desktop controller is left for two checks; the next one reopens it with the saved consent. Co-Authored-By: Claude Opus 5.5 <[email protected]> * portal: stop screen sharing as soon as the last controller leaves The idle watch stays as the fallback for controllers that vanish without a release event. Co-Authored-By: Claude Opus 5.5 <[email protected]> * portal test: accept the runtime-engine message in portal builds Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
e503041dac
commit
47c7728822
11 files changed
+279
-27
No files matched your search
@@ -56,7 +56,7 @@ struct uu_portal {
|
||||
int format_valid, stream_started;
|
||||
gint64 interrupted_at, display_changed_at;
|
||||
uint32_t node, width, height;
|
||||
int logical_width, logical_height;
|
||||
int logical_width, logical_height, position_x, position_y, has_position;
|
||||
int absolute_stream_pixels;
|
||||
struct ei *ei;
|
||||
GList *ei_devices;
|
||||
@@ -369,6 +369,7 @@ static int read_stream_result(struct uu_portal *p, GVariant *results) {
|
||||
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);
|
||||
p->has_position = g_variant_lookup(properties, "position", "(ii)", &p->position_x, &p->position_y);
|
||||
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);
|
||||
@@ -675,3 +676,63 @@ int uu_portal_key(struct uu_portal *p, uint32_t symbol, int keycode, int pressed
|
||||
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));
|
||||
}
|
||||
|
||||
/* Logical position of the granted monitor: matches a Mutter logical monitor. */
|
||||
int uu_portal_stream_position(struct uu_portal *p, int32_t *x, int32_t *y) {
|
||||
if (!p || !p->has_position) return 11;
|
||||
*x = p->position_x; *y = p->position_y;
|
||||
return 0;
|
||||
}
|
||||
/* Mutter's monitors as "connector\twidth\theight\tx\ty\tprimary\n" lines: current mode in
|
||||
* pixels, logical position. Returns the count, or -1 without Mutter (KDE, no session bus). */
|
||||
int uu_portal_monitors(char *out, size_t length) {
|
||||
if (!out || !length) return -1;
|
||||
out[0] = 0;
|
||||
GDBusConnection *bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
|
||||
if (!bus) return -1;
|
||||
GVariant *reply = g_dbus_connection_call_sync(bus, MUTTER_DISPLAY, MUTTER_DISPLAY_PATH, MUTTER_DISPLAY,
|
||||
"GetCurrentState", NULL, G_VARIANT_TYPE("(ua((ssss)a(siiddada{sv})a{sv})a(iiduba(ssss)a{sv})a{sv})"),
|
||||
G_DBUS_CALL_FLAGS_NONE, 3000, NULL, NULL);
|
||||
g_object_unref(bus);
|
||||
if (!reply) return -1;
|
||||
GVariant *monitors = g_variant_get_child_value(reply, 1), *logical = g_variant_get_child_value(reply, 2);
|
||||
int count = 0; size_t used = 0;
|
||||
for (gsize i = 0; i < g_variant_n_children(logical); i++) {
|
||||
gint32 x, y; gdouble scale; guint32 transform; gboolean primary; GVariant *specs, *props;
|
||||
g_variant_get_child(logical, i, "(iidub@a(ssss)@a{sv})", &x, &y, &scale, &transform, &primary, &specs, &props);
|
||||
const gchar *connector = NULL;
|
||||
if (g_variant_n_children(specs)) g_variant_get_child(specs, 0, "(&s&s&s&s)", &connector, NULL, NULL, NULL);
|
||||
gint32 width = 0, height = 0;
|
||||
for (gsize m = 0; connector && m < g_variant_n_children(monitors); m++) {
|
||||
GVariant *monitor = g_variant_get_child_value(monitors, m), *spec = g_variant_get_child_value(monitor, 0),
|
||||
*modes = g_variant_get_child_value(monitor, 1);
|
||||
const gchar *name = NULL; g_variant_get_child(spec, 0, "&s", &name);
|
||||
for (gsize k = 0; name && !strcmp(name, connector) && k < g_variant_n_children(modes); k++) {
|
||||
GVariant *mode = g_variant_get_child_value(modes, k), *mode_props = g_variant_get_child_value(mode, 6);
|
||||
gboolean current = FALSE;
|
||||
if (g_variant_lookup(mode_props, "is-current", "b", ¤t) && current)
|
||||
g_variant_get_child(mode, 1, "i", &width), g_variant_get_child(mode, 2, "i", &height);
|
||||
g_variant_unref(mode_props); g_variant_unref(mode);
|
||||
}
|
||||
g_variant_unref(modes); g_variant_unref(spec); g_variant_unref(monitor);
|
||||
}
|
||||
if (transform % 2) { gint32 t = width; width = height; height = t; } /* 90/270, flipped or not */
|
||||
if (connector && width > 0 && height > 0) {
|
||||
int n = snprintf(out + used, length - used, "%s\t%d\t%d\t%d\t%d\t%d\n", connector, width, height, x, y, primary ? 1 : 0);
|
||||
if (n > 0 && (size_t)n < length - used) { used += (size_t)n; count++; }
|
||||
}
|
||||
g_variant_unref(specs); g_variant_unref(props);
|
||||
}
|
||||
g_variant_unref(monitors); g_variant_unref(logical); g_variant_unref(reply);
|
||||
return count;
|
||||
}
|
||||
/* End the compositor session now (screen-share indicator off) while the handle stays valid;
|
||||
* captures then report a closed stream until the handle is replaced. */
|
||||
void uu_portal_end(struct uu_portal *p) {
|
||||
if (!p || atomic_exchange(&p->closed, 1)) return;
|
||||
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);
|
||||
if (reply) g_variant_unref(reply);
|
||||
}
|
||||
}
|
||||
@@ -26,4 +26,7 @@ int uu_portal_capture_since(struct uu_portal *portal, uint8_t *bgra, size_t leng
|
||||
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 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);
|
||||
void uu_portal_end(struct uu_portal *portal);
|
||||
#endif
|
||||
Reference in new issue
Block a user