Commit 0ea790c9 authored by Ryan C. Gordon's avatar Ryan C. Gordon

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.

--HG--
branch : SDL-1.2
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%402305
parent b120a012
...@@ -734,12 +734,14 @@ void QZ_PumpEvents (_THIS) ...@@ -734,12 +734,14 @@ void QZ_PumpEvents (_THIS)
return; /* don't do anything if there's no screen surface. */ return; /* don't do anything if there's no screen surface. */
/* Update activity every five seconds to prevent screensaver. --ryan. */ /* Update activity every five seconds to prevent screensaver. --ryan. */
if (!allow_screensaver) {
nowTicks = SDL_GetTicks(); nowTicks = SDL_GetTicks();
if ((nowTicks - screensaverTicks) > 5000) if ((nowTicks - screensaverTicks) > 5000)
{ {
UpdateSystemActivity(UsrActivity); UpdateSystemActivity(UsrActivity);
screensaverTicks = nowTicks; screensaverTicks = nowTicks;
} }
}
pool = [ [ NSAutoreleasePool alloc ] init ]; pool = [ [ NSAutoreleasePool alloc ] init ];
distantPast = [ NSDate distantPast ]; distantPast = [ NSDate distantPast ];
......
...@@ -80,6 +80,7 @@ ...@@ -80,6 +80,7 @@
/* Main driver structure to store required state information */ /* Main driver structure to store required state information */
typedef struct SDL_PrivateVideoData { typedef struct SDL_PrivateVideoData {
BOOL allow_screensaver; /* 0 == disable screensaver */
CGDirectDisplayID display; /* 0 == main display (only support single display) */ CGDirectDisplayID display; /* 0 == main display (only support single display) */
CFDictionaryRef mode; /* current mode of the display */ CFDictionaryRef mode; /* current mode of the display */
CFDictionaryRef save_mode; /* original mode of the display */ CFDictionaryRef save_mode; /* original mode of the display */
...@@ -127,6 +128,7 @@ typedef struct SDL_PrivateVideoData { ...@@ -127,6 +128,7 @@ typedef struct SDL_PrivateVideoData {
#define display_id (this->hidden->display) #define display_id (this->hidden->display)
#define mode (this->hidden->mode) #define mode (this->hidden->mode)
#define save_mode (this->hidden->save_mode) #define save_mode (this->hidden->save_mode)
#define allow_screensaver (this->hidden->allow_screensaver)
#define mode_list (this->hidden->mode_list) #define mode_list (this->hidden->mode_list)
#define palette (this->hidden->palette) #define palette (this->hidden->palette)
#define gl_context (this->hidden->gl_context) #define gl_context (this->hidden->gl_context)
......
...@@ -169,12 +169,17 @@ static void QZ_DeleteDevice (SDL_VideoDevice *device) { ...@@ -169,12 +169,17 @@ static void QZ_DeleteDevice (SDL_VideoDevice *device) {
static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format) { static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format) {
const char *env = NULL;
/* Initialize the video settings; this data persists between mode switches */ /* Initialize the video settings; this data persists between mode switches */
display_id = kCGDirectMainDisplay; display_id = kCGDirectMainDisplay;
save_mode = CGDisplayCurrentMode (display_id); save_mode = CGDisplayCurrentMode (display_id);
mode_list = CGDisplayAvailableModes (display_id); mode_list = CGDisplayAvailableModes (display_id);
palette = CGPaletteCreateDefaultColorPalette (); 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 */ /* Gather some information that is useful to know about the display */
CFNumberGetValue (CFDictionaryGetValue (save_mode, kCGDisplayBitsPerPixel), CFNumberGetValue (CFDictionaryGetValue (save_mode, kCGDisplayBitsPerPixel),
kCFNumberSInt32Type, &device_bpp); kCFNumberSInt32Type, &device_bpp);
......
...@@ -1136,9 +1136,14 @@ void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms) ...@@ -1136,9 +1136,14 @@ void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms)
#endif /* SDL_VIDEO_DRIVER_X11_DPMS */ #endif /* SDL_VIDEO_DRIVER_X11_DPMS */
} }
void X11_DisableScreenSaver(Display *display) void X11_DisableScreenSaver(_THIS, Display *display)
{ {
int timeout, interval, prefer_blank, allow_exp; int timeout, interval, prefer_blank, allow_exp;
if (this->hidden->allow_screensaver) {
return;
}
XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp); XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
timeout = 0; timeout = 0;
XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp); XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp);
...@@ -1153,9 +1158,14 @@ void X11_DisableScreenSaver(Display *display) ...@@ -1153,9 +1158,14 @@ void X11_DisableScreenSaver(Display *display)
#endif /* SDL_VIDEO_DRIVER_X11_DPMS */ #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; int timeout, interval, prefer_blank, allow_exp;
if (this->hidden->allow_screensaver) {
return;
}
XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp); XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
timeout = saved_timeout; timeout = saved_timeout;
XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp); XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp);
......
...@@ -29,5 +29,5 @@ extern void X11_PumpEvents(_THIS); ...@@ -29,5 +29,5 @@ extern void X11_PumpEvents(_THIS);
extern void X11_SetKeyboardState(Display *display, const char *key_vec); extern void X11_SetKeyboardState(Display *display, const char *key_vec);
extern void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms); extern void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms);
extern void X11_DisableScreenSaver(Display *display); extern void X11_DisableScreenSaver(_THIS, Display *display);
extern void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms); extern void X11_RestoreScreenSaver(_THIS, Display *display, int saved_timeout, BOOL dpms);
...@@ -441,6 +441,7 @@ static void create_aux_windows(_THIS) ...@@ -441,6 +441,7 @@ static void create_aux_windows(_THIS)
static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat) static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
{ {
const char *env = NULL;
char *display; char *display;
int i; int i;
...@@ -546,7 +547,7 @@ static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat) ...@@ -546,7 +547,7 @@ static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
/* Save DPMS and screensaver settings */ /* Save DPMS and screensaver settings */
X11_SaveScreenSaver(SDL_Display, &screensaver_timeout, &dpms_enabled); 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 */ /* See if we have been passed a window to use */
SDL_windowid = SDL_getenv("SDL_WINDOWID"); SDL_windowid = SDL_getenv("SDL_WINDOWID");
...@@ -562,6 +563,10 @@ static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat) ...@@ -562,6 +563,10 @@ static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
/* Fill in some window manager capabilities */ /* Fill in some window manager capabilities */
this->info.wm_available = 1; 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! */ /* We're done! */
XFlush(SDL_Display); XFlush(SDL_Display);
return(0); return(0);
...@@ -1375,7 +1380,7 @@ void X11_VideoQuit(_THIS) ...@@ -1375,7 +1380,7 @@ void X11_VideoQuit(_THIS)
} }
/* Restore DPMS and screensaver settings */ /* 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 */ /* Free that blank cursor */
if ( SDL_BlankCursor != NULL ) { if ( SDL_BlankCursor != NULL ) {
......
...@@ -139,6 +139,8 @@ struct SDL_PrivateVideoData { ...@@ -139,6 +139,8 @@ struct SDL_PrivateVideoData {
int use_xme; int use_xme;
int currently_fullscreen; int currently_fullscreen;
int allow_screensaver;
/* Automatic mode switching support (entering/leaving fullscreen) */ /* Automatic mode switching support (entering/leaving fullscreen) */
Uint32 switch_waiting; Uint32 switch_waiting;
Uint32 switch_time; Uint32 switch_time;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment