Skip to content

Commit

Permalink
feat(xdp): support persistent sessions
Browse files Browse the repository at this point in the history
Support persistent remote desktop sessions when a recent enough libportal
is available.

closes #721
  • Loading branch information
andyholmes committed Aug 24, 2024
1 parent 00e6f85 commit 2978905
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ config_h_functions = {
'HAVE_CLOCK_GETTIME': 'clock_gettime',
'HAVE_LOCALTIME_R': 'localtime_r',
'HAVE_SCHED_GETCPU': 'sched_getcpu',
'HAVE_REMOTE_DESKTOP_FULL': 'xdp_portal_create_remote_desktop_session_full',
}

foreach define, function : config_h_functions
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/xdp/ca.andyholmes.Valent.Plugin.xdp.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
<key name="autostart" type="b">
<default>true</default>
</key>
<key name="session-token" type="s">
<default>''</default>
</key>
</schema>
</schemalist>
22 changes: 22 additions & 0 deletions src/plugins/xdp/valent-xdp-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ on_session_started (XdpSession *session,
g_clear_object (&self->session);
}

g_settings_set_string (self->settings,
"session-token",
xdp_session_get_restore_token (session));
self->session_starting = FALSE;
}

Expand Down Expand Up @@ -100,6 +103,7 @@ static gboolean
ensure_session (ValentXdpInput *self)
{
g_autoptr (GCancellable) cancellable = NULL;
g_autofree char *restore_token = NULL;

if G_LIKELY (self->started)
return TRUE;
Expand All @@ -109,6 +113,23 @@ ensure_session (ValentXdpInput *self)

self->session_starting = TRUE;
cancellable = valent_object_ref_cancellable (VALENT_OBJECT (self));
restore_token = g_settings_get_string (self->settings, "session-token");
if (!g_uuid_string_is_valid (restore_token))
g_clear_pointer (&restore_token, g_free);

#ifdef HAVE_REMOTE_DESKTOP_FULL
xdp_portal_create_remote_desktop_session_full (valent_xdp_get_default (),
(XDP_DEVICE_KEYBOARD |
XDP_DEVICE_POINTER),
XDP_OUTPUT_NONE,
XDP_REMOTE_DESKTOP_FLAG_NONE,
XDP_CURSOR_MODE_HIDDEN,
XDP_PERSIST_MODE_PERSISTENT,
restore_token,
cancellable,
(GAsyncReadyCallback)on_session_created,
self);
#else
xdp_portal_create_remote_desktop_session (valent_xdp_get_default (),
(XDP_DEVICE_KEYBOARD |
XDP_DEVICE_POINTER),
Expand All @@ -118,6 +139,7 @@ ensure_session (ValentXdpInput *self)
cancellable,
(GAsyncReadyCallback)on_session_created,
self);
#endif

return FALSE;
}
Expand Down

0 comments on commit 2978905

Please sign in to comment.