From d1e784d0e7b6cce4484aa84592e85acf936f40b5 Mon Sep 17 00:00:00 2001 From: Billy Date: Tue, 24 May 2022 17:45:59 +0100 Subject: [PATCH 1/4] Fixed issue where y was used instead of h. --- portal-test/gtk3/portal-test-win.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portal-test/gtk3/portal-test-win.c b/portal-test/gtk3/portal-test-win.c index 9d507083..e2432c6d 100644 --- a/portal-test/gtk3/portal-test-win.c +++ b/portal-test/gtk3/portal-test-win.c @@ -594,7 +594,7 @@ session_started (GObject *source, 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, y, x, y); + g_string_append_printf (s, "Stream %d: %dx%d @ %d,%d", id, w, h, x, y); g_variant_unref (props); } From 5d1e8ff4a937b2a3db6c3d3f2070115446944446 Mon Sep 17 00:00:00 2001 From: Billy Date: Fri, 27 May 2022 19:12:06 +0100 Subject: [PATCH 2/4] Added remote desktop example to portal test. --- portal-test/gtk3/portal-test-win.c | 111 +++++++++++++++++++++++++++- portal-test/gtk3/portal-test-win.ui | 71 +++++++++++++----- 2 files changed, 159 insertions(+), 23 deletions(-) diff --git a/portal-test/gtk3/portal-test-win.c b/portal-test/gtk3/portal-test-win.c index e2432c6d..04e86ec2 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_variant_unref (props); + } + + 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 @@ 1 end - Network + Remote Desktop 0 8 + + + 1 + Remote Desktop + + + + 1 + 8 + + + + + 1 + end + + + 2 + 8 + + + + + + 1 + end + Network + + + 0 + 9 + + 1 @@ -416,7 +449,7 @@ 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 From 5004756a2736a94327247331253c9836aa897ac9 Mon Sep 17 00:00:00 2001 From: bjaraujo Date: Sat, 24 Feb 2024 21:36:03 +0000 Subject: [PATCH 3/4] Update portal-test/gtk3/portal-test-win.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Hubert Figuière --- portal-test/gtk3/portal-test-win.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portal-test/gtk3/portal-test-win.c b/portal-test/gtk3/portal-test-win.c index 04e86ec2..79f30696 100644 --- a/portal-test/gtk3/portal-test-win.c +++ b/portal-test/gtk3/portal-test-win.c @@ -674,7 +674,7 @@ remote_desktop_session_started (GObject *source, guint id; g_autoptr(GVariantIter) iter = NULL; GVariant *props; - g_autoptr (GString) s = NULL; + g_autoptr(GString) s = NULL; if (!xdp_session_start_finish (session, result, &error)) { From b51501d4790af077d6ae20b5cd175118b8b80aae Mon Sep 17 00:00:00 2001 From: bjaraujo Date: Sat, 24 Feb 2024 21:36:15 +0000 Subject: [PATCH 4/4] Update portal-test/gtk3/portal-test-win.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Hubert Figuière --- portal-test/gtk3/portal-test-win.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portal-test/gtk3/portal-test-win.c b/portal-test/gtk3/portal-test-win.c index 79f30696..e961c9ba 100644 --- a/portal-test/gtk3/portal-test-win.c +++ b/portal-test/gtk3/portal-test-win.c @@ -696,7 +696,7 @@ remote_desktop_session_started (GObject *source, 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_variant_unref (props); + g_clear_pointer (&props, g_variant_unref); } gtk_label_set_label (GTK_LABEL (win->remote_desktop_label), s->str);