Commit 2f0bec32 authored by Tim Angus's avatar Tim Angus

* SDL_IOS_IDLE_TIMER_DISABLED hint

parent a36a856b
...@@ -907,6 +907,10 @@ ...@@ -907,6 +907,10 @@
RelativePath="..\..\src\SDL_hints.c" RelativePath="..\..\src\SDL_hints.c"
> >
</File> </File>
<File
RelativePath="..\..\src\SDL_hints_c.h"
>
</File>
<File <File
RelativePath="..\..\src\stdlib\SDL_iconv.c" RelativePath="..\..\src\stdlib\SDL_iconv.c"
> >
......
...@@ -896,6 +896,10 @@ ...@@ -896,6 +896,10 @@
RelativePath="..\..\src\SDL_hints.c" RelativePath="..\..\src\SDL_hints.c"
> >
</File> </File>
<File
RelativePath="..\..\src\SDL_hints_c.h"
>
</File>
<File <File
RelativePath="..\..\src\stdlib\SDL_iconv.c" RelativePath="..\..\src\stdlib\SDL_iconv.c"
> >
......
...@@ -281,6 +281,7 @@ ...@@ -281,6 +281,7 @@
<ClInclude Include="..\..\src\audio\dummy\SDL_dummyaudio.h" /> <ClInclude Include="..\..\src\audio\dummy\SDL_dummyaudio.h" />
<ClInclude Include="..\..\src\audio\windx5\SDL_dx5audio.h" /> <ClInclude Include="..\..\src\audio\windx5\SDL_dx5audio.h" />
<ClInclude Include="..\..\src\SDL_error_c.h" /> <ClInclude Include="..\..\src\SDL_error_c.h" />
<ClInclude Include="..\..\src\SDL_hints_c.h" />
<ClInclude Include="..\..\src\events\SDL_events_c.h" /> <ClInclude Include="..\..\src\events\SDL_events_c.h" />
<ClInclude Include="..\..\src\SDL_fatal.h" /> <ClInclude Include="..\..\src\SDL_fatal.h" />
<ClInclude Include="..\..\src\video\SDL_glesfuncs.h" /> <ClInclude Include="..\..\src\video\SDL_glesfuncs.h" />
......
...@@ -122,6 +122,7 @@ ...@@ -122,6 +122,7 @@
04FFAB8C12E23B8D00BA343D /* SDL_spinlock.c in Sources */ = {isa = PBXBuildFile; fileRef = 04FFAB8A12E23B8D00BA343D /* SDL_spinlock.c */; }; 04FFAB8C12E23B8D00BA343D /* SDL_spinlock.c in Sources */ = {isa = PBXBuildFile; fileRef = 04FFAB8A12E23B8D00BA343D /* SDL_spinlock.c */; };
04FFAB9612E23BDC00BA343D /* SDL_blendmode.h in Headers */ = {isa = PBXBuildFile; fileRef = 04FFAB9312E23BDC00BA343D /* SDL_blendmode.h */; settings = {ATTRIBUTES = (Public, ); }; }; 04FFAB9612E23BDC00BA343D /* SDL_blendmode.h in Headers */ = {isa = PBXBuildFile; fileRef = 04FFAB9312E23BDC00BA343D /* SDL_blendmode.h */; settings = {ATTRIBUTES = (Public, ); }; };
04FFAB9812E23BDC00BA343D /* SDL_shape.h in Headers */ = {isa = PBXBuildFile; fileRef = 04FFAB9512E23BDC00BA343D /* SDL_shape.h */; settings = {ATTRIBUTES = (Public, ); }; }; 04FFAB9812E23BDC00BA343D /* SDL_shape.h in Headers */ = {isa = PBXBuildFile; fileRef = 04FFAB9512E23BDC00BA343D /* SDL_shape.h */; settings = {ATTRIBUTES = (Public, ); }; };
22C905CD13A22646003FE4E4 /* SDL_hints_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 22C905CC13A22646003FE4E4 /* SDL_hints_c.h */; };
56ED04E1118A8EE200A56AA6 /* SDL_power.c in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E0118A8EE200A56AA6 /* SDL_power.c */; }; 56ED04E1118A8EE200A56AA6 /* SDL_power.c in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E0118A8EE200A56AA6 /* SDL_power.c */; };
56ED04E3118A8EFD00A56AA6 /* SDL_syspower.m in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */; }; 56ED04E3118A8EFD00A56AA6 /* SDL_syspower.m in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */; };
FD24846D0E5655AE0021E198 /* SDL_uikitkeyboard.h in Headers */ = {isa = PBXBuildFile; fileRef = FD24846B0E5655AE0021E198 /* SDL_uikitkeyboard.h */; }; FD24846D0E5655AE0021E198 /* SDL_uikitkeyboard.h in Headers */ = {isa = PBXBuildFile; fileRef = FD24846B0E5655AE0021E198 /* SDL_uikitkeyboard.h */; };
...@@ -376,6 +377,7 @@ ...@@ -376,6 +377,7 @@
04FFAB8A12E23B8D00BA343D /* SDL_spinlock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_spinlock.c; sourceTree = "<group>"; }; 04FFAB8A12E23B8D00BA343D /* SDL_spinlock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_spinlock.c; sourceTree = "<group>"; };
04FFAB9312E23BDC00BA343D /* SDL_blendmode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_blendmode.h; path = ../../include/SDL_blendmode.h; sourceTree = SOURCE_ROOT; }; 04FFAB9312E23BDC00BA343D /* SDL_blendmode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_blendmode.h; path = ../../include/SDL_blendmode.h; sourceTree = SOURCE_ROOT; };
04FFAB9512E23BDC00BA343D /* SDL_shape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_shape.h; path = ../../include/SDL_shape.h; sourceTree = SOURCE_ROOT; }; 04FFAB9512E23BDC00BA343D /* SDL_shape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_shape.h; path = ../../include/SDL_shape.h; sourceTree = SOURCE_ROOT; };
22C905CC13A22646003FE4E4 /* SDL_hints_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_hints_c.h; path = ../../src/SDL_hints_c.h; sourceTree = "<group>"; };
56ED04E0118A8EE200A56AA6 /* SDL_power.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDL_power.c; path = ../../src/power/SDL_power.c; sourceTree = SOURCE_ROOT; }; 56ED04E0118A8EE200A56AA6 /* SDL_power.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDL_power.c; path = ../../src/power/SDL_power.c; sourceTree = SOURCE_ROOT; };
56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDL_syspower.m; path = ../../src/power/uikit/SDL_syspower.m; sourceTree = SOURCE_ROOT; }; 56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDL_syspower.m; path = ../../src/power/uikit/SDL_syspower.m; sourceTree = SOURCE_ROOT; };
FD0BBFEF0E3933DD00D833B1 /* SDL_uikitview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitview.h; sourceTree = "<group>"; }; FD0BBFEF0E3933DD00D833B1 /* SDL_uikitview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitview.h; sourceTree = "<group>"; };
...@@ -971,6 +973,7 @@ ...@@ -971,6 +973,7 @@
FD99B9D60DD52EDC00FB1D6B /* SDL_fatal.c */, FD99B9D60DD52EDC00FB1D6B /* SDL_fatal.c */,
FD99B9D70DD52EDC00FB1D6B /* SDL_fatal.h */, FD99B9D70DD52EDC00FB1D6B /* SDL_fatal.h */,
0442EC5412FE1C3F004C9285 /* SDL_hints.c */, 0442EC5412FE1C3F004C9285 /* SDL_hints.c */,
22C905CC13A22646003FE4E4 /* SDL_hints_c.h */,
04BAC09B1300C1290055DE28 /* SDL_log.c */, 04BAC09B1300C1290055DE28 /* SDL_log.c */,
FD99B9D80DD52EDC00FB1D6B /* SDL.c */, FD99B9D80DD52EDC00FB1D6B /* SDL.c */,
); );
...@@ -1241,6 +1244,7 @@ ...@@ -1241,6 +1244,7 @@
04BAC0991300C0F70055DE28 /* SDL_log.h in Headers */, 04BAC0991300C0F70055DE28 /* SDL_log.h in Headers */,
04BAC09C1300C1290055DE28 /* SDL_assert_c.h in Headers */, 04BAC09C1300C1290055DE28 /* SDL_assert_c.h in Headers */,
0417A516130C988500578583 /* SDL_keycode.h in Headers */, 0417A516130C988500578583 /* SDL_keycode.h in Headers */,
22C905CD13A22646003FE4E4 /* SDL_hints_c.h in Headers */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
......
...@@ -119,6 +119,20 @@ extern "C" { ...@@ -119,6 +119,20 @@ extern "C" {
*/ */
#define SDL_HINT_RENDER_VSYNC "SDL_RENDER_VSYNC" #define SDL_HINT_RENDER_VSYNC "SDL_RENDER_VSYNC"
/**
* \brief A variable controlling whether the idle timer is disabled on iOS.
*
* When an iOS app does not receive touches for some time, the screen is
* dimmed automatically. For games where the accelerometer is the only input
* this is problematic. This functionality can be disabled by setting this
* hint.
*
* This variable can be set to the following values:
* "0" - Enable idle timer
* "1" - Disable idle timer
*/
#define SDL_HINT_IDLE_TIMER_DISABLED "SDL_IOS_IDLE_TIMER_DISABLED"
/** /**
* \brief A variable controlling which orientations are allowed on iOS. * \brief A variable controlling which orientations are allowed on iOS.
* *
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "SDL_config.h" #include "SDL_config.h"
#include "SDL_hints.h" #include "SDL_hints.h"
#include "SDL_hints_c.h"
/* Assuming there aren't many hints set and they aren't being queried in /* Assuming there aren't many hints set and they aren't being queried in
...@@ -30,11 +31,26 @@ typedef struct SDL_Hint { ...@@ -30,11 +31,26 @@ typedef struct SDL_Hint {
char *name; char *name;
char *value; char *value;
SDL_HintPriority priority; SDL_HintPriority priority;
SDL_HintChangedCb callback;
struct SDL_Hint *next; struct SDL_Hint *next;
} SDL_Hint; } SDL_Hint;
static SDL_Hint *SDL_hints; static SDL_Hint *SDL_hints;
SDL_bool
SDL_RegisterHintChangedCb(const char *name, SDL_HintChangedCb hintCb)
{
SDL_Hint *hint;
for (hint = SDL_hints; hint; hint = hint->next) {
if (SDL_strcmp(name, hint->name) == 0) {
hint->callback = hintCb;
return SDL_TRUE;
}
}
return SDL_FALSE;
}
SDL_bool SDL_bool
SDL_SetHintWithPriority(const char *name, const char *value, SDL_SetHintWithPriority(const char *name, const char *value,
...@@ -59,6 +75,9 @@ SDL_SetHintWithPriority(const char *name, const char *value, ...@@ -59,6 +75,9 @@ SDL_SetHintWithPriority(const char *name, const char *value,
return SDL_FALSE; return SDL_FALSE;
} }
if (SDL_strcmp(hint->value, value) != 0) { if (SDL_strcmp(hint->value, value) != 0) {
if (hint->callback != NULL) {
(*hint->callback)(name, hint->value, value);
}
SDL_free(hint->value); SDL_free(hint->value);
hint->value = SDL_strdup(value); hint->value = SDL_strdup(value);
} }
...@@ -75,6 +94,7 @@ SDL_SetHintWithPriority(const char *name, const char *value, ...@@ -75,6 +94,7 @@ SDL_SetHintWithPriority(const char *name, const char *value,
hint->name = SDL_strdup(name); hint->name = SDL_strdup(name);
hint->value = SDL_strdup(value); hint->value = SDL_strdup(value);
hint->priority = priority; hint->priority = priority;
hint->callback = NULL;
hint->next = SDL_hints; hint->next = SDL_hints;
SDL_hints = hint; SDL_hints = hint;
return SDL_TRUE; return SDL_TRUE;
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
*/ */
#import "../SDL_sysvideo.h" #import "../SDL_sysvideo.h"
#import "SDL_assert.h"
#import "SDL_hints.h"
#import "../../SDL_hints_c.h"
#import "SDL_uikitappdelegate.h" #import "SDL_uikitappdelegate.h"
#import "SDL_uikitopenglview.h" #import "SDL_uikitopenglview.h"
...@@ -55,6 +58,13 @@ int main(int argc, char **argv) { ...@@ -55,6 +58,13 @@ int main(int argc, char **argv) {
return 0; return 0;
} }
static void SDL_IdleTimerDisabledChanged(const char *name, const char *oldValue, const char *newValue) {
SDL_assert(SDL_strcmp(name, SDL_HINT_IDLE_TIMER_DISABLED) == 0);
BOOL disable = (*newValue != '0');
[UIApplication sharedApplication].idleTimerDisabled = disable;
}
@implementation SDLUIKitDelegate @implementation SDLUIKitDelegate
/* convenience method */ /* convenience method */
...@@ -76,6 +86,10 @@ int main(int argc, char **argv) { ...@@ -76,6 +86,10 @@ int main(int argc, char **argv) {
- (void)postFinishLaunch { - (void)postFinishLaunch {
/* register a callback for the idletimer hint */
SDL_SetHint(SDL_HINT_IDLE_TIMER_DISABLED, "0");
SDL_RegisterHintChangedCb(SDL_HINT_IDLE_TIMER_DISABLED, &SDL_IdleTimerDisabledChanged);
/* run the user's application, passing argc and argv */ /* run the user's application, passing argc and argv */
int exit_status = SDL_main(forward_argc, forward_argv); int exit_status = SDL_main(forward_argc, forward_argv);
......
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