Fixed bug #203
authorSam Lantinga <slouken@libsdl.org>
Mon, 08 May 2006 06:38:13 +0000
changeset 1783c546353b1ad4
parent 1782 23fe15f88c03
child 1784 45669d4efd02
Fixed bug #203

Disable screensaver and DPMS blanking while SDL app is running.
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
     1.1 --- a/configure.in	Mon May 08 06:23:11 2006 +0000
     1.2 +++ b/configure.in	Mon May 08 06:38:13 2006 +0000
     1.3 @@ -927,10 +927,22 @@
     1.4                      fi
     1.5                  fi
     1.6              fi
     1.7 -
     1.8              if test x$definitely_enable_video_x11_xrandr = xyes; then
     1.9                  AC_DEFINE(SDL_VIDEO_DRIVER_X11_XRANDR)
    1.10              fi
    1.11 +            AC_ARG_ENABLE(video-x11-dpms,
    1.12 +AC_HELP_STRING([--enable-video-x11-dpms], [enable X11 DPMS extension [[default=yes]]]),
    1.13 +                            , enable_video_x11_dpms=yes)
    1.14 +            if test x$enable_video_x11_dpms = xyes; then
    1.15 +                AC_CHECK_HEADER(X11/extensions/dpms.h,
    1.16 +                                have_dpms_h_hdr=yes,
    1.17 +                                have_dpms_h_hdr=no,
    1.18 +                                [#include <X11/Xlib.h>
    1.19 +                                ])
    1.20 +                if test x$have_dpms_h_hdr = xyes; then
    1.21 +                    AC_DEFINE(SDL_VIDEO_DRIVER_X11_DPMS)
    1.22 +                fi
    1.23 +            fi
    1.24          fi
    1.25      fi
    1.26  }
     2.1 --- a/include/SDL_config.h.in	Mon May 08 06:23:11 2006 +0000
     2.2 +++ b/include/SDL_config.h.in	Mon May 08 06:38:13 2006 +0000
     2.3 @@ -278,6 +278,7 @@
     2.4  #undef SDL_VIDEO_DRIVER_WSCONS
     2.5  #undef SDL_VIDEO_DRIVER_X11
     2.6  #undef SDL_VIDEO_DRIVER_X11_DGAMOUSE
     2.7 +#undef SDL_VIDEO_DRIVER_X11_DPMS
     2.8  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC
     2.9  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
    2.10  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
     3.1 --- a/src/video/x11/SDL_x11events.c	Mon May 08 06:23:11 2006 +0000
     3.2 +++ b/src/video/x11/SDL_x11events.c	Mon May 08 06:38:13 2006 +0000
     3.3 @@ -1118,3 +1118,55 @@
     3.4  	X11_InitKeymap();
     3.5  }
     3.6  
     3.7 +void X11_SaveScreenSaver(_THIS)
     3.8 +{
     3.9 +	int timeout, interval, prefer_blank, allow_exp;
    3.10 +	XGetScreenSaver(SDL_Display, &timeout, &interval, &prefer_blank, &allow_exp);
    3.11 +	screensaver_timeout = timeout;
    3.12 +
    3.13 +#if SDL_VIDEO_DRIVER_X11_DPMS
    3.14 +	if ( SDL_X11_HAVE_DPMS ) {
    3.15 +		int dummy;
    3.16 +	  	if ( DPMSQueryExtension(SDL_Display, &dummy, &dummy) ) {
    3.17 +			CARD16 state;
    3.18 +			DPMSInfo(SDL_Display, &state, &dpms_enabled);
    3.19 +		}
    3.20 +	}
    3.21 +#endif /* SDL_VIDEO_DRIVER_X11_DPMS */
    3.22 +}
    3.23 +
    3.24 +void X11_DisableScreenSaver(_THIS)
    3.25 +{
    3.26 +	int timeout, interval, prefer_blank, allow_exp;
    3.27 +	XGetScreenSaver(SDL_Display, &timeout, &interval, &prefer_blank, &allow_exp);
    3.28 +	timeout = 0;
    3.29 +	XSetScreenSaver(SDL_Display, timeout, interval, prefer_blank, allow_exp);
    3.30 +
    3.31 +#if SDL_VIDEO_DRIVER_X11_DPMS
    3.32 +	if ( SDL_X11_HAVE_DPMS ) {
    3.33 +		int dummy;
    3.34 +	  	if ( DPMSQueryExtension(SDL_Display, &dummy, &dummy) ) {
    3.35 +			DPMSDisable(SDL_Display);
    3.36 +		}
    3.37 +	}
    3.38 +#endif /* SDL_VIDEO_DRIVER_X11_DPMS */
    3.39 +}
    3.40 +
    3.41 +void X11_RestoreScreenSaver(_THIS)
    3.42 +{
    3.43 +	int timeout, interval, prefer_blank, allow_exp;
    3.44 +	XGetScreenSaver(SDL_Display, &timeout, &interval, &prefer_blank, &allow_exp);
    3.45 +	timeout = screensaver_timeout;
    3.46 +	XSetScreenSaver(SDL_Display, timeout, interval, prefer_blank, allow_exp);
    3.47 +
    3.48 +#if SDL_VIDEO_DRIVER_X11_DPMS
    3.49 +	if ( SDL_X11_HAVE_DPMS ) {
    3.50 +		int dummy;
    3.51 +	  	if ( DPMSQueryExtension(SDL_Display, &dummy, &dummy) ) {
    3.52 +			if ( dpms_enabled ) {
    3.53 +				DPMSEnable(SDL_Display);
    3.54 +			}
    3.55 +		}
    3.56 +	}
    3.57 +#endif /* SDL_VIDEO_DRIVER_X11_DPMS */
    3.58 +}
     4.1 --- a/src/video/x11/SDL_x11events_c.h	Mon May 08 06:23:11 2006 +0000
     4.2 +++ b/src/video/x11/SDL_x11events_c.h	Mon May 08 06:38:13 2006 +0000
     4.3 @@ -28,3 +28,6 @@
     4.4  extern void X11_PumpEvents(_THIS);
     4.5  extern void X11_SetKeyboardState(Display *display, const char *key_vec);
     4.6  
     4.7 +extern void X11_SaveScreenSaver(_THIS);
     4.8 +extern void X11_DisableScreenSaver(_THIS);
     4.9 +extern void X11_RestoreScreenSaver(_THIS);
     5.1 --- a/src/video/x11/SDL_x11sym.h	Mon May 08 06:23:11 2006 +0000
     5.2 +++ b/src/video/x11/SDL_x11sym.h	Mon May 08 06:38:13 2006 +0000
     5.3 @@ -56,9 +56,9 @@
     5.4  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)
     5.5  SDL_X11_SYM(XModifierKeymap*,XGetModifierMapping,(Display* a),(a),return)
     5.6  SDL_X11_SYM(int,XGetPointerControl,(Display* a,int* b,int* c,int* d),(a,b,c,d),return)
     5.7 +SDL_X11_SYM(int,XGetScreenSaver,(Display* a,int* b,int* c,int* d, int* e),(a,b,c,d,e),return)
     5.8  SDL_X11_SYM(XVisualInfo*,XGetVisualInfo,(Display* a,long b,XVisualInfo* c,int* d),(a,b,c,d),return)
     5.9  SDL_X11_SYM(XWMHints*,XGetWMHints,(Display* a,Window b),(a,b),return)
    5.10 -SDL_X11_SYM(Status,XGetTextProperty,(Display* a,Window b,XTextProperty* c,Atom d),(a,b,c,d),return)
    5.11  SDL_X11_SYM(Status,XGetWindowAttributes,(Display* a,Window b,XWindowAttributes* c),(a,b,c),return)
    5.12  SDL_X11_SYM(int,XGrabKeyboard,(Display* a,Window b,Bool c,int d,int e,Time f),(a,b,c,d,e,f),return)
    5.13  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)
    5.14 @@ -91,6 +91,7 @@
    5.15  SDL_X11_SYM(int,XSetClassHint,(Display* a,Window b,XClassHint* c),(a,b,c),return)
    5.16  SDL_X11_SYM(XErrorHandler,XSetErrorHandler,(XErrorHandler a),(a),return)
    5.17  SDL_X11_SYM(XIOErrorHandler,XSetIOErrorHandler,(XIOErrorHandler a),(a),return)
    5.18 +SDL_X11_SYM(int,XSetScreenSaver,(Display* a,int b,int c,int d,int e),(a,b,c,d,e),return)
    5.19  SDL_X11_SYM(int,XSetTransientForHint,(Display* a,Window b,Window c),(a,b,c),return)
    5.20  SDL_X11_SYM(int,XSetWMHints,(Display* a,Window b,XWMHints* c),(a,b,c),return)
    5.21  SDL_X11_SYM(void,XSetTextProperty,(Display* a,Window b,XTextProperty* c,Atom d),(a,b,c,d),)
    5.22 @@ -187,5 +188,14 @@
    5.23  SDL_X11_SYM(void,XRRFreeScreenConfigInfo,(XRRScreenConfiguration *config),(config),)
    5.24  #endif
    5.25  
    5.26 +/* DPMS support */
    5.27 +#if SDL_VIDEO_DRIVER_X11_DPMS
    5.28 +SDL_X11_MODULE(DPMS)
    5.29 +SDL_X11_SYM(Status,DPMSQueryExtension,(Display *dpy,int *major_versionp,int *minor_versionp),(dpy,major_versionp,minor_versionp),return)
    5.30 +SDL_X11_SYM(Status,DPMSInfo,(Display *dpy,CARD16 *state,BOOL *onoff),(dpy,state,onoff),return)
    5.31 +SDL_X11_SYM(Status,DPMSEnable,(Display *dpy),(dpy),return)
    5.32 +SDL_X11_SYM(Status,DPMSDisable,(Display *dpy),(dpy),return)
    5.33 +#endif
    5.34 +
    5.35  /* end of SDL_x11sym.h ... */
    5.36  
     6.1 --- a/src/video/x11/SDL_x11video.c	Mon May 08 06:23:11 2006 +0000
     6.2 +++ b/src/video/x11/SDL_x11video.c	Mon May 08 06:38:13 2006 +0000
     6.3 @@ -544,6 +544,10 @@
     6.4  	}
     6.5  	X11_SaveVidModeGamma(this);
     6.6  
     6.7 +	/* Save DPMS and screensaver settings */
     6.8 +	X11_SaveScreenSaver(this);
     6.9 +	X11_DisableScreenSaver(this);
    6.10 +
    6.11  	/* See if we have been passed a window to use */
    6.12  	SDL_windowid = SDL_getenv("SDL_WINDOWID");
    6.13  
    6.14 @@ -1364,11 +1368,15 @@
    6.15  			SDL_free(SDL_iconcolors);
    6.16  			SDL_iconcolors = NULL;
    6.17  		} 
    6.18 +
    6.19  		/* Restore gamma settings if they've changed */
    6.20  		if ( SDL_GetAppState() & SDL_APPACTIVE ) {
    6.21  			X11_SwapVidModeGamma(this);
    6.22  		}
    6.23  
    6.24 +		/* Restore DPMS and screensaver settings */
    6.25 +		X11_RestoreScreenSaver(this);
    6.26 +
    6.27  		/* Free that blank cursor */
    6.28  		if ( SDL_BlankCursor != NULL ) {
    6.29  			this->FreeWMCursor(this, SDL_BlankCursor);
     7.1 --- a/src/video/x11/SDL_x11video.h	Mon May 08 06:23:11 2006 +0000
     7.2 +++ b/src/video/x11/SDL_x11video.h	Mon May 08 06:38:13 2006 +0000
     7.3 @@ -46,6 +46,9 @@
     7.4  #if SDL_VIDEO_DRIVER_X11_XME
     7.5  #include "../Xext/extensions/xme.h"
     7.6  #endif
     7.7 +#if SDL_VIDEO_DRIVER_X11_DPMS
     7.8 +#include <X11/extensions/dpms.h>
     7.9 +#endif
    7.10  
    7.11  #include "SDL_x11dyn.h"
    7.12  
    7.13 @@ -151,6 +154,12 @@
    7.14      int gamma_changed;		/* flag: has VidMode gamma been modified? */
    7.15  
    7.16      short *iconcolors;		/* List of colors used by the icon */
    7.17 +
    7.18 +    /* Screensaver settings */
    7.19 +    int screensaver_timeout;
    7.20 +#if SDL_VIDEO_DRIVER_X11_DPMS
    7.21 +    BOOL dpms_enabled;
    7.22 +#endif
    7.23  };
    7.24  
    7.25  /* Old variable names */
    7.26 @@ -201,6 +210,8 @@
    7.27  #define gamma_saved		(this->hidden->gamma_saved)
    7.28  #define gamma_changed		(this->hidden->gamma_changed)
    7.29  #define SDL_iconcolors		(this->hidden->iconcolors)
    7.30 +#define screensaver_timeout	(this->hidden->screensaver_timeout)
    7.31 +#define dpms_enabled		(this->hidden->dpms_enabled)
    7.32  /* Some versions of XFree86 have bugs - detect if this is one of them */
    7.33  #define BUGGY_XFREE86(condition, buggy_version) \
    7.34  ((SDL_strcmp(ServerVendor(SDL_Display), "The XFree86 Project, Inc") == 0) && \