]> www.fi.muni.cz Git - evince.git/blobdiff - cut-n-paste/totem-screensaver/totem-scrsaver.c
totem-screensaver: Update from totem sources
[evince.git] / cut-n-paste / totem-screensaver / totem-scrsaver.c
index ba05d3f77aa2756ad1388cf294a8d07ebf776b12..aaa74bd9cf41ff80cf47a688936a88362e12f749 100644 (file)
@@ -2,6 +2,7 @@
 
    Copyright (C) 2004-2006 Bastien Nocera <hadess@hadess.net>
    Copyright © 2010 Christian Persch
 
    Copyright (C) 2004-2006 Bastien Nocera <hadess@hadess.net>
    Copyright © 2010 Christian Persch
+   Copyright © 2010 Carlos Garcia Campos
 
    The Gnome Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public License as
 
    The Gnome Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public License as
    write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301  USA.
 
    write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301  USA.
 
-   Author: Bastien Nocera <hadess@hadess.net>
+   Authors: Bastien Nocera <hadess@hadess.net>
+            Christian Persch
+            Carlos Garcia Campos
  */
 
  */
 
-
 #include "config.h"
 
 #include <glib/gi18n.h>
 
 #include "config.h"
 
 #include <glib/gi18n.h>
 
-#include <gdk/gdk.h>
+#include <gtk/gtk.h>
 
 #ifdef GDK_WINDOWING_X11
 #include <gdk/gdkx.h>
 
 #ifdef GDK_WINDOWING_X11
 #include <gdk/gdkx.h>
 
 #include "totem-scrsaver.h"
 
 
 #include "totem-scrsaver.h"
 
-#define GS_SERVICE   "org.gnome.ScreenSaver"
-#define GS_PATH      "/org/gnome/ScreenSaver"
-#define GS_INTERFACE "org.gnome.ScreenSaver"
+#define GS_SERVICE   "org.gnome.SessionManager"
+#define GS_PATH      "/org/gnome/SessionManager"
+#define GS_INTERFACE "org.gnome.SessionManager"
+/* From org.gnome.SessionManager.xml */
+#define GS_NO_IDLE_FLAG 8
 
 #define XSCREENSAVER_MIN_TIMEOUT 60
 
 
 #define XSCREENSAVER_MIN_TIMEOUT 60
 
+enum {
+       PROP_0,
+       PROP_REASON,
+       PROP_WINDOW
+};
+
 static void totem_scrsaver_finalize   (GObject *object);
 
 struct TotemScrsaverPrivate {
        /* Whether the screensaver is disabled */
        gboolean disabled;
 static void totem_scrsaver_finalize   (GObject *object);
 
 struct TotemScrsaverPrivate {
        /* Whether the screensaver is disabled */
        gboolean disabled;
+       /* The reason for the inhibition */
+       char *reason;
 
        GDBusProxy *gs_proxy;
 
        GDBusProxy *gs_proxy;
-        gboolean have_screensaver_dbus;
-        guint watch_id;
+        gboolean have_session_dbus;
        guint32 cookie;
        guint32 cookie;
+       GtkWindow *window;
 
        /* To save the screensaver info */
        int timeout;
 
        /* To save the screensaver info */
        int timeout;
@@ -73,7 +85,62 @@ G_DEFINE_TYPE(TotemScrsaver, totem_scrsaver, G_TYPE_OBJECT)
 static gboolean
 screensaver_is_running_dbus (TotemScrsaver *scr)
 {
 static gboolean
 screensaver_is_running_dbus (TotemScrsaver *scr)
 {
-        return scr->priv->have_screensaver_dbus;
+        return scr->priv->have_session_dbus;
+}
+
+static void
+on_inhibit_cb (GObject      *source_object,
+              GAsyncResult *res,
+              gpointer      user_data)
+{
+       GDBusProxy    *proxy = G_DBUS_PROXY (source_object);
+       TotemScrsaver *scr = TOTEM_SCRSAVER (user_data);
+       GVariant      *value;
+       GError        *error = NULL;
+
+       value = g_dbus_proxy_call_finish (proxy, res, &error);
+       if (!value) {
+               g_warning ("Problem inhibiting the screensaver: %s", error->message);
+               g_object_unref (scr);
+               g_error_free (error);
+
+               return;
+       }
+
+       /* save the cookie */
+       if (g_variant_is_of_type (value, G_VARIANT_TYPE ("(u)")))
+               g_variant_get (value, "(u)", &scr->priv->cookie);
+       else
+               scr->priv->cookie = 0;
+       g_variant_unref (value);
+
+       g_object_unref (scr);
+}
+
+static void
+on_uninhibit_cb (GObject      *source_object,
+                GAsyncResult *res,
+                gpointer      user_data)
+{
+       GDBusProxy    *proxy = G_DBUS_PROXY (source_object);
+       TotemScrsaver *scr = TOTEM_SCRSAVER (user_data);
+       GVariant      *value;
+       GError        *error = NULL;
+
+       value = g_dbus_proxy_call_finish (proxy, res, &error);
+       if (!value) {
+               g_warning ("Problem uninhibiting the screensaver: %s", error->message);
+               g_object_unref (scr);
+               g_error_free (error);
+
+               return;
+       }
+
+       /* clear the cookie */
+       scr->priv->cookie = 0;
+       g_variant_unref (value);
+
+       g_object_unref (scr);
 }
 
 static void
 }
 
 static void
@@ -81,72 +148,48 @@ screensaver_inhibit_dbus (TotemScrsaver *scr,
                          gboolean       inhibit)
 {
         TotemScrsaverPrivate *priv = scr->priv;
                          gboolean       inhibit)
 {
         TotemScrsaverPrivate *priv = scr->priv;
-       GError *error = NULL;
-        GVariant *value;
+        GdkWindow *window;
 
 
-        if (!priv->have_screensaver_dbus)
+        if (!priv->have_session_dbus)
                 return;
 
                 return;
 
+       g_object_ref (scr);
+
        if (inhibit) {
        if (inhibit) {
-                value = g_dbus_proxy_call_sync (priv->gs_proxy,
-                                               "Inhibit",
-                                               g_variant_new ("(ss)",
-                                                              "Evince",
-                                                              _("Running in presentation mode")),
-                                               G_DBUS_CALL_FLAGS_NO_AUTO_START,
-                                               -1,
-                                               NULL,
-                                               &error);
-               if (error && g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD)) {
-                       /* try the old API */
-                        g_clear_error (&error);
-                        value = g_dbus_proxy_call_sync (priv->gs_proxy,
-                                                       "InhibitActivation",
-                                                       g_variant_new ("(s)",
-                                                                      _("Running in presentation mode")),
-                                                       G_DBUS_CALL_FLAGS_NO_AUTO_START,
-                                                       -1,
-                                                       NULL,
-                                                       &error);
-                }
-                if (value != NULL) {
-                       /* save the cookie */
-                        if (g_variant_is_of_type (value, G_VARIANT_TYPE ("(u)")))
-                              g_variant_get (value, "(u)", &priv->cookie);
-                        else
-                                priv->cookie = 0;
-                        g_variant_unref (value);
-               } else {
-                       g_warning ("Problem inhibiting the screensaver: %s", error->message);
-                        g_error_free (error);
+               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)",
+                                                 g_get_application_name (),
+                                                 xid,
+                                                 scr->priv->reason,
+                                                 GS_NO_IDLE_FLAG),
+                                  G_DBUS_CALL_FLAGS_NO_AUTO_START,
+                                  -1,
+                                  NULL,
+                                  on_inhibit_cb,
+                                  scr);
        } else {
        } else {
-                value = g_dbus_proxy_call_sync (priv->gs_proxy,
-                                               "UnInhibit",
-                                               g_variant_new ("(u)", priv->cookie),
-                                               G_DBUS_CALL_FLAGS_NO_AUTO_START,
-                                               -1,
-                                               NULL,
-                                               &error);
-               if (error && g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD)) {
-                       /* try the old API */
-                        g_clear_error (&error);
-                        value = g_dbus_proxy_call_sync (priv->gs_proxy,
-                                                       "AllowActivation",
-                                                       g_variant_new ("()"),
-                                                       G_DBUS_CALL_FLAGS_NO_AUTO_START,
-                                                       -1,
-                                                       NULL,
-                                                       &error);
-                }
-                if (value != NULL) {
-                       /* clear the cookie */
-                       priv->cookie = 0;
-                        g_variant_unref (value);
-               } else {
-                       g_warning ("Problem uninhibiting the screensaver: %s", error->message);
-                       g_error_free (error);
+               if (priv->cookie > 0) {
+                       g_dbus_proxy_call (priv->gs_proxy,
+                                          "Uninhibit",
+                                          g_variant_new ("(u)", priv->cookie),
+                                          G_DBUS_CALL_FLAGS_NO_AUTO_START,
+                                          -1,
+                                          NULL,
+                                          on_uninhibit_cb,
+                                          scr);
                }
        }
 }
                }
        }
 }
@@ -164,65 +207,42 @@ screensaver_disable_dbus (TotemScrsaver *scr)
 }
 
 static void
 }
 
 static void
-screensaver_dbus_appeared_cb (GDBusConnection *connection,
-                             const gchar     *name,
-                             const gchar     *name_owner,
-                             GDBusProxy      *proxy,
-                             gpointer         user_data)
+screensaver_dbus_proxy_new_cb (GObject      *source,
+                               GAsyncResult *result,
+                               gpointer      user_data)
 {
 {
-        TotemScrsaver *scr = TOTEM_SCRSAVER (user_data);
-        TotemScrsaverPrivate *priv = scr->priv;
-
-       priv->gs_proxy = g_object_ref (proxy);
-
-        priv->have_screensaver_dbus = TRUE;
-}
-
-static void
-screensaver_dbus_disappeared_cb (GDBusConnection *connection,
-                                const gchar     *name,
-                                gpointer         user_data)
-{
-        TotemScrsaver *scr = TOTEM_SCRSAVER (user_data);
-        TotemScrsaverPrivate *priv = scr->priv;
+       TotemScrsaver *scr = TOTEM_SCRSAVER (user_data);
+       TotemScrsaverPrivate *priv = scr->priv;
 
 
-       if (priv->gs_proxy) {
-               g_object_unref (priv->gs_proxy);
-               priv->gs_proxy = NULL;
-       }
+       priv->gs_proxy = g_dbus_proxy_new_for_bus_finish (result, NULL);
+       if (!priv->gs_proxy)
+               return;
 
 
-        priv->have_screensaver_dbus = FALSE;
+       priv->have_session_dbus = TRUE;
+       if (priv->reason != NULL && scr->priv->disabled)
+               screensaver_disable_dbus (scr);
 }
 
 static void
 screensaver_init_dbus (TotemScrsaver *scr)
 {
 }
 
 static void
 screensaver_init_dbus (TotemScrsaver *scr)
 {
-       TotemScrsaverPrivate *priv = scr->priv;
-
-        priv->watch_id = g_bus_watch_proxy (G_BUS_TYPE_SESSION,
-                                           GS_SERVICE,
-                                           G_BUS_NAME_WATCHER_FLAGS_NONE,
-                                           GS_PATH,
-                                           GS_INTERFACE,
-                                           G_TYPE_DBUS_PROXY,
-                                           G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
-                                           G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
-                                           screensaver_dbus_appeared_cb,
-                                           screensaver_dbus_disappeared_cb,
-                                           scr, NULL);
+        g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
+                                 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+                                 NULL,
+                                 GS_SERVICE,
+                                 GS_PATH,
+                                 GS_INTERFACE,
+                                 NULL,
+                                 screensaver_dbus_proxy_new_cb,
+                                 scr);
 }
 
 static void
 screensaver_finalize_dbus (TotemScrsaver *scr)
 {
 }
 
 static void
 screensaver_finalize_dbus (TotemScrsaver *scr)
 {
-        TotemScrsaverPrivate *priv = scr->priv;
-
        if (scr->priv->gs_proxy) {
                g_object_unref (scr->priv->gs_proxy);
        }
        if (scr->priv->gs_proxy) {
                g_object_unref (scr->priv->gs_proxy);
        }
-
-       if (priv->watch_id > 0)
-               g_bus_unwatch_proxy (priv->watch_id);
 }
 
 #ifdef GDK_WINDOWING_X11
 }
 
 #ifdef GDK_WINDOWING_X11
@@ -238,13 +258,13 @@ screensaver_enable_x11 (TotemScrsaver *scr)
        }
 #endif /* HAVE_XTEST */
 
        }
 #endif /* HAVE_XTEST */
 
-       XLockDisplay (GDK_DISPLAY());
-       XSetScreenSaver (GDK_DISPLAY(),
+       XLockDisplay (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
+       XSetScreenSaver (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
                        scr->priv->timeout,
                        scr->priv->interval,
                        scr->priv->prefer_blanking,
                        scr->priv->allow_exposures);
                        scr->priv->timeout,
                        scr->priv->interval,
                        scr->priv->prefer_blanking,
                        scr->priv->allow_exposures);
-       XUnlockDisplay (GDK_DISPLAY());
+       XUnlockDisplay (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
 }
 
 #ifdef HAVE_XTEST
 }
 
 #ifdef HAVE_XTEST
@@ -253,12 +273,12 @@ fake_event (TotemScrsaver *scr)
 {
        if (scr->priv->disabled)
        {
 {
        if (scr->priv->disabled)
        {
-               XLockDisplay (GDK_DISPLAY());
-               XTestFakeKeyEvent (GDK_DISPLAY(), *scr->priv->keycode,
+               XLockDisplay (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
+               XTestFakeKeyEvent (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), *scr->priv->keycode,
                                True, CurrentTime);
                                True, CurrentTime);
-               XTestFakeKeyEvent (GDK_DISPLAY(), *scr->priv->keycode,
+               XTestFakeKeyEvent (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), *scr->priv->keycode,
                                False, CurrentTime);
                                False, CurrentTime);
-               XUnlockDisplay (GDK_DISPLAY());
+               XUnlockDisplay (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
                /* Swap the keycode */
                if (scr->priv->keycode == &scr->priv->keycode1)
                        scr->priv->keycode = &scr->priv->keycode2;
                /* Swap the keycode */
                if (scr->priv->keycode == &scr->priv->keycode1)
                        scr->priv->keycode = &scr->priv->keycode2;
@@ -277,12 +297,12 @@ screensaver_disable_x11 (TotemScrsaver *scr)
 #ifdef HAVE_XTEST
        if (scr->priv->have_xtest != FALSE)
        {
 #ifdef HAVE_XTEST
        if (scr->priv->have_xtest != FALSE)
        {
-               XLockDisplay (GDK_DISPLAY());
-               XGetScreenSaver(GDK_DISPLAY(), &scr->priv->timeout,
+               XLockDisplay (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
+               XGetScreenSaver(GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &scr->priv->timeout,
                                &scr->priv->interval,
                                &scr->priv->prefer_blanking,
                                &scr->priv->allow_exposures);
                                &scr->priv->interval,
                                &scr->priv->prefer_blanking,
                                &scr->priv->allow_exposures);
-               XUnlockDisplay (GDK_DISPLAY());
+               XUnlockDisplay (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
 
                if (scr->priv->timeout != 0) {
                        g_timeout_add_seconds (scr->priv->timeout / 2,
 
                if (scr->priv->timeout != 0) {
                        g_timeout_add_seconds (scr->priv->timeout / 2,
@@ -296,14 +316,14 @@ screensaver_disable_x11 (TotemScrsaver *scr)
        }
 #endif /* HAVE_XTEST */
 
        }
 #endif /* HAVE_XTEST */
 
-       XLockDisplay (GDK_DISPLAY());
-       XGetScreenSaver(GDK_DISPLAY(), &scr->priv->timeout,
+       XLockDisplay (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
+       XGetScreenSaver(GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &scr->priv->timeout,
                        &scr->priv->interval,
                        &scr->priv->prefer_blanking,
                        &scr->priv->allow_exposures);
                        &scr->priv->interval,
                        &scr->priv->prefer_blanking,
                        &scr->priv->allow_exposures);
-       XSetScreenSaver(GDK_DISPLAY(), 0, 0,
+       XSetScreenSaver(GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), 0, 0,
                        DontPreferBlanking, DontAllowExposures);
                        DontPreferBlanking, DontAllowExposures);
-       XUnlockDisplay (GDK_DISPLAY());
+       XUnlockDisplay (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
 }
 
 static void
 }
 
 static void
@@ -312,24 +332,24 @@ screensaver_init_x11 (TotemScrsaver *scr)
 #ifdef HAVE_XTEST
        int a, b, c, d;
 
 #ifdef HAVE_XTEST
        int a, b, c, d;
 
-       XLockDisplay (GDK_DISPLAY());
-       scr->priv->have_xtest = (XTestQueryExtension (GDK_DISPLAY(), &a, &b, &c, &d) == True);
+       XLockDisplay (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
+       scr->priv->have_xtest = (XTestQueryExtension (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &a, &b, &c, &d) == True);
        if (scr->priv->have_xtest != FALSE)
        {
        if (scr->priv->have_xtest != FALSE)
        {
-               scr->priv->keycode1 = XKeysymToKeycode (GDK_DISPLAY(), XK_Alt_L);
+               scr->priv->keycode1 = XKeysymToKeycode (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XK_Alt_L);
                if (scr->priv->keycode1 == 0) {
                        g_warning ("scr->priv->keycode1 not existant");
                }
                if (scr->priv->keycode1 == 0) {
                        g_warning ("scr->priv->keycode1 not existant");
                }
-               scr->priv->keycode2 = XKeysymToKeycode (GDK_DISPLAY(), XK_Alt_R);
+               scr->priv->keycode2 = XKeysymToKeycode (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XK_Alt_R);
                if (scr->priv->keycode2 == 0) {
                if (scr->priv->keycode2 == 0) {
-                       scr->priv->keycode2 = XKeysymToKeycode (GDK_DISPLAY(), XK_Alt_L);
+                       scr->priv->keycode2 = XKeysymToKeycode (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XK_Alt_L);
                        if (scr->priv->keycode2 == 0) {
                                g_warning ("scr->priv->keycode2 not existant");
                        }
                }
                scr->priv->keycode = &scr->priv->keycode1;
        }
                        if (scr->priv->keycode2 == 0) {
                                g_warning ("scr->priv->keycode2 not existant");
                        }
                }
                scr->priv->keycode = &scr->priv->keycode1;
        }
-       XUnlockDisplay (GDK_DISPLAY());
+       XUnlockDisplay (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
 #endif /* HAVE_XTEST */
 }
 
 #endif /* HAVE_XTEST */
 }
 
@@ -340,6 +360,55 @@ screensaver_finalize_x11 (TotemScrsaver *scr)
 }
 #endif
 
 }
 #endif
 
+static void
+totem_scrsaver_get_property (GObject *object,
+                            guint property_id,
+                            GValue *value,
+                            GParamSpec *pspec)
+{
+       TotemScrsaver *scr;
+
+       scr = TOTEM_SCRSAVER (object);
+
+       switch (property_id)
+       {
+       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);
+       }
+}
+
+static void
+totem_scrsaver_set_property (GObject *object,
+                            guint property_id,
+                            const GValue *value,
+                            GParamSpec *pspec)
+{
+       TotemScrsaver *scr;
+
+       scr = TOTEM_SCRSAVER (object);
+
+       switch (property_id)
+       {
+       case PROP_REASON:
+               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);
+       }
+}
+
 static void
 totem_scrsaver_class_init (TotemScrsaverClass *klass)
 {
 static void
 totem_scrsaver_class_init (TotemScrsaverClass *klass)
 {
@@ -347,7 +416,16 @@ totem_scrsaver_class_init (TotemScrsaverClass *klass)
 
        g_type_class_add_private (klass, sizeof (TotemScrsaverPrivate));
 
 
        g_type_class_add_private (klass, sizeof (TotemScrsaverPrivate));
 
+       object_class->set_property = totem_scrsaver_set_property;
+       object_class->get_property = totem_scrsaver_get_property;
        object_class->finalize = totem_scrsaver_finalize;
        object_class->finalize = totem_scrsaver_finalize;
+
+       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));
 }
 
 /**
 }
 
 /**
@@ -384,7 +462,7 @@ totem_scrsaver_init (TotemScrsaver *scr)
 void
 totem_scrsaver_disable (TotemScrsaver *scr)
 {
 void
 totem_scrsaver_disable (TotemScrsaver *scr)
 {
-       g_return_if_fail (TOTEM_SCRSAVER (scr));
+       g_return_if_fail (TOTEM_IS_SCRSAVER (scr));
 
        if (scr->priv->disabled != FALSE)
                return;
 
        if (scr->priv->disabled != FALSE)
                return;
@@ -393,7 +471,7 @@ totem_scrsaver_disable (TotemScrsaver *scr)
 
        if (screensaver_is_running_dbus (scr) != FALSE)
                screensaver_disable_dbus (scr);
 
        if (screensaver_is_running_dbus (scr) != FALSE)
                screensaver_disable_dbus (scr);
-       else 
+       else
 #ifdef GDK_WINDOWING_X11
                screensaver_disable_x11 (scr);
 #else
 #ifdef GDK_WINDOWING_X11
                screensaver_disable_x11 (scr);
 #else
@@ -405,7 +483,7 @@ totem_scrsaver_disable (TotemScrsaver *scr)
 void
 totem_scrsaver_enable (TotemScrsaver *scr)
 {
 void
 totem_scrsaver_enable (TotemScrsaver *scr)
 {
-       g_return_if_fail (TOTEM_SCRSAVER (scr));
+       g_return_if_fail (TOTEM_IS_SCRSAVER (scr));
 
        if (scr->priv->disabled == FALSE)
                return;
 
        if (scr->priv->disabled == FALSE)
                return;
@@ -414,7 +492,7 @@ totem_scrsaver_enable (TotemScrsaver *scr)
 
        if (screensaver_is_running_dbus (scr) != FALSE)
                screensaver_enable_dbus (scr);
 
        if (screensaver_is_running_dbus (scr) != FALSE)
                screensaver_enable_dbus (scr);
-       else 
+       else
 #ifdef GDK_WINDOWING_X11
                screensaver_enable_x11 (scr);
 #else
 #ifdef GDK_WINDOWING_X11
                screensaver_enable_x11 (scr);
 #else
@@ -426,7 +504,7 @@ totem_scrsaver_enable (TotemScrsaver *scr)
 void
 totem_scrsaver_set_state (TotemScrsaver *scr, gboolean enable)
 {
 void
 totem_scrsaver_set_state (TotemScrsaver *scr, gboolean enable)
 {
-       g_return_if_fail (TOTEM_SCRSAVER (scr));
+       g_return_if_fail (TOTEM_IS_SCRSAVER (scr));
 
        if (scr->priv->disabled == !enable)
                return;
 
        if (scr->priv->disabled == !enable)
                return;
@@ -442,6 +520,10 @@ totem_scrsaver_finalize (GObject *object)
 {
        TotemScrsaver *scr = TOTEM_SCRSAVER (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
        screensaver_finalize_x11 (scr);
        screensaver_finalize_dbus (scr);
 #ifdef GDK_WINDOWING_X11
        screensaver_finalize_x11 (scr);