Skip to content

Commit

Permalink
Fixed bug #203
Browse files Browse the repository at this point in the history
Disable screensaver and DPMS blanking while SDL app is running.
  • Loading branch information
slouken committed May 8, 2006
1 parent 10cd1cf commit 820c153
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 2 deletions.
14 changes: 13 additions & 1 deletion configure.in
Expand Up @@ -927,10 +927,22 @@ AC_HELP_STRING([--enable-video-x11-xrandr], [enable X11 Xrandr extension for ful
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
}
Expand Down
1 change: 1 addition & 0 deletions include/SDL_config.h.in
Expand Up @@ -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
Expand Down
52 changes: 52 additions & 0 deletions src/video/x11/SDL_x11events.c
Expand Up @@ -1118,3 +1118,55 @@ void X11_InitOSKeymap(_THIS)
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 */
}
3 changes: 3 additions & 0 deletions src/video/x11/SDL_x11events_c.h
Expand Up @@ -28,3 +28,6 @@ extern void X11_InitOSKeymap(_THIS);
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);
12 changes: 11 additions & 1 deletion src/video/x11/SDL_x11sym.h
Expand Up @@ -56,9 +56,9 @@ SDL_X11_SYM(int,XFreePixmap,(Display* a,Pixmap b),(a,b),return)
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)
Expand Down Expand Up @@ -91,6 +91,7 @@ SDL_X11_SYM(Status,XSendEvent,(Display* a,Window b,Bool c,long d,XEvent* e),(a,b
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),)
Expand Down Expand Up @@ -187,5 +188,14 @@ SDL_X11_SYM(Status,XRRSetScreenConfig,(Display *dpy, XRRScreenConfiguration *con
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 ... */

8 changes: 8 additions & 0 deletions src/video/x11/SDL_x11video.c
Expand Up @@ -544,6 +544,10 @@ static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
}
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");

Expand Down Expand Up @@ -1364,11 +1368,15 @@ void X11_VideoQuit(_THIS)
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);
Expand Down
11 changes: 11 additions & 0 deletions src/video/x11/SDL_x11video.h
Expand Up @@ -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"

Expand Down Expand Up @@ -151,6 +154,12 @@ struct SDL_PrivateVideoData {
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 */
Expand Down Expand Up @@ -201,6 +210,8 @@ struct SDL_PrivateVideoData {
#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) && \
Expand Down

0 comments on commit 820c153

Please sign in to comment.