[totem] lib: Add "window" property for screensaver inhibitor
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem] lib: Add "window" property for screensaver inhibitor
- Date: Thu, 10 Mar 2011 14:52:21 +0000 (UTC)
commit a1ed327b7522e884ed79dae4b7f4f57323adf365
Author: Bastien Nocera <hadess hadess net>
Date: Thu Mar 10 14:48:00 2011 +0000
lib: Add "window" property for screensaver inhibitor
So that we can pass the actual top-level window to the session.
lib/totem-scrsaver.c | 79 ++++++++++++++++++++++---------------------------
1 files changed, 36 insertions(+), 43 deletions(-)
---
diff --git a/lib/totem-scrsaver.c b/lib/totem-scrsaver.c
index 08847ad..47f96df 100644
--- a/lib/totem-scrsaver.c
+++ b/lib/totem-scrsaver.c
@@ -28,7 +28,7 @@
#include <glib/gi18n.h>
-#include <gdk/gdk.h>
+#include <gtk/gtk.h>
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
@@ -51,7 +51,8 @@
enum {
PROP_0,
- PROP_REASON
+ PROP_REASON,
+ PROP_WINDOW
};
static void totem_scrsaver_finalize (GObject *object);
@@ -63,8 +64,9 @@ struct TotemScrsaverPrivate {
char *reason;
GDBusProxy *gs_proxy;
- gboolean have_screensaver_dbus;
+ gboolean have_session_dbus;
guint32 cookie;
+ GtkWindow *window;
/* To save the screensaver info */
int timeout;
@@ -83,7 +85,7 @@ G_DEFINE_TYPE(TotemScrsaver, totem_scrsaver, G_TYPE_OBJECT)
static gboolean
screensaver_is_running_dbus (TotemScrsaver *scr)
{
- return scr->priv->have_screensaver_dbus;
+ return scr->priv->have_session_dbus;
}
static void
@@ -146,16 +148,26 @@ screensaver_inhibit_dbus (TotemScrsaver *scr,
gboolean inhibit)
{
TotemScrsaverPrivate *priv = scr->priv;
- guint xid;
+ GdkWindow *window;
- if (!priv->have_screensaver_dbus)
+ if (!priv->have_session_dbus)
return;
g_object_ref (scr);
- xid = 0;
if (inhibit) {
+ guint xid;
+
g_return_if_fail (scr->priv->reason != NULL);
+
+ xid = 0;
+ if (scr->priv->window != NULL) {
+ window = gtk_widget_get_window (GTK_WIDGET (scr->priv->window));
+ if (window != NULL)
+ xid = gdk_x11_window_get_xid (window);
+ }
+
+
g_dbus_proxy_call (priv->gs_proxy,
"Inhibit",
g_variant_new ("(susu)",
@@ -193,35 +205,6 @@ screensaver_disable_dbus (TotemScrsaver *scr)
}
static void
-screensaver_update_dbus_presence (TotemScrsaver *scr)
-{
- TotemScrsaverPrivate *priv = scr->priv;
- gchar *name_owner;
-
- name_owner = g_dbus_proxy_get_name_owner (priv->gs_proxy);
- if (name_owner) {
- priv->have_screensaver_dbus = TRUE;
- g_free (name_owner);
-
- /* screensaver just appeared, or reappeared */
- if (priv->reason != NULL)
- screensaver_disable_dbus (scr);
- } else {
- priv->have_screensaver_dbus = FALSE;
- }
-}
-
-static void
-screensaver_dbus_owner_changed_cb (GObject *object,
- GParamSpec *pspec,
- gpointer user_data)
-{
- TotemScrsaver *scr = TOTEM_SCRSAVER (user_data);
-
- screensaver_update_dbus_presence (scr);
-}
-
-static void
screensaver_dbus_proxy_new_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
@@ -233,11 +216,9 @@ screensaver_dbus_proxy_new_cb (GObject *source,
if (!priv->gs_proxy)
return;
- screensaver_update_dbus_presence (scr);
-
- g_signal_connect (priv->gs_proxy, "notify::g-name-owner",
- G_CALLBACK (screensaver_dbus_owner_changed_cb),
- scr);
+ priv->have_session_dbus = TRUE;
+ if (priv->reason != NULL && scr->priv->disabled)
+ screensaver_disable_dbus (scr);
}
static void
@@ -392,6 +373,9 @@ totem_scrsaver_get_property (GObject *object,
case PROP_REASON:
g_value_set_string (value, scr->priv->reason);
break;
+ case PROP_WINDOW:
+ g_value_set_object (value, scr->priv->window);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -413,6 +397,11 @@ totem_scrsaver_set_property (GObject *object,
g_free (scr->priv->reason);
scr->priv->reason = g_value_dup_string (value);
break;
+ case PROP_WINDOW:
+ if (scr->priv->window)
+ g_object_unref (scr->priv->window);
+ scr->priv->window = g_value_dup_object (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -432,7 +421,9 @@ totem_scrsaver_class_init (TotemScrsaverClass *klass)
g_object_class_install_property (object_class, PROP_REASON,
g_param_spec_string ("reason", NULL, NULL,
NULL, G_PARAM_READWRITE));
-
+ g_object_class_install_property (object_class, PROP_WINDOW,
+ g_param_spec_object ("window", NULL, NULL,
+ GTK_TYPE_WINDOW, G_PARAM_READWRITE));
}
/**
@@ -478,7 +469,7 @@ totem_scrsaver_disable (TotemScrsaver *scr)
if (screensaver_is_running_dbus (scr) != FALSE)
screensaver_disable_dbus (scr);
- else
+ else
#ifdef GDK_WINDOWING_X11
screensaver_disable_x11 (scr);
#else
@@ -528,6 +519,8 @@ totem_scrsaver_finalize (GObject *object)
TotemScrsaver *scr = TOTEM_SCRSAVER (object);
g_free (scr->priv->reason);
+ if (scr->priv->window != NULL)
+ g_object_unref (scr->priv->window);
screensaver_finalize_dbus (scr);
#ifdef GDK_WINDOWING_X11
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]