changeset 3030:f13ad181f5b2

This is so wrong, it hurts. Instead of the GNOME screensaver respecting the MIT-SCREEN-SAVER extension and registering for the screensaver idle event, it uses a completely different control mechanism. Our alternatives are to use dbus (very complicated) or this really painful hack.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 12 Jan 2009 08:26:24 +0000
parents 89f8a72e1ee9
children 86918831452f
files src/video/x11/SDL_x11events.c
diffstat 1 files changed, 44 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/x11/SDL_x11events.c	Mon Jan 12 08:23:47 2009 +0000
+++ b/src/video/x11/SDL_x11events.c	Mon Jan 12 08:26:24 2009 +0000
@@ -410,6 +410,33 @@
     }
 }
 
+/* This is so wrong it hurts */
+#define GNOME_SCREENSAVER_HACK
+#ifdef GNOME_SCREENSAVER_HACK
+#include <unistd.h>
+static pid_t screensaver_inhibit_pid;
+static void gnome_screensaver_disable()
+{
+    screensaver_inhibit_pid = fork();
+    if (screensaver_inhibit_pid == 0) {
+        //close(0);
+        //close(1);
+        //close(2);
+        execl("/usr/bin/gnome-screensaver-command",
+              "gnome-screensaver-command",
+              "--inhibit",
+              "--reason",
+              "GNOME screensaver doesn't respect MIT-SCREEN-SAVER",
+              NULL);
+        exit(2);
+    }
+}
+static void gnome_screensaver_enable()
+{
+    kill(screensaver_inhibit_pid, 15);
+}
+#endif
+
 void
 X11_SuspendScreenSaver(_THIS)
 {
@@ -418,20 +445,26 @@
     int dummy;
     int major_version, minor_version;
 
-    if (!SDL_X11_HAVE_XSS) {
-        return;
-    }
+    if (SDL_X11_HAVE_XSS) {
+        /* XScreenSaverSuspend was introduced in MIT-SCREEN-SAVER 1.1 */
+        if (!XScreenSaverQueryExtension(data->display, &dummy, &dummy) ||
+            !XScreenSaverQueryVersion(data->display,
+                                      &major_version, &minor_version) ||
+            major_version < 1 || (major_version == 1 && minor_version < 1)) {
+            return;
+        }
 
-    /* XScreenSaverSuspend was introduced in MIT-SCREEN-SAVER 1.1 */
-    if (!XScreenSaverQueryExtension(data->display, &dummy, &dummy) ||
-        !XScreenSaverQueryVersion(data->display,
-                                  &major_version, &minor_version) ||
-        major_version < 1 || (major_version == 1 && minor_version < 1)) {
-        return;
+        XScreenSaverSuspend(data->display, _this->suspend_screensaver);
+        XResetScreenSaver(data->display);
     }
+#endif
 
-    XScreenSaverSuspend(data->display, _this->suspend_screensaver);
-    XResetScreenSaver(data->display);
+#ifdef GNOME_SCREENSAVER_HACK
+    if (_this->suspend_screensaver) {
+        gnome_screensaver_disable();
+    } else {
+        gnome_screensaver_enable();
+    }
 #endif
 }