Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 107 additions & 4 deletions portal-test/gtk3/portal-test-win.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -563,7 +566,7 @@ take_screenshot (GtkButton *button,
}

static void
session_started (GObject *source,
screencast_session_started (GObject *source,
GAsyncResult *result,
gpointer data)
{
Expand Down Expand Up @@ -602,7 +605,7 @@ session_started (GObject *source,
}

static void
session_created (GObject *source,
screencast_session_created (GObject *source,
GAsyncResult *result,
gpointer data)
{
Expand All @@ -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);
}

Expand All @@ -635,7 +638,7 @@ start_screencast (PortalTestWin *win)
XDP_PERSIST_MODE_NONE,
NULL,
NULL,
session_created,
screencast_session_created,
win);
}

Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
71 changes: 52 additions & 19 deletions portal-test/gtk3/portal-test-win.ui
Original file line number Diff line number Diff line change
Expand Up @@ -402,21 +402,54 @@
<object class="GtkLabel">
<property name="visible">1</property>
<property name="halign">end</property>
<property name="label">Network</property>
<property name="label">Remote Desktop</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">8</property>
</packing>
</child>
<child>
<object class="GtkToggleButton" id="remote_desktop_toggle">
<property name="visible">1</property>
<property name="label">Remote Desktop</property>
<signal name="toggled" handler="remote_desktop_toggled"/>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">8</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="remote_desktop_label">
<property name="visible">1</property>
<property name="halign">end</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">8</property>
</packing>
</child>

<child>
<object class="GtkLabel">
<property name="visible">1</property>
<property name="halign">end</property>
<property name="label">Network</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">9</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="monitor_name">
<property name="visible">1</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">8</property>
<property name="top-attach">9</property>
</packing>
</child>
<child>
Expand All @@ -426,7 +459,7 @@
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">8</property>
<property name="top-attach">9</property>
<property name="width">2</property>
</packing>
</child>
Expand All @@ -439,7 +472,7 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">9</property>
<property name="top-attach">10</property>
</packing>
</child>
<child>
Expand All @@ -449,7 +482,7 @@
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">9</property>
<property name="top-attach">10</property>
</packing>
</child>
<child>
Expand All @@ -459,7 +492,7 @@
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">9</property>
<property name="top-attach">10</property>
<property name="width">2</property>
</packing>
</child>
Expand All @@ -472,7 +505,7 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">10</property>
<property name="top-attach">11</property>
</packing>
</child>
<child>
Expand All @@ -484,7 +517,7 @@
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">10</property>
<property name="top-attach">11</property>
</packing>
</child>
<child>
Expand All @@ -496,7 +529,7 @@
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">10</property>
<property name="top-attach">11</property>
</packing>
</child>

Expand All @@ -508,7 +541,7 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">11</property>
<property name="top-attach">12</property>
</packing>
</child>
<child>
Expand All @@ -520,7 +553,7 @@
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">11</property>
<property name="top-attach">12</property>
</packing>
</child>

Expand All @@ -532,7 +565,7 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">12</property>
<property name="top-attach">13</property>
</packing>
</child>
<child>
Expand Down Expand Up @@ -573,7 +606,7 @@
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">12</property>
<property name="top-attach">13</property>
<property name="width">2</property>
</packing>
</child>
Expand All @@ -586,7 +619,7 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">13</property>
<property name="top-attach">14</property>
</packing>
</child>
<child>
Expand All @@ -598,7 +631,7 @@
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">13</property>
<property name="top-attach">14</property>
</packing>
</child>

Expand All @@ -610,7 +643,7 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">14</property>
<property name="top-attach">15</property>
</packing>
</child>
<child>
Expand All @@ -622,7 +655,7 @@
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">14</property>
<property name="top-attach">15</property>
</packing>
</child>

Expand All @@ -633,7 +666,7 @@
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">15</property>
<property name="top-attach">16</property>
</packing>
</child>
<child>
Expand All @@ -653,7 +686,7 @@
<property name="label"></property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="left-attach">2</property>
<property name="top-attach">16</property>
</packing>
</child>
Expand Down