# HG changeset patch # User Ryan C. Gordon # Date 1175891441 0 # Node ID c5c3c772f5aa1f159d313d6003060e706e4f8254 # Parent 00959c391aa657aefd4fe58a93231f8dbc0e54c6 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. diff -r 00959c391aa6 -r c5c3c772f5aa src/video/quartz/SDL_QuartzEvents.m --- a/src/video/quartz/SDL_QuartzEvents.m Wed Apr 04 10:34:42 2007 +0000 +++ b/src/video/quartz/SDL_QuartzEvents.m Fri Apr 06 20:30:41 2007 +0000 @@ -734,11 +734,13 @@ return; /* don't do anything if there's no screen surface. */ /* Update activity every five seconds to prevent screensaver. --ryan. */ - nowTicks = SDL_GetTicks(); - if ((nowTicks - screensaverTicks) > 5000) - { - UpdateSystemActivity(UsrActivity); - screensaverTicks = nowTicks; + if (!allow_screensaver) { + nowTicks = SDL_GetTicks(); + if ((nowTicks - screensaverTicks) > 5000) + { + UpdateSystemActivity(UsrActivity); + screensaverTicks = nowTicks; + } } pool = [ [ NSAutoreleasePool alloc ] init ]; diff -r 00959c391aa6 -r c5c3c772f5aa src/video/quartz/SDL_QuartzVideo.h --- a/src/video/quartz/SDL_QuartzVideo.h Wed Apr 04 10:34:42 2007 +0000 +++ b/src/video/quartz/SDL_QuartzVideo.h Fri Apr 06 20:30:41 2007 +0000 @@ -80,6 +80,7 @@ /* Main driver structure to store required state information */ typedef struct SDL_PrivateVideoData { + BOOL allow_screensaver; /* 0 == disable screensaver */ CGDirectDisplayID display; /* 0 == main display (only support single display) */ CFDictionaryRef mode; /* current mode of the display */ CFDictionaryRef save_mode; /* original mode of the display */ @@ -127,6 +128,7 @@ #define display_id (this->hidden->display) #define mode (this->hidden->mode) #define save_mode (this->hidden->save_mode) +#define allow_screensaver (this->hidden->allow_screensaver) #define mode_list (this->hidden->mode_list) #define palette (this->hidden->palette) #define gl_context (this->hidden->gl_context) diff -r 00959c391aa6 -r c5c3c772f5aa src/video/quartz/SDL_QuartzVideo.m --- a/src/video/quartz/SDL_QuartzVideo.m Wed Apr 04 10:34:42 2007 +0000 +++ b/src/video/quartz/SDL_QuartzVideo.m Fri Apr 06 20:30:41 2007 +0000 @@ -169,12 +169,17 @@ static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format) { + const char *env = NULL; + /* Initialize the video settings; this data persists between mode switches */ display_id = kCGDirectMainDisplay; save_mode = CGDisplayCurrentMode (display_id); mode_list = CGDisplayAvailableModes (display_id); palette = CGPaletteCreateDefaultColorPalette (); + env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER"); + allow_screensaver = ( env && SDL_atoi(env) ) ? YES : NO; + /* Gather some information that is useful to know about the display */ CFNumberGetValue (CFDictionaryGetValue (save_mode, kCGDisplayBitsPerPixel), kCFNumberSInt32Type, &device_bpp); diff -r 00959c391aa6 -r c5c3c772f5aa src/video/x11/SDL_x11events.c --- a/src/video/x11/SDL_x11events.c Wed Apr 04 10:34:42 2007 +0000 +++ b/src/video/x11/SDL_x11events.c Fri Apr 06 20:30:41 2007 +0000 @@ -1136,9 +1136,14 @@ #endif /* SDL_VIDEO_DRIVER_X11_DPMS */ } -void X11_DisableScreenSaver(Display *display) +void X11_DisableScreenSaver(_THIS, Display *display) { int timeout, interval, prefer_blank, allow_exp; + + if (this->hidden->allow_screensaver) { + return; + } + XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp); timeout = 0; XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp); @@ -1153,9 +1158,14 @@ #endif /* SDL_VIDEO_DRIVER_X11_DPMS */ } -void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms) +void X11_RestoreScreenSaver(_THIS, Display *display, int saved_timeout, BOOL dpms) { int timeout, interval, prefer_blank, allow_exp; + + if (this->hidden->allow_screensaver) { + return; + } + XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp); timeout = saved_timeout; XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp); diff -r 00959c391aa6 -r c5c3c772f5aa src/video/x11/SDL_x11events_c.h --- a/src/video/x11/SDL_x11events_c.h Wed Apr 04 10:34:42 2007 +0000 +++ b/src/video/x11/SDL_x11events_c.h Fri Apr 06 20:30:41 2007 +0000 @@ -29,5 +29,5 @@ extern void X11_SetKeyboardState(Display *display, const char *key_vec); extern void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms); -extern void X11_DisableScreenSaver(Display *display); -extern void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms); +extern void X11_DisableScreenSaver(_THIS, Display *display); +extern void X11_RestoreScreenSaver(_THIS, Display *display, int saved_timeout, BOOL dpms); diff -r 00959c391aa6 -r c5c3c772f5aa src/video/x11/SDL_x11video.c --- a/src/video/x11/SDL_x11video.c Wed Apr 04 10:34:42 2007 +0000 +++ b/src/video/x11/SDL_x11video.c Fri Apr 06 20:30:41 2007 +0000 @@ -441,6 +441,7 @@ static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat) { + const char *env = NULL; char *display; int i; @@ -546,7 +547,7 @@ /* Save DPMS and screensaver settings */ X11_SaveScreenSaver(SDL_Display, &screensaver_timeout, &dpms_enabled); - X11_DisableScreenSaver(SDL_Display); + X11_DisableScreenSaver(this, SDL_Display); /* See if we have been passed a window to use */ SDL_windowid = SDL_getenv("SDL_WINDOWID"); @@ -562,6 +563,10 @@ /* Fill in some window manager capabilities */ this->info.wm_available = 1; + /* Allow environment override of screensaver disable. */ + env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER"); + this->hidden->allow_screensaver = ( (env && SDL_atoi(env)) ? 1 : 0 ); + /* We're done! */ XFlush(SDL_Display); return(0); @@ -1375,7 +1380,7 @@ } /* Restore DPMS and screensaver settings */ - X11_RestoreScreenSaver(SDL_Display, screensaver_timeout, dpms_enabled); + X11_RestoreScreenSaver(this, SDL_Display, screensaver_timeout, dpms_enabled); /* Free that blank cursor */ if ( SDL_BlankCursor != NULL ) { diff -r 00959c391aa6 -r c5c3c772f5aa src/video/x11/SDL_x11video.h --- a/src/video/x11/SDL_x11video.h Wed Apr 04 10:34:42 2007 +0000 +++ b/src/video/x11/SDL_x11video.h Fri Apr 06 20:30:41 2007 +0000 @@ -139,6 +139,8 @@ int use_xme; int currently_fullscreen; + int allow_screensaver; + /* Automatic mode switching support (entering/leaving fullscreen) */ Uint32 switch_waiting; Uint32 switch_time;