Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's SDL-1.2
authorRyan C. Gordon <icculus@icculus.org>
Fri, 06 Apr 2007 20:30:41 +0000
branchSDL-1.2
changeset 3936c5c3c772f5aa
parent 3935 00959c391aa6
child 3937 5c6e937518c6
Let app set SDL_VIDEO_ALLOW_SCREENSAVER environment variable to override SDL's
attempt to disable screen savers. Works for Quartz (Mac OS X) and X11.

Need a formal API for this in 1.3, still.

Fixes Bugzilla #415.
src/video/quartz/SDL_QuartzEvents.m
src/video/quartz/SDL_QuartzVideo.h
src/video/quartz/SDL_QuartzVideo.m
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11events_c.h
src/video/x11/SDL_x11video.c
src/video/x11/SDL_x11video.h
     1.1 --- a/src/video/quartz/SDL_QuartzEvents.m	Wed Apr 04 10:34:42 2007 +0000
     1.2 +++ b/src/video/quartz/SDL_QuartzEvents.m	Fri Apr 06 20:30:41 2007 +0000
     1.3 @@ -734,11 +734,13 @@
     1.4          return;  /* don't do anything if there's no screen surface. */
     1.5  
     1.6      /* Update activity every five seconds to prevent screensaver. --ryan. */
     1.7 -    nowTicks = SDL_GetTicks();
     1.8 -    if ((nowTicks - screensaverTicks) > 5000)
     1.9 -    {
    1.10 -        UpdateSystemActivity(UsrActivity);
    1.11 -        screensaverTicks = nowTicks;
    1.12 +    if (!allow_screensaver) {
    1.13 +        nowTicks = SDL_GetTicks();
    1.14 +        if ((nowTicks - screensaverTicks) > 5000)
    1.15 +        {
    1.16 +            UpdateSystemActivity(UsrActivity);
    1.17 +            screensaverTicks = nowTicks;
    1.18 +        }
    1.19      }
    1.20  
    1.21      pool = [ [ NSAutoreleasePool alloc ] init ];
     2.1 --- a/src/video/quartz/SDL_QuartzVideo.h	Wed Apr 04 10:34:42 2007 +0000
     2.2 +++ b/src/video/quartz/SDL_QuartzVideo.h	Fri Apr 06 20:30:41 2007 +0000
     2.3 @@ -80,6 +80,7 @@
     2.4  /* Main driver structure to store required state information */
     2.5  typedef struct SDL_PrivateVideoData {
     2.6  
     2.7 +    BOOL               allow_screensaver;  /* 0 == disable screensaver */
     2.8      CGDirectDisplayID  display;            /* 0 == main display (only support single display) */
     2.9      CFDictionaryRef    mode;               /* current mode of the display */
    2.10      CFDictionaryRef    save_mode;          /* original mode of the display */
    2.11 @@ -127,6 +128,7 @@
    2.12  #define display_id (this->hidden->display)
    2.13  #define mode (this->hidden->mode)
    2.14  #define save_mode (this->hidden->save_mode)
    2.15 +#define allow_screensaver (this->hidden->allow_screensaver)
    2.16  #define mode_list (this->hidden->mode_list)
    2.17  #define palette (this->hidden->palette)
    2.18  #define gl_context (this->hidden->gl_context)
     3.1 --- a/src/video/quartz/SDL_QuartzVideo.m	Wed Apr 04 10:34:42 2007 +0000
     3.2 +++ b/src/video/quartz/SDL_QuartzVideo.m	Fri Apr 06 20:30:41 2007 +0000
     3.3 @@ -169,12 +169,17 @@
     3.4  
     3.5  static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format) {
     3.6  
     3.7 +    const char *env = NULL;
     3.8 +
     3.9      /* Initialize the video settings; this data persists between mode switches */
    3.10      display_id = kCGDirectMainDisplay;
    3.11      save_mode  = CGDisplayCurrentMode    (display_id);
    3.12      mode_list  = CGDisplayAvailableModes (display_id);
    3.13      palette    = CGPaletteCreateDefaultColorPalette ();
    3.14  
    3.15 +    env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER");
    3.16 +    allow_screensaver = ( env && SDL_atoi(env) ) ? YES : NO;
    3.17 +
    3.18      /* Gather some information that is useful to know about the display */
    3.19      CFNumberGetValue (CFDictionaryGetValue (save_mode, kCGDisplayBitsPerPixel),
    3.20                        kCFNumberSInt32Type, &device_bpp);
     4.1 --- a/src/video/x11/SDL_x11events.c	Wed Apr 04 10:34:42 2007 +0000
     4.2 +++ b/src/video/x11/SDL_x11events.c	Fri Apr 06 20:30:41 2007 +0000
     4.3 @@ -1136,9 +1136,14 @@
     4.4  #endif /* SDL_VIDEO_DRIVER_X11_DPMS */
     4.5  }
     4.6  
     4.7 -void X11_DisableScreenSaver(Display *display)
     4.8 +void X11_DisableScreenSaver(_THIS, Display *display)
     4.9  {
    4.10  	int timeout, interval, prefer_blank, allow_exp;
    4.11 +
    4.12 +	if (this->hidden->allow_screensaver) {
    4.13 +		return;
    4.14 +	}
    4.15 +
    4.16  	XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
    4.17  	timeout = 0;
    4.18  	XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp);
    4.19 @@ -1153,9 +1158,14 @@
    4.20  #endif /* SDL_VIDEO_DRIVER_X11_DPMS */
    4.21  }
    4.22  
    4.23 -void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms)
    4.24 +void X11_RestoreScreenSaver(_THIS, Display *display, int saved_timeout, BOOL dpms)
    4.25  {
    4.26  	int timeout, interval, prefer_blank, allow_exp;
    4.27 +
    4.28 +	if (this->hidden->allow_screensaver) {
    4.29 +		return;
    4.30 +	}
    4.31 +
    4.32  	XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
    4.33  	timeout = saved_timeout;
    4.34  	XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp);
     5.1 --- a/src/video/x11/SDL_x11events_c.h	Wed Apr 04 10:34:42 2007 +0000
     5.2 +++ b/src/video/x11/SDL_x11events_c.h	Fri Apr 06 20:30:41 2007 +0000
     5.3 @@ -29,5 +29,5 @@
     5.4  extern void X11_SetKeyboardState(Display *display, const char *key_vec);
     5.5  
     5.6  extern void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms);
     5.7 -extern void X11_DisableScreenSaver(Display *display);
     5.8 -extern void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms);
     5.9 +extern void X11_DisableScreenSaver(_THIS, Display *display);
    5.10 +extern void X11_RestoreScreenSaver(_THIS, Display *display, int saved_timeout, BOOL dpms);
     6.1 --- a/src/video/x11/SDL_x11video.c	Wed Apr 04 10:34:42 2007 +0000
     6.2 +++ b/src/video/x11/SDL_x11video.c	Fri Apr 06 20:30:41 2007 +0000
     6.3 @@ -441,6 +441,7 @@
     6.4  
     6.5  static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
     6.6  {
     6.7 +	const char *env = NULL;
     6.8  	char *display;
     6.9  	int i;
    6.10  
    6.11 @@ -546,7 +547,7 @@
    6.12  
    6.13  	/* Save DPMS and screensaver settings */
    6.14  	X11_SaveScreenSaver(SDL_Display, &screensaver_timeout, &dpms_enabled);
    6.15 -	X11_DisableScreenSaver(SDL_Display);
    6.16 +	X11_DisableScreenSaver(this, SDL_Display);
    6.17  
    6.18  	/* See if we have been passed a window to use */
    6.19  	SDL_windowid = SDL_getenv("SDL_WINDOWID");
    6.20 @@ -562,6 +563,10 @@
    6.21  	/* Fill in some window manager capabilities */
    6.22  	this->info.wm_available = 1;
    6.23  
    6.24 +	/* Allow environment override of screensaver disable. */
    6.25 +	env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER");
    6.26 +	this->hidden->allow_screensaver = ( (env && SDL_atoi(env)) ? 1 : 0 );
    6.27 +
    6.28  	/* We're done! */
    6.29  	XFlush(SDL_Display);
    6.30  	return(0);
    6.31 @@ -1375,7 +1380,7 @@
    6.32  		}
    6.33  
    6.34  		/* Restore DPMS and screensaver settings */
    6.35 -		X11_RestoreScreenSaver(SDL_Display, screensaver_timeout, dpms_enabled);
    6.36 +		X11_RestoreScreenSaver(this, SDL_Display, screensaver_timeout, dpms_enabled);
    6.37  
    6.38  		/* Free that blank cursor */
    6.39  		if ( SDL_BlankCursor != NULL ) {
     7.1 --- a/src/video/x11/SDL_x11video.h	Wed Apr 04 10:34:42 2007 +0000
     7.2 +++ b/src/video/x11/SDL_x11video.h	Fri Apr 06 20:30:41 2007 +0000
     7.3 @@ -139,6 +139,8 @@
     7.4      int use_xme;
     7.5      int currently_fullscreen;
     7.6  
     7.7 +    int allow_screensaver;
     7.8 +
     7.9      /* Automatic mode switching support (entering/leaving fullscreen) */
    7.10      Uint32 switch_waiting;
    7.11      Uint32 switch_time;