Skip to content

Commit

Permalink
iOS: Added support for SDL_DisableScreenSaver and SDL_EnableScreenSaver.
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed May 16, 2015
1 parent f7ac020 commit 240a3fb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/SDL_hints.h
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/video/uikit/SDL_uikitvideo.h
Expand Up @@ -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);

Expand Down
17 changes: 17 additions & 0 deletions src/video/uikit/SDL_uikitvideo.m
Expand Up @@ -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"
Expand Down Expand Up @@ -74,6 +75,7 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device)
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;
Expand Down Expand Up @@ -130,6 +132,21 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device)
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)
{
Expand Down

0 comments on commit 240a3fb

Please sign in to comment.