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,11 +734,13 @@ void QZ_PumpEvents (_THIS)
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 ];
......
......@@ -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 @@ typedef struct SDL_PrivateVideoData {
#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)
......
......@@ -169,12 +169,17 @@ static void QZ_DeleteDevice (SDL_VideoDevice *device) {
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);
......
......@@ -1136,9 +1136,14 @@ void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *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;
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 @@ void X11_DisableScreenSaver(Display *display)
#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);
......
......@@ -29,5 +29,5 @@ extern void X11_PumpEvents(_THIS);
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);
......@@ -441,6 +441,7 @@ static void create_aux_windows(_THIS)
static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
const char *env = NULL;
char *display;
int i;
......@@ -546,7 +547,7 @@ static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
/* 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 @@ static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
/* 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 @@ void X11_VideoQuit(_THIS)
}
/* 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 ) {
......
......@@ -139,6 +139,8 @@ struct SDL_PrivateVideoData {
int use_xme;
int currently_fullscreen;
int allow_screensaver;
/* Automatic mode switching support (entering/leaving fullscreen) */
Uint32 switch_waiting;
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