Added a hint to enable the screensaver by default
authorSam Lantinga <slouken@libsdl.org>
Fri, 28 Feb 2014 14:23:41 -0800
changeset 8266 d123fc5d02bc
parent 8265 1ed54c57d6c7
child 8267 3e857d08cd02
Added a hint to enable the screensaver by default
include/SDL_hints.h
src/video/SDL_video.c
--- a/include/SDL_hints.h	Thu Feb 27 22:06:41 2014 -0500
+++ b/include/SDL_hints.h	Fri Feb 28 14:23:41 2014 -0800
@@ -129,6 +129,17 @@
 #define SDL_HINT_RENDER_VSYNC               "SDL_RENDER_VSYNC"
 
 /**
+ *  \brief  A variable controlling whether the screensaver is enabled. 
+ *
+ *  This variable can be set to the following values:
+ *    "0"       - Disable screensaver
+ *    "1"       - Enable screensaver
+ *
+ *  By default SDL will disable the screensaver.
+ */
+#define SDL_HINT_VIDEO_ALLOW_SCREENSAVER    "SDL_VIDEO_ALLOW_SCREENSAVER"
+
+/**
  *  \brief  A variable controlling whether the X11 VidMode extension should be used.
  *
  *  This variable can be set to the following values:
--- a/src/video/SDL_video.c	Thu Feb 27 22:06:41 2014 -0500
+++ b/src/video/SDL_video.c	Fri Feb 28 14:23:41 2014 -0800
@@ -421,8 +421,10 @@
 SDL_VideoInit(const char *driver_name)
 {
     SDL_VideoDevice *video;
+    const char *hint;
     int index;
     int i;
+    SDL_bool allow_screensaver;
 
     /* Check to make sure we don't overwrite '_this' */
     if (_this != NULL) {
@@ -510,7 +512,15 @@
        joystick, or passively watching a movie. Things that use SDL but
        function more like a normal desktop app should explicitly reenable the
        screensaver. */
-    SDL_DisableScreenSaver();
+    hint = SDL_GetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER);
+    if (hint) {
+        allow_screensaver = SDL_atoi(hint) ? SDL_TRUE : SDL_FALSE;
+    } else {
+        allow_screensaver = SDL_FALSE;
+    }
+    if (!allow_screensaver) {
+        SDL_DisableScreenSaver();
+    }
 
     /* If we don't use a screen keyboard, turn on text input by default,
        otherwise programs that expect to get text events without enabling