iOS: Added support for SDL_DisableScreenSaver and SDL_EnableScreenSaver.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 5eaba8f..93ad5cb 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -243,6 +243,9 @@ extern "C" {
* this is problematic. This functionality can be disabled by setting this
* hint.
*
+ * As of SDL 2.0.4, SDL_EnableScreenSaver and SDL_DisableScreenSaver accomplish
+ * the same thing on iOS. They should be preferred over this hint.
+ *
* This variable can be set to the following values:
* "0" - Enable idle timer
* "1" - Disable idle timer
diff --git a/src/video/uikit/SDL_uikitvideo.h b/src/video/uikit/SDL_uikitvideo.h
index dac80a2..190031c 100644
--- a/src/video/uikit/SDL_uikitvideo.h
+++ b/src/video/uikit/SDL_uikitvideo.h
@@ -25,6 +25,8 @@
#include "../SDL_sysvideo.h"
+void UIKit_SuspendScreenSaver(_THIS);
+
BOOL UIKit_IsSystemVersionAtLeast(double version);
CGRect UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen);
diff --git a/src/video/uikit/SDL_uikitvideo.m b/src/video/uikit/SDL_uikitvideo.m
index c3448ef..25e4464 100644
--- a/src/video/uikit/SDL_uikitvideo.m
+++ b/src/video/uikit/SDL_uikitvideo.m
@@ -26,6 +26,7 @@
#include "SDL_video.h"
#include "SDL_mouse.h"
+#include "SDL_hints.h"
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
@@ -74,6 +75,7 @@ UIKit_CreateDevice(int devindex)
device->GetDisplayModes = UIKit_GetDisplayModes;
device->SetDisplayMode = UIKit_SetDisplayMode;
device->PumpEvents = UIKit_PumpEvents;
+ device->SuspendScreenSaver = UIKit_SuspendScreenSaver;
device->CreateWindow = UIKit_CreateWindow;
device->SetWindowTitle = UIKit_SetWindowTitle;
device->ShowWindow = UIKit_ShowWindow;
@@ -130,6 +132,21 @@ UIKit_VideoQuit(_THIS)
UIKit_QuitModes(_this);
}
+void
+UIKit_SuspendScreenSaver(_THIS)
+{
+ @autoreleasepool {
+ /* Ignore ScreenSaver API calls if the idle timer hint has been set. */
+ /* FIXME: The idle timer hint should be deprecated for SDL 2.1. */
+ if (SDL_GetHint(SDL_HINT_IDLE_TIMER_DISABLED) == NULL) {
+ UIApplication *app = [UIApplication sharedApplication];
+
+ /* Prevent the display from dimming and going to sleep. */
+ app.idleTimerDisabled = (_this->suspend_screensaver != SDL_FALSE);
+ }
+ }
+}
+
BOOL
UIKit_IsSystemVersionAtLeast(double version)
{