[gtk+/wip/session: 4/5] GtkApplication: Add an inhibit api
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/session: 4/5] GtkApplication: Add an inhibit api
- Date: Wed, 4 Jan 2012 00:14:18 +0000 (UTC)
commit 43461bdc6d58aa32e21e40cb734efc4df531b05d
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Jan 3 15:02:49 2012 -0500
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.
gtk/gtk.symbols | 3 +
gtk/gtkapplication.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkapplication.h | 17 ++++++++
3 files changed, 128 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index 8ed3adf..7699959 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -223,12 +223,15 @@ gtk_application_get_app_menu
gtk_application_get_menubar
gtk_application_get_type
gtk_application_get_windows
+gtk_application_inhibit
+gtk_application_is_inhibited
gtk_application_new
gtk_application_quit_response
gtk_application_remove_accelerator
gtk_application_remove_window
gtk_application_set_app_menu
gtk_application_set_menubar
+gtk_application_uninhibit
gtk_application_window_get_show_menubar
gtk_application_window_get_type
gtk_application_window_new
diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c
index 111f12e..661d8e5 100644
--- a/gtk/gtkapplication.c
+++ b/gtk/gtkapplication.c
@@ -1065,4 +1065,112 @@ 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),
+ 0,
+ -1,
+ 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)
+{
+ GVariant *res;
+ GError *error = NULL;
+
+ 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_debug ("Calling Uninhibit\n");
+ res = g_dbus_proxy_call_sync (application->priv->sm_proxy,
+ "Uninhibit",
+ g_variant_new ("(u)", cookie),
+ 0,
+ -1,
+ NULL,
+ &error);
+ if (error)
+ {
+ g_warning ("Calling Uninhibit failed: %s\n", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ g_variant_unref (res);
+}
+
+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),
+ 0,
+ -1,
+ NULL,
+ &error);
+ if (error)
+ {
+ g_warning ("Calling IsInhibited failed: %s\n", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ inhibited = g_variant_get_boolean (res);
+ g_variant_unref (res);
+
+ return inhibited;
+}
+
#endif
diff --git a/gtk/gtkapplication.h b/gtk/gtkapplication.h
index 3bd7b20..35c40b4 100644
--- a/gtk/gtkapplication.h
+++ b/gtk/gtkapplication.h
@@ -104,6 +104,23 @@ void gtk_application_quit_response (GtkApplication *application
gboolean will_quit,
const gchar *reason);
+typedef enum
+{
+ GTK_APPLICATION_INHIBIT_LOGOUT = (1 << 0),
+ GTK_APPLICATION_INHIBIT_SWITCH = (1 << 1),
+ GTK_APPLICATION_INHIBIT_SUSPEND = (1 << 2),
+ GTK_APPLICATION_INHIBIT_IDLE = (1 << 3)
+} GtkApplicationInhibitFlags;
+
+guint gtk_application_inhibit (GtkApplication *application,
+ GtkWindow *window,
+ GtkApplicationInhibitFlags flags,
+ const gchar *reason);
+void gtk_application_uninhibit (GtkApplication *application,
+ guint cookie);
+gboolean gtk_application_is_inhibited (GtkApplication *application,
+ GtkApplicationInhibitFlags flags);
+
G_END_DECLS
#endif /* __GTK_APPLICATION_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]