Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog18
-rw-r--r--configure.ac1
-rw-r--r--cut-n-paste/Makefile.am2
-rw-r--r--cut-n-paste/totem-screensaver/.cvsignore2
-rw-r--r--cut-n-paste/totem-screensaver/Makefile.am11
-rw-r--r--cut-n-paste/totem-screensaver/README3
-rw-r--r--cut-n-paste/totem-screensaver/totem-scrsaver.c416
-rw-r--r--cut-n-paste/totem-screensaver/totem-scrsaver.h49
-rw-r--r--shell/Makefile.am3
-rw-r--r--shell/ev-window.c19
10 files changed, 520 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index b549342..db91570 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2006-11-22 Wouter Bolsterlee <wbolster@cvs.gnome.org>
+
+ * configure.ac:
+ * cut-n-paste/Makefile.am:
+ * cut-n-paste/totem-screensaver/.cvsignore
+ * cut-n-paste/totem-screensaver/Makefile.am:
+ * cut-n-paste/totem-screensaver/README:
+ * cut-n-paste/totem-screensaver/totem-scrsaver.c:
+ * cut-n-paste/totem-screensaver/totem-scrsaver.h:
+ * shell/Makefile.am:
+ * shell/ev-window.c: (ev_window_run_presentation),
+ (ev_window_stop_presentation), (ev_window_cmd_help_about),
+ (ev_window_init):
+
+ Implemented screensaver enabling/disabling for
+ presentation mode (not fullscreen mode). Code stolen
+ from Totem (with some minor tweaks). Fixes bug #338889.
+
2006-11-19 Wouter Bolsterlee <wbolster@cvs.gnome.org>
* configure.ac:
diff --git a/configure.ac b/configure.ac
index 1f5abc7..2b2b722 100644
--- a/configure.ac
+++ b/configure.ac
@@ -374,6 +374,7 @@ cut-n-paste/Makefile
cut-n-paste/recent-files/Makefile
cut-n-paste/toolbar-editor/Makefile
cut-n-paste/zoom-control/Makefile
+cut-n-paste/totem-screensaver/Makefile
data/evince.desktop.in
data/icons/16x16/Makefile
data/icons/22x22/Makefile
diff --git a/cut-n-paste/Makefile.am b/cut-n-paste/Makefile.am
index 33218c0..d70ab46 100644
--- a/cut-n-paste/Makefile.am
+++ b/cut-n-paste/Makefile.am
@@ -6,4 +6,4 @@ else
SUBDIRS += recent-files
endif
-SUBDIRS += zoom-control toolbar-editor
+SUBDIRS += zoom-control toolbar-editor totem-screensaver
diff --git a/cut-n-paste/totem-screensaver/.cvsignore b/cut-n-paste/totem-screensaver/.cvsignore
new file mode 100644
index 0000000..282522d
--- /dev/null
+++ b/cut-n-paste/totem-screensaver/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/cut-n-paste/totem-screensaver/Makefile.am b/cut-n-paste/totem-screensaver/Makefile.am
new file mode 100644
index 0000000..9108b91
--- /dev/null
+++ b/cut-n-paste/totem-screensaver/Makefile.am
@@ -0,0 +1,11 @@
+noinst_LTLIBRARIES = libtotemscrsaver.la
+libtotemscrsaver_la_SOURCES = \
+ totem-scrsaver.h \
+ totem-scrsaver.c
+
+libtotemscrsaver_la_CFLAGS = \
+ -I$(top_srcdir)/lib \
+ $(LIB_CFLAGS) \
+ $(DBUS_CFLAGS) \
+ $(WARNING_CFLAGS) \
+ $(DISABLE_DEPRECATED)
diff --git a/cut-n-paste/totem-screensaver/README b/cut-n-paste/totem-screensaver/README
new file mode 100644
index 0000000..a5be11b
--- /dev/null
+++ b/cut-n-paste/totem-screensaver/README
@@ -0,0 +1,3 @@
+The sources for the screensaver enabling/disabling code are copied from Totem.
+A simple replacement (s/WITH_DBUS/ENABLE_DBUS/g) was needed. The hardcoded
+"reason for inhibiting" string was also modified.
diff --git a/cut-n-paste/totem-screensaver/totem-scrsaver.c b/cut-n-paste/totem-screensaver/totem-scrsaver.c
new file mode 100644
index 0000000..5d5a1f2
--- /dev/null
+++ b/cut-n-paste/totem-screensaver/totem-scrsaver.c
@@ -0,0 +1,416 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+
+ Copyright (C) 2004-2006 Bastien Nocera <hadess@hadess.net>
+
+ 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
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Bastien Nocera <hadess@hadess.net>
+ */
+
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+#include <gdk/gdkx.h>
+
+#ifdef HAVE_XTEST
+#include <X11/extensions/XTest.h>
+#endif /* HAVE_XTEST */
+#include <X11/keysym.h>
+
+#ifdef ENABLE_DBUS
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
+
+#define GS_SERVICE "org.gnome.ScreenSaver"
+#define GS_PATH "/org/gnome/ScreenSaver"
+#define GS_INTERFACE "org.gnome.ScreenSaver"
+#endif /* ENABLE_DBUS */
+
+#include "totem-scrsaver.h"
+
+#define XSCREENSAVER_MIN_TIMEOUT 60
+
+static GObjectClass *parent_class = NULL;
+static void totem_scrsaver_class_init (TotemScrsaverClass *class);
+static void totem_scrsaver_init (TotemScrsaver *parser);
+static void totem_scrsaver_finalize (GObject *object);
+
+
+struct TotemScrsaverPrivate {
+ /* Whether the screensaver is disabled */
+ gboolean disabled;
+
+#ifdef ENABLE_DBUS
+ DBusGConnection *connection;
+ DBusGProxy *gs_proxy;
+ guint32 cookie;
+#endif /* ENABLE_DBUS */
+
+ /* To save the screensaver info */
+ int timeout;
+ int interval;
+ int prefer_blanking;
+ int allow_exposures;
+
+ /* For use with XTest */
+ int keycode1, keycode2;
+ int *keycode;
+ Bool have_xtest;
+};
+
+G_DEFINE_TYPE(TotemScrsaver, totem_scrsaver, G_TYPE_OBJECT)
+
+static gboolean
+screensaver_is_running_dbus (TotemScrsaver *scr)
+{
+#ifdef ENABLE_DBUS
+ if (! scr->priv->connection)
+ return FALSE;
+
+ if (! scr->priv->gs_proxy)
+ return FALSE;
+
+ return TRUE;
+#else
+ return FALSE;
+#endif /* ENABLE_DBUS */
+}
+
+static void
+screensaver_inhibit_dbus (TotemScrsaver *scr,
+ gboolean inhibit)
+{
+#ifdef ENABLE_DBUS
+ GError *error;
+ gboolean res;
+
+ g_return_if_fail (scr != NULL);
+ g_return_if_fail (scr->priv->connection != NULL);
+ g_return_if_fail (scr->priv->gs_proxy != NULL);
+
+ error = NULL;
+ if (inhibit) {
+ char *application;
+ char *reason;
+ guint32 cookie;
+
+ application = g_strdup ("Evince");
+ reason = g_strdup (_("Running in presentation mode"));
+
+ res = dbus_g_proxy_call (scr->priv->gs_proxy,
+ "Inhibit",
+ &error,
+ G_TYPE_STRING, application,
+ G_TYPE_STRING, reason,
+ G_TYPE_INVALID,
+ G_TYPE_UINT, &cookie,
+ G_TYPE_INVALID);
+
+ if (res) {
+ /* save the cookie */
+ scr->priv->cookie = cookie;
+ } else {
+ /* try the old API */
+ res = dbus_g_proxy_call (scr->priv->gs_proxy,
+ "InhibitActivation",
+ &error,
+ G_TYPE_STRING, reason,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ }
+
+ g_free (reason);
+ g_free (application);
+
+ } else {
+ res = dbus_g_proxy_call (scr->priv->gs_proxy,
+ "UnInhibit",
+ &error,
+ G_TYPE_UINT, scr->priv->cookie,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ if (res) {
+ /* clear the cookie */
+ scr->priv->cookie = 0;
+ } else {
+ /* try the old API */
+ res = dbus_g_proxy_call (scr->priv->gs_proxy,
+ "AllowActivation",
+ &error,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ }
+ }
+
+ if (! res) {
+ if (error) {
+ g_warning ("Problem inhibiting the screensaver: %s", error->message);
+ g_error_free (error);
+ }
+ }
+#endif /* ENABLE_DBUS */
+}
+
+static void
+screensaver_enable_dbus (TotemScrsaver *scr)
+{
+ screensaver_inhibit_dbus (scr, FALSE);
+}
+
+static void
+screensaver_disable_dbus (TotemScrsaver *scr)
+{
+ screensaver_inhibit_dbus (scr, TRUE);
+}
+
+#ifdef ENABLE_DBUS
+static void
+gs_proxy_destroy_cb (GObject *proxy,
+ TotemScrsaver *scr)
+{
+ g_warning ("Detected that GNOME screensaver has left the bus");
+
+ /* just invalidate for now */
+ scr->priv->gs_proxy = NULL;
+}
+#endif
+
+static void
+screensaver_init_dbus (TotemScrsaver *scr)
+{
+#ifdef ENABLE_DBUS
+ GError *error = NULL;
+
+ scr->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+
+ if (! scr->priv->connection) {
+ if (error) {
+ g_warning ("Failed to connect to the session bus: %s", error->message);
+ g_error_free (error);
+ }
+ return;
+ }
+
+ scr->priv->gs_proxy = dbus_g_proxy_new_for_name_owner (scr->priv->connection,
+ GS_SERVICE,
+ GS_PATH,
+ GS_INTERFACE,
+ NULL);
+ if (scr->priv->gs_proxy != NULL) {
+ g_signal_connect_object (scr->priv->gs_proxy,
+ "destroy",
+ G_CALLBACK (gs_proxy_destroy_cb),
+ scr,
+ 0);
+
+ }
+
+#endif /* ENABLE_DBUS */
+}
+
+static void
+screensaver_finalize_dbus (TotemScrsaver *scr)
+{
+#ifdef ENABLE_DBUS
+ if (scr->priv->gs_proxy) {
+ g_object_unref (scr->priv->gs_proxy);
+ }
+#endif /* ENABLE_DBUS */
+}
+
+static void
+screensaver_enable_x11 (TotemScrsaver *scr)
+{
+
+#ifdef HAVE_XTEST
+ if (scr->priv->have_xtest == True)
+ {
+ g_source_remove_by_user_data (scr);
+ return;
+ }
+#endif /* HAVE_XTEST */
+
+ XLockDisplay (GDK_DISPLAY());
+ XSetScreenSaver (GDK_DISPLAY(),
+ scr->priv->timeout,
+ scr->priv->interval,
+ scr->priv->prefer_blanking,
+ scr->priv->allow_exposures);
+ XUnlockDisplay (GDK_DISPLAY());
+}
+
+#ifdef HAVE_XTEST
+static gboolean
+fake_event (TotemScrsaver *scr)
+{
+ if (scr->priv->disabled)
+ {
+ XLockDisplay (GDK_DISPLAY());
+ XTestFakeKeyEvent (GDK_DISPLAY(), *scr->priv->keycode,
+ True, CurrentTime);
+ XTestFakeKeyEvent (GDK_DISPLAY(), *scr->priv->keycode,
+ False, CurrentTime);
+ XUnlockDisplay (GDK_DISPLAY());
+ /* Swap the keycode */
+ if (scr->priv->keycode == &scr->priv->keycode1)
+ scr->priv->keycode = &scr->priv->keycode2;
+ else
+ scr->priv->keycode = &scr->priv->keycode1;
+ }
+
+ return TRUE;
+}
+#endif /* HAVE_XTEST */
+
+static void
+screensaver_disable_x11 (TotemScrsaver *scr)
+{
+
+#ifdef HAVE_XTEST
+ if (scr->priv->have_xtest == True)
+ {
+ XLockDisplay (GDK_DISPLAY());
+ XGetScreenSaver(GDK_DISPLAY(), &scr->priv->timeout,
+ &scr->priv->interval,
+ &scr->priv->prefer_blanking,
+ &scr->priv->allow_exposures);
+ XUnlockDisplay (GDK_DISPLAY());
+
+ if (scr->priv->timeout != 0)
+ {
+ g_timeout_add (scr->priv->timeout / 2 * 1000,
+ (GSourceFunc) fake_event, scr);
+ } else {
+ g_timeout_add (XSCREENSAVER_MIN_TIMEOUT / 2 * 1000,
+ (GSourceFunc) fake_event, scr);
+ }
+
+ return;
+ }
+#endif /* HAVE_XTEST */
+
+ XLockDisplay (GDK_DISPLAY());
+ XGetScreenSaver(GDK_DISPLAY(), &scr->priv->timeout,
+ &scr->priv->interval,
+ &scr->priv->prefer_blanking,
+ &scr->priv->allow_exposures);
+ XSetScreenSaver(GDK_DISPLAY(), 0, 0,
+ DontPreferBlanking, DontAllowExposures);
+ XUnlockDisplay (GDK_DISPLAY());
+}
+
+static void
+screensaver_init_x11 (TotemScrsaver *scr)
+{
+#ifdef HAVE_XTEST
+ int a, b, c, d;
+
+ XLockDisplay (GDK_DISPLAY());
+ scr->priv->have_xtest = XTestQueryExtension (GDK_DISPLAY(), &a, &b, &c, &d);
+ if(scr->priv->have_xtest == True)
+ {
+ scr->priv->keycode1 = XKeysymToKeycode (GDK_DISPLAY(), XK_Alt_L);
+ if (scr->priv->keycode1 == 0) {
+ g_warning ("scr->priv->keycode1 not existant");
+ }
+ scr->priv->keycode2 = XKeysymToKeycode (GDK_DISPLAY(), XK_Alt_R);
+ if (scr->priv->keycode2 == 0) {
+ scr->priv->keycode2 = XKeysymToKeycode (GDK_DISPLAY(), XK_Alt_L);
+ if (scr->priv->keycode2 == 0) {
+ g_warning ("scr->priv->keycode2 not existant");
+ }
+ }
+ scr->priv->keycode = &scr->priv->keycode1;
+ }
+ XUnlockDisplay (GDK_DISPLAY());
+#endif /* HAVE_XTEST */
+}
+
+static void
+screensaver_finalize_x11 (TotemScrsaver *scr)
+{
+ g_source_remove_by_user_data (scr);
+}
+
+static void
+totem_scrsaver_class_init (TotemScrsaverClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ object_class->finalize = totem_scrsaver_finalize;
+}
+
+TotemScrsaver *
+totem_scrsaver_new (void)
+{
+ return TOTEM_SCRSAVER (g_object_new (TOTEM_TYPE_SCRSAVER, NULL));
+}
+
+static void
+totem_scrsaver_init (TotemScrsaver *scr)
+{
+ scr->priv = g_new0 (TotemScrsaverPrivate, 1);
+
+ screensaver_init_dbus (scr);
+ screensaver_init_x11 (scr);
+}
+
+void
+totem_scrsaver_disable (TotemScrsaver *scr)
+{
+ if (scr->priv->disabled != FALSE)
+ return;
+
+ scr->priv->disabled = TRUE;
+
+ if (screensaver_is_running_dbus (scr) != FALSE)
+ screensaver_disable_dbus (scr);
+ else
+ screensaver_disable_x11 (scr);
+}
+
+void
+totem_scrsaver_enable (TotemScrsaver *scr)
+{
+ if (scr->priv->disabled == FALSE)
+ return;
+
+ scr->priv->disabled = FALSE;
+
+ if (screensaver_is_running_dbus (scr) != FALSE)
+ screensaver_enable_dbus (scr);
+ else
+ screensaver_enable_x11 (scr);
+}
+
+static void
+totem_scrsaver_finalize (GObject *object)
+{
+ TotemScrsaver *scr = TOTEM_SCRSAVER (object);
+
+ screensaver_finalize_dbus (scr);
+ screensaver_finalize_x11 (scr);
+
+ g_free (scr->priv);
+
+ if (G_OBJECT_CLASS (parent_class)->finalize != NULL) {
+ (* G_OBJECT_CLASS (parent_class)->finalize) (object);
+ }
+}
+
diff --git a/cut-n-paste/totem-screensaver/totem-scrsaver.h b/cut-n-paste/totem-screensaver/totem-scrsaver.h
new file mode 100644
index 0000000..f34fb15
--- /dev/null
+++ b/cut-n-paste/totem-screensaver/totem-scrsaver.h
@@ -0,0 +1,49 @@
+/*
+ Copyright (C) 2004, Bastien Nocera <hadess@hadess.net>
+
+ 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
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Bastien Nocera <hadess@hadess.net>
+ */
+
+#include <glib.h>
+#include <glib-object.h>
+
+#define TOTEM_TYPE_SCRSAVER (totem_scrsaver_get_type ())
+#define TOTEM_SCRSAVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TOTEM_TYPE_SCRSAVER, TotemScrsaver))
+#define TOTEM_SCRSAVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TOTEM_TYPE_SCRSAVER, TotemScrsaverClass))
+#define TOTEM_IS_SCRSAVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TOTEM_TYPE_SCRSAVER))
+#define TOTEM_IS_SCRSAVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TOTEM_TYPE_SCRSAVER))
+
+
+typedef struct TotemScrsaver TotemScrsaver;
+typedef struct TotemScrsaverClass TotemScrsaverClass;
+typedef struct TotemScrsaverPrivate TotemScrsaverPrivate;
+
+struct TotemScrsaver {
+ GObject parent;
+ TotemScrsaverPrivate *priv;
+};
+
+struct TotemScrsaverClass {
+ GObjectClass parent_class;
+};
+
+GType totem_scrsaver_get_type (void);
+TotemScrsaver *totem_scrsaver_new (void);
+void totem_scrsaver_enable (TotemScrsaver *scr);
+void totem_scrsaver_disable (TotemScrsaver *scr);
+
diff --git a/shell/Makefile.am b/shell/Makefile.am
index 30dde9e..3033504 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -4,6 +4,7 @@ INCLUDES= \
-I$(top_srcdir)/lib \
-I$(top_srcdir)/cut-n-paste/zoom-control/ \
-I$(top_srcdir)/cut-n-paste/toolbar-editor/ \
+ -I$(top_srcdir)/cut-n-paste/totem-screensaver/ \
-I$(top_srcdir)/backend \
-I$(top_srcdir)/properties \
-DGNOMELOCALEDIR=\"$(datadir)/locale\" \
@@ -82,6 +83,7 @@ evince_SOURCES= \
ev-stock-icons.h \
main.c
+
if WITH_GNOME_PRINT
evince_SOURCES+= \
ev-print-job.c \
@@ -92,6 +94,7 @@ endif
evince_LDADD= \
$(top_builddir)/cut-n-paste/zoom-control/libephyzoom.la \
$(top_builddir)/cut-n-paste/toolbar-editor/libtoolbareditor.la \
+ $(top_builddir)/cut-n-paste/totem-screensaver/libtotemscrsaver.la \
$(top_builddir)/properties/libevproperties.la \
$(top_builddir)/lib/libev.la \
$(SHELL_LIBS) \
diff --git a/shell/ev-window.c b/shell/ev-window.c
index c7d39cd..7442654 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -89,6 +89,8 @@
#include <libgnomevfs/gnome-vfs-utils.h>
#include <gconf/gconf-client.h>
+#include "totem-scrsaver.h"
+
#include <string.h>
typedef enum {
@@ -148,7 +150,10 @@ struct _EvWindowPrivate {
GtkWidget *fullscreen_toolbar;
GtkWidget *fullscreen_popup;
guint fullscreen_timeout_id;
-
+
+ /* Screensaver */
+ TotemScrsaver *screensaver;
+
/* Popup link */
GtkWidget *view_popup;
EvLink *link;
@@ -2535,6 +2540,8 @@ ev_window_run_presentation (EvWindow *window)
window);
fullscreen_set_timeout (window);
+ totem_scrsaver_disable (window->priv->screensaver);
+
if (!ev_window_is_empty (window))
ev_metadata_manager_set_boolean (window->priv->uri, "presentation", TRUE);
}
@@ -2561,6 +2568,8 @@ ev_window_stop_presentation (EvWindow *window)
window);
fullscreen_clear_timeout (window);
+ totem_scrsaver_enable (window->priv->screensaver);
+
if (!ev_window_is_empty (window))
ev_metadata_manager_set_boolean (window->priv->uri, "presentation", FALSE);
}
@@ -3157,7 +3166,7 @@ ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
"name", _("Evince"),
"version", VERSION,
"copyright",
- _("\xc2\xa9 1996-2005 The Evince authors"),
+ _("\xc2\xa9 1996-2007 The Evince authors"),
"license", license_trans,
"website", "http://www.gnome.org/projects/evince",
"comments", comments,
@@ -4621,7 +4630,11 @@ ev_window_init (EvWindow *ev_window)
g_signal_connect_swapped (G_OBJECT (ev_window->priv->view), "drag-data-received",
G_CALLBACK (drag_data_received_cb),
ev_window);
-
+
+ /* Screensaver */
+
+ ev_window->priv->screensaver = totem_scrsaver_new ();
+
/* Set it user interface params */
ev_window_setup_recent (ev_window);