mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-15 21:20:09 +00:00
Add utility functions for portal paths
The paths that we create for requests and sessions need some icky code to create. Keep it in one place.
This commit is contained in:
parent
eb9f95e9fa
commit
b271db253f
@ -291,3 +291,39 @@ gtk_should_use_portal (void)
|
||||
|
||||
return use_portal[0] == '1';
|
||||
}
|
||||
|
||||
static char *
|
||||
get_portal_path (GDBusConnection *connection,
|
||||
const char *kind,
|
||||
char **token)
|
||||
{
|
||||
char *sender;
|
||||
int i;
|
||||
char *path;
|
||||
|
||||
*token = g_strdup_printf ("gtk%d", g_random_int_range (0, G_MAXINT));
|
||||
sender = g_strdup (g_dbus_connection_get_unique_name (connection) + 1);
|
||||
for (i = 0; sender[i]; i++)
|
||||
if (sender[i] == '.')
|
||||
sender[i] = '_';
|
||||
|
||||
path = g_strconcat (PORTAL_OBJECT_PATH, "/", kind, "/", sender, "/", token, NULL);
|
||||
|
||||
g_free (sender);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
char *
|
||||
gtk_get_portal_request_path (GDBusConnection *connection,
|
||||
char **token)
|
||||
{
|
||||
return get_portal_path (connection, "request", token);
|
||||
}
|
||||
|
||||
char *
|
||||
gtk_get_portal_session_path (GDBusConnection *connection,
|
||||
char **token)
|
||||
{
|
||||
return get_portal_path (connection, "session", token);
|
||||
}
|
||||
|
@ -110,6 +110,10 @@ gdouble _gtk_get_slowdown (void);
|
||||
void _gtk_set_slowdown (gdouble slowdown_factor);
|
||||
|
||||
gboolean gtk_should_use_portal (void);
|
||||
char *gtk_get_portal_request_path (GDBusConnection *connection,
|
||||
char **token);
|
||||
char *gtk_get_portal_session_path (GDBusConnection *connection,
|
||||
char **token);
|
||||
|
||||
#define PORTAL_BUS_NAME "org.freedesktop.portal.Desktop"
|
||||
#define PORTAL_OBJECT_PATH "/org/freedesktop/portal/desktop"
|
||||
|
Loading…
Reference in New Issue
Block a user