Application: Support sandboxed session state changes
React to the session-state in StateChanged signals from the inhibit portal and call QueryEndResponse as appropriate.
This commit is contained in:
parent
1e2bd15b22
commit
a3e070f59c
@ -193,6 +193,13 @@ screensaver_signal_session (GDBusProxy *proxy,
|
|||||||
gtk_application_set_screensaver_active (application, active);
|
gtk_application_set_screensaver_active (application, active);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum {
|
||||||
|
UNKNOWN = 0,
|
||||||
|
RUNNING = 1,
|
||||||
|
QUERY_END = 2,
|
||||||
|
ENDING = 3
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
screensaver_signal_portal (GDBusConnection *connection,
|
screensaver_signal_portal (GDBusConnection *connection,
|
||||||
const char *sender_name,
|
const char *sender_name,
|
||||||
@ -202,16 +209,42 @@ screensaver_signal_portal (GDBusConnection *connection,
|
|||||||
GVariant *parameters,
|
GVariant *parameters,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
GtkApplication *application = data;
|
GtkApplicationImplDBus *dbus = (GtkApplicationImplDBus *)data;
|
||||||
|
GtkApplication *application = data;
|
||||||
gboolean active;
|
gboolean active;
|
||||||
GVariant *state;
|
GVariant *state;
|
||||||
|
guint32 session_state = UNKNOWN;
|
||||||
|
|
||||||
if (!g_str_equal (signal_name, "StateChanged"))
|
if (!g_str_equal (signal_name, "StateChanged"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g_variant_get (parameters, "(o@a{sv})", NULL, &state);
|
g_variant_get (parameters, "(o@a{sv})", NULL, &state);
|
||||||
g_variant_lookup (state, "screensaver-active", "b", &active);
|
g_variant_lookup (state, "screensaver-active", "b", &active);
|
||||||
gtk_application_set_screensaver_active (application, active);
|
gtk_application_set_screensaver_active (dbus->impl.application, active);
|
||||||
|
|
||||||
|
g_variant_lookup (state, "session-state", "u", &session_state);
|
||||||
|
if (session_state != dbus->session_state)
|
||||||
|
{
|
||||||
|
dbus->session_state = session_state;
|
||||||
|
|
||||||
|
/* Note that we'll only ever get here if we get a session-state,
|
||||||
|
* in which case, the interface is new enough to have QueryEndResponse.
|
||||||
|
*/
|
||||||
|
if (session_state == ENDING)
|
||||||
|
{
|
||||||
|
g_application_quit (G_APPLICATION (application));
|
||||||
|
}
|
||||||
|
else if (session_state == QUERY_END)
|
||||||
|
{
|
||||||
|
g_dbus_proxy_call (dbus->inhibit_proxy,
|
||||||
|
"QueryEndResponse",
|
||||||
|
g_variant_new ("(o)", dbus->session_id),
|
||||||
|
G_DBUS_CALL_FLAGS_NONE,
|
||||||
|
G_MAXINT,
|
||||||
|
NULL,
|
||||||
|
NULL, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -455,7 +488,7 @@ gtk_application_impl_dbus_startup (GtkApplicationImpl *impl,
|
|||||||
NULL,
|
NULL,
|
||||||
G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE,
|
G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE,
|
||||||
screensaver_signal_portal,
|
screensaver_signal_portal,
|
||||||
impl->application,
|
dbus,
|
||||||
NULL);
|
NULL);
|
||||||
g_variant_builder_init (&opt_builder, G_VARIANT_TYPE_VARDICT);
|
g_variant_builder_init (&opt_builder, G_VARIANT_TYPE_VARDICT);
|
||||||
g_variant_builder_add (&opt_builder, "{sv}",
|
g_variant_builder_add (&opt_builder, "{sv}",
|
||||||
|
@ -139,6 +139,7 @@ typedef struct
|
|||||||
GSList *inhibit_handles;
|
GSList *inhibit_handles;
|
||||||
guint state_changed_handler;
|
guint state_changed_handler;
|
||||||
char * session_id;
|
char * session_id;
|
||||||
|
guint session_state;
|
||||||
} GtkApplicationImplDBus;
|
} GtkApplicationImplDBus;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
Loading…
Reference in New Issue
Block a user