summaryrefslogtreecommitdiff
path: root/gtk/gtkapplication.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2012-01-03 15:02:49 -0500
committerMatthias Clasen <mclasen@redhat.com>2012-01-07 03:20:56 -0500
commitbdd7e15c849cd641000e0efddaeacfe420b1b3e4 (patch)
tree2ec0ec68d5c8cc2dc7127e755b45426b955764e6 /gtk/gtkapplication.c
parent31337913025090266926fd318e872e5d6f8dd101 (diff)
downloadgtk+-bdd7e15c849cd641000e0efddaeacfe420b1b3e4.tar.gz
GtkApplication: Add an inhibit api
This lets applications block logout and similar actions ahead of time. Currently only implemented for D-Bus, but Windows has very similar API since Vista.
Diffstat (limited to 'gtk/gtkapplication.c')
-rw-r--r--gtk/gtkapplication.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c
index 7f3f252148..7ee766f641 100644
--- a/gtk/gtkapplication.c
+++ b/gtk/gtkapplication.c
@@ -1073,6 +1073,7 @@ gtk_application_startup_session_dbus (GtkApplication *app)
g_variant_unref (res);
g_debug ("Registered client at '%s'", app->priv->client_path);
+
app->priv->client_proxy = g_dbus_proxy_new_sync (app->priv->session_bus, 0,
NULL,
"org.gnome.SessionManager",
@@ -1112,4 +1113,100 @@ gtk_application_quit_response (GtkApplication *application,
NULL, NULL, NULL);
}
+guint
+gtk_application_inhibit (GtkApplication *application,
+ GtkWindow *window,
+ GtkApplicationInhibitFlags flags,
+ const gchar *reason)
+{
+ GVariant *res;
+ GError *error = NULL;
+ guint cookie;
+ guint xid;
+
+ g_return_val_if_fail (GTK_IS_APPLICATION (application), 0);
+ g_return_val_if_fail (!g_application_get_is_remote (G_APPLICATION (application)), 0);
+ g_return_val_if_fail (application->priv->sm_proxy != NULL, 0);
+
+ g_debug ("Calling Inhibit\n");
+
+ if (window != NULL)
+ xid = GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (window)));
+ else
+ xid = 0;
+
+ res = g_dbus_proxy_call_sync (application->priv->sm_proxy,
+ "Inhibit",
+ g_variant_new ("(susu)",
+ application->priv->app_id,
+ xid,
+ reason,
+ flags),
+ G_DBUS_CALL_FLAGS_NONE,
+ G_MAXINT,
+ NULL,
+ &error);
+ if (error)
+ {
+ g_warning ("Calling Inhibit failed: %s\n", error->message);
+ g_error_free (error);
+ return 0;
+ }
+
+ g_variant_get (res, "(u)", &cookie);
+ g_variant_unref (res);
+
+ return cookie;
+}
+
+void
+gtk_application_uninhibit (GtkApplication *application,
+ guint cookie)
+{
+ g_return_if_fail (GTK_IS_APPLICATION (application));
+ g_return_if_fail (!g_application_get_is_remote (G_APPLICATION (application)));
+ g_return_if_fail (application->priv->sm_proxy != NULL);
+
+ g_dbus_proxy_call (application->priv->sm_proxy,
+ "Uninhibit",
+ g_variant_new ("(u)", cookie),
+ G_DBUS_CALL_FLAGS_NONE,
+ G_MAXINT,
+ NULL, NULL, NULL);
+}
+
+gboolean
+gtk_application_is_inhibited (GtkApplication *application,
+ GtkApplicationInhibitFlags flags)
+{
+ GVariant *res;
+ GError *error = NULL;
+ gboolean inhibited;
+
+ g_return_val_if_fail (GTK_IS_APPLICATION (application), FALSE);
+ g_return_val_if_fail (!g_application_get_is_remote (G_APPLICATION (application)), FALSE);
+ g_return_val_if_fail (application->priv->sm_proxy != NULL, FALSE);
+
+ g_debug ("Calling IsInhibited\n");
+
+ res = g_dbus_proxy_call_sync (application->priv->sm_proxy,
+ "IsInhibited",
+ g_variant_new ("(u)", flags),
+ G_DBUS_CALL_FLAGS_NONE,
+ G_MAXINT,
+ NULL,
+ &error);
+ if (error)
+ {
+ g_warning ("Calling IsInhibited failed: %s\n", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ g_variant_get (res, "(b)", &inhibited);
+ g_variant_unref (res);
+
+ return inhibited;
+}
+
#endif