Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
* SDL_IOS_IDLE_TIMER_DISABLED hint
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Angus committed Jun 10, 2011
1 parent e1b5a1e commit e1a2dcc
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 1 deletion.
4 changes: 4 additions & 0 deletions VisualC/SDL/SDL_VS2005.vcproj
Expand Up @@ -907,6 +907,10 @@
RelativePath="..\..\src\SDL_hints.c"
>
</File>
<File
RelativePath="..\..\src\SDL_hints_c.h"
>
</File>
<File
RelativePath="..\..\src\stdlib\SDL_iconv.c"
>
Expand Down
4 changes: 4 additions & 0 deletions VisualC/SDL/SDL_VS2008.vcproj
Expand Up @@ -896,6 +896,10 @@
RelativePath="..\..\src\SDL_hints.c"
>
</File>
<File
RelativePath="..\..\src\SDL_hints_c.h"
>
</File>
<File
RelativePath="..\..\src\stdlib\SDL_iconv.c"
>
Expand Down
3 changes: 2 additions & 1 deletion VisualC/SDL/SDL_VS2010.vcxproj
Expand Up @@ -281,6 +281,7 @@
<ClInclude Include="..\..\src\audio\dummy\SDL_dummyaudio.h" />
<ClInclude Include="..\..\src\audio\windx5\SDL_dx5audio.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\SDL_fatal.h" />
<ClInclude Include="..\..\src\video\SDL_glesfuncs.h" />
Expand Down Expand Up @@ -436,4 +437,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
4 changes: 4 additions & 0 deletions Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj
Expand Up @@ -122,6 +122,7 @@
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, ); }; };
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 */; };
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 */; };
Expand Down Expand Up @@ -376,6 +377,7 @@
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; };
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; };
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>"; };
Expand Down Expand Up @@ -971,6 +973,7 @@
FD99B9D60DD52EDC00FB1D6B /* SDL_fatal.c */,
FD99B9D70DD52EDC00FB1D6B /* SDL_fatal.h */,
0442EC5412FE1C3F004C9285 /* SDL_hints.c */,
22C905CC13A22646003FE4E4 /* SDL_hints_c.h */,
04BAC09B1300C1290055DE28 /* SDL_log.c */,
FD99B9D80DD52EDC00FB1D6B /* SDL.c */,
);
Expand Down Expand Up @@ -1241,6 +1244,7 @@
04BAC0991300C0F70055DE28 /* SDL_log.h in Headers */,
04BAC09C1300C1290055DE28 /* SDL_assert_c.h in Headers */,
0417A516130C988500578583 /* SDL_keycode.h in Headers */,
22C905CD13A22646003FE4E4 /* SDL_hints_c.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
14 changes: 14 additions & 0 deletions include/SDL_hints.h
Expand Up @@ -119,6 +119,20 @@ extern "C" {
*/
#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.
*
Expand Down
20 changes: 20 additions & 0 deletions src/SDL_hints.c
Expand Up @@ -21,6 +21,7 @@
#include "SDL_config.h"

#include "SDL_hints.h"
#include "SDL_hints_c.h"


/* Assuming there aren't many hints set and they aren't being queried in
Expand All @@ -30,11 +31,26 @@ typedef struct SDL_Hint {
char *name;
char *value;
SDL_HintPriority priority;
SDL_HintChangedCb callback;
struct SDL_Hint *next;
} SDL_Hint;

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_SetHintWithPriority(const char *name, const char *value,
Expand All @@ -59,6 +75,9 @@ SDL_SetHintWithPriority(const char *name, const char *value,
return SDL_FALSE;
}
if (SDL_strcmp(hint->value, value) != 0) {
if (hint->callback != NULL) {
(*hint->callback)(name, hint->value, value);
}
SDL_free(hint->value);
hint->value = SDL_strdup(value);
}
Expand All @@ -75,6 +94,7 @@ SDL_SetHintWithPriority(const char *name, const char *value,
hint->name = SDL_strdup(name);
hint->value = SDL_strdup(value);
hint->priority = priority;
hint->callback = NULL;
hint->next = SDL_hints;
SDL_hints = hint;
return SDL_TRUE;
Expand Down
14 changes: 14 additions & 0 deletions src/video/uikit/SDL_uikitappdelegate.m
Expand Up @@ -20,6 +20,9 @@
*/

#import "../SDL_sysvideo.h"
#import "SDL_assert.h"
#import "SDL_hints.h"
#import "../../SDL_hints_c.h"

#import "SDL_uikitappdelegate.h"
#import "SDL_uikitopenglview.h"
Expand Down Expand Up @@ -55,6 +58,13 @@ int main(int argc, char **argv) {
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

/* convenience method */
Expand All @@ -75,6 +85,10 @@ - (id)init {
}

- (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 */
int exit_status = SDL_main(forward_argc, forward_argv);
Expand Down

0 comments on commit e1a2dcc

Please sign in to comment.