diff --git a/portal-test/gtk3/portal-test-win.c b/portal-test/gtk3/portal-test-win.c
index e2432c6d..e961c9ba 100644
--- a/portal-test/gtk3/portal-test-win.c
+++ b/portal-test/gtk3/portal-test-win.c
@@ -63,6 +63,9 @@ struct _PortalTestWin
GtkWidget *screencast_label;
GtkWidget *screencast_toggle;
+ GtkWidget *remote_desktop_label;
+ GtkWidget *remote_desktop_toggle;
+
GFileMonitor *update_monitor;
GtkWidget *update_dialog;
GtkWidget *update_dialog2;
@@ -563,7 +566,7 @@ take_screenshot (GtkButton *button,
}
static void
-session_started (GObject *source,
+screencast_session_started (GObject *source,
GAsyncResult *result,
gpointer data)
{
@@ -602,7 +605,7 @@ session_started (GObject *source,
}
static void
-session_created (GObject *source,
+screencast_session_created (GObject *source,
GAsyncResult *result,
gpointer data)
{
@@ -619,7 +622,7 @@ session_created (GObject *source,
}
parent = xdp_parent_new_gtk (GTK_WINDOW (win));
- xdp_session_start (win->session, parent, NULL, session_started, win);
+ xdp_session_start (win->session, parent, NULL, screencast_session_started, win);
xdp_parent_free (parent);
}
@@ -635,7 +638,7 @@ start_screencast (PortalTestWin *win)
XDP_PERSIST_MODE_NONE,
NULL,
NULL,
- session_created,
+ screencast_session_created,
win);
}
@@ -660,6 +663,103 @@ screencast_toggled (GtkToggleButton *button,
stop_screencast (win);
}
+static void
+remote_desktop_session_started (GObject *source,
+ GAsyncResult *result,
+ gpointer data)
+{
+ XdpSession *session = (XdpSession*) source;
+ PortalTestWin *win = data;
+ g_autoptr(GError) error = NULL;
+ guint id;
+ g_autoptr(GVariantIter) iter = NULL;
+ GVariant *props;
+ g_autoptr(GString) s = NULL;
+
+ if (!xdp_session_start_finish (session, result, &error))
+ {
+ g_warning ("Failed to start remote desktop session: %s", error->message);
+ g_clear_object (&win->session);
+ gtk_label_set_label (GTK_LABEL (win->remote_desktop_label), "");
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (win->remote_desktop_toggle), FALSE);
+ return;
+ }
+
+ s = g_string_new ("");
+
+ iter = g_variant_iter_new (xdp_session_get_streams (session));
+ while (g_variant_iter_next (iter, "(u@a{sv})", &id, &props))
+ {
+ int x, y, w, h;
+ g_variant_lookup (props, "position", "(ii)", &x, &y);
+ g_variant_lookup (props, "size", "(ii)", &w, &h);
+ if (s->len > 0)
+ g_string_append (s, "\n");
+ g_string_append_printf (s, "Stream %d: %dx%d @ %d,%d", id, w, h, x, y);
+ g_clear_pointer (&props, g_variant_unref);
+ }
+
+ gtk_label_set_label (GTK_LABEL (win->remote_desktop_label), s->str);
+}
+
+static void
+remote_desktop_session_created (GObject *source,
+ GAsyncResult *result,
+ gpointer data)
+{
+ XdpPortal *portal = XDP_PORTAL (source);
+ PortalTestWin *win = data;
+ g_autoptr(GError) error = NULL;
+ XdpParent *parent = NULL;
+
+ win->session = xdp_portal_create_remote_desktop_session_finish (portal, result, &error);
+ if (win->session == NULL)
+ {
+ g_warning ("Failed to create remote desktop session: %s", error->message);
+ return;
+ }
+
+ parent = xdp_parent_new_gtk (GTK_WINDOW (win));
+ xdp_session_start (win->session, parent, NULL, remote_desktop_session_started, win);
+ xdp_parent_free (parent);
+}
+
+static void
+start_remote_desktop (PortalTestWin *win)
+{
+ g_clear_object (&win->session);
+
+ xdp_portal_create_remote_desktop_session (win->portal,
+ XDP_DEVICE_POINTER,
+ XDP_OUTPUT_MONITOR | XDP_OUTPUT_WINDOW,
+ XDP_REMOTE_DESKTOP_FLAG_NONE,
+ XDP_CURSOR_MODE_HIDDEN,
+ NULL,
+ remote_desktop_session_created,
+ win);
+}
+
+static void
+stop_remote_desktop (PortalTestWin *win)
+{
+ if (win->session != NULL)
+ {
+ xdp_session_close (win->session);
+ g_clear_object (&win->session);
+ gtk_label_set_label (GTK_LABEL (win->remote_desktop_label), "");
+ }
+}
+
+static void
+remote_desktop_toggled (GtkToggleButton *button,
+ PortalTestWin *win)
+{
+ if (gtk_toggle_button_get_active (button))
+ start_remote_desktop (win);
+ else
+ stop_remote_desktop (win);
+}
+
static void
account_response (GObject *source,
GAsyncResult *result,
@@ -1249,6 +1349,7 @@ portal_test_win_class_init (PortalTestWinClass *class)
gtk_widget_class_bind_template_callback (widget_class, open_local);
gtk_widget_class_bind_template_callback (widget_class, take_screenshot);
gtk_widget_class_bind_template_callback (widget_class, screencast_toggled);
+ gtk_widget_class_bind_template_callback (widget_class, remote_desktop_toggled);
gtk_widget_class_bind_template_callback (widget_class, notify_me);
gtk_widget_class_bind_template_callback (widget_class, print_cb);
gtk_widget_class_bind_template_callback (widget_class, inhibit_changed);
@@ -1276,6 +1377,8 @@ portal_test_win_class_init (PortalTestWinClass *class)
gtk_widget_class_bind_template_child (widget_class, PortalTestWin, save_how);
gtk_widget_class_bind_template_child (widget_class, PortalTestWin, screencast_label);
gtk_widget_class_bind_template_child (widget_class, PortalTestWin, screencast_toggle);
+ gtk_widget_class_bind_template_child (widget_class, PortalTestWin, remote_desktop_label);
+ gtk_widget_class_bind_template_child (widget_class, PortalTestWin, remote_desktop_toggle);
gtk_widget_class_bind_template_child (widget_class, PortalTestWin, update_dialog);
gtk_widget_class_bind_template_child (widget_class, PortalTestWin, update_dialog2);
gtk_widget_class_bind_template_child (widget_class, PortalTestWin, update_progressbar);
diff --git a/portal-test/gtk3/portal-test-win.ui b/portal-test/gtk3/portal-test-win.ui
index 7112a190..fc33157d 100644
--- a/portal-test/gtk3/portal-test-win.ui
+++ b/portal-test/gtk3/portal-test-win.ui
@@ -402,13 +402,46 @@
0
8
+
+
+
+ 1
+ 8
+
+
+
+
+
+ 2
+ 8
+
+
+
+
+
+
+ 0
+ 9
+
+
1
- 8
+ 9
@@ -426,7 +459,7 @@
2
- 8
+ 9
2
@@ -439,7 +472,7 @@
0
- 9
+ 10
@@ -449,7 +482,7 @@
1
- 9
+ 10
@@ -459,7 +492,7 @@
2
- 9
+ 10
2
@@ -472,7 +505,7 @@
0
- 10
+ 11
@@ -484,7 +517,7 @@
1
- 10
+ 11
@@ -496,7 +529,7 @@
2
- 10
+ 11
@@ -508,7 +541,7 @@
0
- 11
+ 12
@@ -520,7 +553,7 @@
1
- 11
+ 12
@@ -532,7 +565,7 @@
0
- 12
+ 13
@@ -573,7 +606,7 @@
1
- 12
+ 13
2
@@ -586,7 +619,7 @@
0
- 13
+ 14
@@ -598,7 +631,7 @@
1
- 13
+ 14
@@ -610,7 +643,7 @@
0
- 14
+ 15
@@ -622,7 +655,7 @@
1
- 14
+ 15
@@ -633,7 +666,7 @@
1
- 15
+ 16
@@ -653,7 +686,7 @@
- 1
+ 2
16