changeset 1783:c546353b1ad4

Fixed bug #203 Disable screensaver and DPMS blanking while SDL app is running.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 08 May 2006 06:38:13 +0000
parents 23fe15f88c03
children 45669d4efd02
files configure.in include/SDL_config.h.in src/video/x11/SDL_x11events.c src/video/x11/SDL_x11events_c.h src/video/x11/SDL_x11sym.h src/video/x11/SDL_x11video.c src/video/x11/SDL_x11video.h
diffstat 7 files changed, 99 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/configure.in	Mon May 08 06:23:11 2006 +0000
+++ b/configure.in	Mon May 08 06:38:13 2006 +0000
@@ -927,10 +927,22 @@
                     fi
                 fi
             fi
-
             if test x$definitely_enable_video_x11_xrandr = xyes; then
                 AC_DEFINE(SDL_VIDEO_DRIVER_X11_XRANDR)
             fi
+            AC_ARG_ENABLE(video-x11-dpms,
+AC_HELP_STRING([--enable-video-x11-dpms], [enable X11 DPMS extension [[default=yes]]]),
+                            , enable_video_x11_dpms=yes)
+            if test x$enable_video_x11_dpms = xyes; then
+                AC_CHECK_HEADER(X11/extensions/dpms.h,
+                                have_dpms_h_hdr=yes,
+                                have_dpms_h_hdr=no,
+                                [#include <X11/Xlib.h>
+                                ])
+                if test x$have_dpms_h_hdr = xyes; then
+                    AC_DEFINE(SDL_VIDEO_DRIVER_X11_DPMS)
+                fi
+            fi
         fi
     fi
 }
--- a/include/SDL_config.h.in	Mon May 08 06:23:11 2006 +0000
+++ b/include/SDL_config.h.in	Mon May 08 06:38:13 2006 +0000
@@ -278,6 +278,7 @@
 #undef SDL_VIDEO_DRIVER_WSCONS
 #undef SDL_VIDEO_DRIVER_X11
 #undef SDL_VIDEO_DRIVER_X11_DGAMOUSE
+#undef SDL_VIDEO_DRIVER_X11_DPMS
 #undef SDL_VIDEO_DRIVER_X11_DYNAMIC
 #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
 #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
--- a/src/video/x11/SDL_x11events.c	Mon May 08 06:23:11 2006 +0000
+++ b/src/video/x11/SDL_x11events.c	Mon May 08 06:38:13 2006 +0000
@@ -1118,3 +1118,55 @@
 	X11_InitKeymap();
 }
 
+void X11_SaveScreenSaver(_THIS)
+{
+	int timeout, interval, prefer_blank, allow_exp;
+	XGetScreenSaver(SDL_Display, &timeout, &interval, &prefer_blank, &allow_exp);
+	screensaver_timeout = timeout;
+
+#if SDL_VIDEO_DRIVER_X11_DPMS
+	if ( SDL_X11_HAVE_DPMS ) {
+		int dummy;
+	  	if ( DPMSQueryExtension(SDL_Display, &dummy, &dummy) ) {
+			CARD16 state;
+			DPMSInfo(SDL_Display, &state, &dpms_enabled);
+		}
+	}
+#endif /* SDL_VIDEO_DRIVER_X11_DPMS */
+}
+
+void X11_DisableScreenSaver(_THIS)
+{
+	int timeout, interval, prefer_blank, allow_exp;
+	XGetScreenSaver(SDL_Display, &timeout, &interval, &prefer_blank, &allow_exp);
+	timeout = 0;
+	XSetScreenSaver(SDL_Display, timeout, interval, prefer_blank, allow_exp);
+
+#if SDL_VIDEO_DRIVER_X11_DPMS
+	if ( SDL_X11_HAVE_DPMS ) {
+		int dummy;
+	  	if ( DPMSQueryExtension(SDL_Display, &dummy, &dummy) ) {
+			DPMSDisable(SDL_Display);
+		}
+	}
+#endif /* SDL_VIDEO_DRIVER_X11_DPMS */
+}
+
+void X11_RestoreScreenSaver(_THIS)
+{
+	int timeout, interval, prefer_blank, allow_exp;
+	XGetScreenSaver(SDL_Display, &timeout, &interval, &prefer_blank, &allow_exp);
+	timeout = screensaver_timeout;
+	XSetScreenSaver(SDL_Display, timeout, interval, prefer_blank, allow_exp);
+
+#if SDL_VIDEO_DRIVER_X11_DPMS
+	if ( SDL_X11_HAVE_DPMS ) {
+		int dummy;
+	  	if ( DPMSQueryExtension(SDL_Display, &dummy, &dummy) ) {
+			if ( dpms_enabled ) {
+				DPMSEnable(SDL_Display);
+			}
+		}
+	}
+#endif /* SDL_VIDEO_DRIVER_X11_DPMS */
+}
--- a/src/video/x11/SDL_x11events_c.h	Mon May 08 06:23:11 2006 +0000
+++ b/src/video/x11/SDL_x11events_c.h	Mon May 08 06:38:13 2006 +0000
@@ -28,3 +28,6 @@
 extern void X11_PumpEvents(_THIS);
 extern void X11_SetKeyboardState(Display *display, const char *key_vec);
 
+extern void X11_SaveScreenSaver(_THIS);
+extern void X11_DisableScreenSaver(_THIS);
+extern void X11_RestoreScreenSaver(_THIS);
--- a/src/video/x11/SDL_x11sym.h	Mon May 08 06:23:11 2006 +0000
+++ b/src/video/x11/SDL_x11sym.h	Mon May 08 06:38:13 2006 +0000
@@ -56,9 +56,9 @@
 SDL_X11_SYM(int,XGetErrorDatabaseText,(Display* a,_Xconst char* b,_Xconst char* c,_Xconst char* d,char* e,int f),(a,b,c,d,e,f),return)
 SDL_X11_SYM(XModifierKeymap*,XGetModifierMapping,(Display* a),(a),return)
 SDL_X11_SYM(int,XGetPointerControl,(Display* a,int* b,int* c,int* d),(a,b,c,d),return)
+SDL_X11_SYM(int,XGetScreenSaver,(Display* a,int* b,int* c,int* d, int* e),(a,b,c,d,e),return)
 SDL_X11_SYM(XVisualInfo*,XGetVisualInfo,(Display* a,long b,XVisualInfo* c,int* d),(a,b,c,d),return)
 SDL_X11_SYM(XWMHints*,XGetWMHints,(Display* a,Window b),(a,b),return)
-SDL_X11_SYM(Status,XGetTextProperty,(Display* a,Window b,XTextProperty* c,Atom d),(a,b,c,d),return)
 SDL_X11_SYM(Status,XGetWindowAttributes,(Display* a,Window b,XWindowAttributes* c),(a,b,c),return)
 SDL_X11_SYM(int,XGrabKeyboard,(Display* a,Window b,Bool c,int d,int e,Time f),(a,b,c,d,e,f),return)
 SDL_X11_SYM(int,XGrabPointer,(Display* a,Window b,Bool c,unsigned int d,int e,int f,Window g,Cursor h,Time i),(a,b,c,d,e,f,g,h,i),return)
@@ -91,6 +91,7 @@
 SDL_X11_SYM(int,XSetClassHint,(Display* a,Window b,XClassHint* c),(a,b,c),return)
 SDL_X11_SYM(XErrorHandler,XSetErrorHandler,(XErrorHandler a),(a),return)
 SDL_X11_SYM(XIOErrorHandler,XSetIOErrorHandler,(XIOErrorHandler a),(a),return)
+SDL_X11_SYM(int,XSetScreenSaver,(Display* a,int b,int c,int d,int e),(a,b,c,d,e),return)
 SDL_X11_SYM(int,XSetTransientForHint,(Display* a,Window b,Window c),(a,b,c),return)
 SDL_X11_SYM(int,XSetWMHints,(Display* a,Window b,XWMHints* c),(a,b,c),return)
 SDL_X11_SYM(void,XSetTextProperty,(Display* a,Window b,XTextProperty* c,Atom d),(a,b,c,d),)
@@ -187,5 +188,14 @@
 SDL_X11_SYM(void,XRRFreeScreenConfigInfo,(XRRScreenConfiguration *config),(config),)
 #endif
 
+/* DPMS support */
+#if SDL_VIDEO_DRIVER_X11_DPMS
+SDL_X11_MODULE(DPMS)
+SDL_X11_SYM(Status,DPMSQueryExtension,(Display *dpy,int *major_versionp,int *minor_versionp),(dpy,major_versionp,minor_versionp),return)
+SDL_X11_SYM(Status,DPMSInfo,(Display *dpy,CARD16 *state,BOOL *onoff),(dpy,state,onoff),return)
+SDL_X11_SYM(Status,DPMSEnable,(Display *dpy),(dpy),return)
+SDL_X11_SYM(Status,DPMSDisable,(Display *dpy),(dpy),return)
+#endif
+
 /* end of SDL_x11sym.h ... */
 
--- a/src/video/x11/SDL_x11video.c	Mon May 08 06:23:11 2006 +0000
+++ b/src/video/x11/SDL_x11video.c	Mon May 08 06:38:13 2006 +0000
@@ -544,6 +544,10 @@
 	}
 	X11_SaveVidModeGamma(this);
 
+	/* Save DPMS and screensaver settings */
+	X11_SaveScreenSaver(this);
+	X11_DisableScreenSaver(this);
+
 	/* See if we have been passed a window to use */
 	SDL_windowid = SDL_getenv("SDL_WINDOWID");
 
@@ -1364,11 +1368,15 @@
 			SDL_free(SDL_iconcolors);
 			SDL_iconcolors = NULL;
 		} 
+
 		/* Restore gamma settings if they've changed */
 		if ( SDL_GetAppState() & SDL_APPACTIVE ) {
 			X11_SwapVidModeGamma(this);
 		}
 
+		/* Restore DPMS and screensaver settings */
+		X11_RestoreScreenSaver(this);
+
 		/* Free that blank cursor */
 		if ( SDL_BlankCursor != NULL ) {
 			this->FreeWMCursor(this, SDL_BlankCursor);
--- a/src/video/x11/SDL_x11video.h	Mon May 08 06:23:11 2006 +0000
+++ b/src/video/x11/SDL_x11video.h	Mon May 08 06:38:13 2006 +0000
@@ -46,6 +46,9 @@
 #if SDL_VIDEO_DRIVER_X11_XME
 #include "../Xext/extensions/xme.h"
 #endif
+#if SDL_VIDEO_DRIVER_X11_DPMS
+#include <X11/extensions/dpms.h>
+#endif
 
 #include "SDL_x11dyn.h"
 
@@ -151,6 +154,12 @@
     int gamma_changed;		/* flag: has VidMode gamma been modified? */
 
     short *iconcolors;		/* List of colors used by the icon */
+
+    /* Screensaver settings */
+    int screensaver_timeout;
+#if SDL_VIDEO_DRIVER_X11_DPMS
+    BOOL dpms_enabled;
+#endif
 };
 
 /* Old variable names */
@@ -201,6 +210,8 @@
 #define gamma_saved		(this->hidden->gamma_saved)
 #define gamma_changed		(this->hidden->gamma_changed)
 #define SDL_iconcolors		(this->hidden->iconcolors)
+#define screensaver_timeout	(this->hidden->screensaver_timeout)
+#define dpms_enabled		(this->hidden->dpms_enabled)
 /* Some versions of XFree86 have bugs - detect if this is one of them */
 #define BUGGY_XFREE86(condition, buggy_version) \
 ((SDL_strcmp(ServerVendor(SDL_Display), "The XFree86 Project, Inc") == 0) && \