* SDL_IOS_IDLE_TIMER_DISABLED hint
authorTim Angus <tim@blackcompanystudios.co.uk>
Fri, 10 Jun 2011 14:23:36 +0100
changeset 55553ecad5e5dbe4
parent 5554 4b4258be8699
child 5556 45a709ef443d
* SDL_IOS_IDLE_TIMER_DISABLED hint
VisualC/SDL/SDL_VS2005.vcproj
VisualC/SDL/SDL_VS2008.vcproj
VisualC/SDL/SDL_VS2010.vcxproj
Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj
include/SDL_hints.h
src/SDL_hints.c
src/video/uikit/SDL_uikitappdelegate.m
     1.1 --- a/VisualC/SDL/SDL_VS2005.vcproj	Fri Jun 10 14:23:24 2011 +0100
     1.2 +++ b/VisualC/SDL/SDL_VS2005.vcproj	Fri Jun 10 14:23:36 2011 +0100
     1.3 @@ -908,6 +908,10 @@
     1.4  			>
     1.5  		</File>
     1.6  		<File
     1.7 +			RelativePath="..\..\src\SDL_hints_c.h"
     1.8 +			>
     1.9 +		</File>
    1.10 +		<File
    1.11  			RelativePath="..\..\src\stdlib\SDL_iconv.c"
    1.12  			>
    1.13  		</File>
     2.1 --- a/VisualC/SDL/SDL_VS2008.vcproj	Fri Jun 10 14:23:24 2011 +0100
     2.2 +++ b/VisualC/SDL/SDL_VS2008.vcproj	Fri Jun 10 14:23:36 2011 +0100
     2.3 @@ -897,6 +897,10 @@
     2.4  			>
     2.5  		</File>
     2.6  		<File
     2.7 +			RelativePath="..\..\src\SDL_hints_c.h"
     2.8 +			>
     2.9 +		</File>
    2.10 +		<File
    2.11  			RelativePath="..\..\src\stdlib\SDL_iconv.c"
    2.12  			>
    2.13  		</File>
     3.1 --- a/VisualC/SDL/SDL_VS2010.vcxproj	Fri Jun 10 14:23:24 2011 +0100
     3.2 +++ b/VisualC/SDL/SDL_VS2010.vcxproj	Fri Jun 10 14:23:36 2011 +0100
     3.3 @@ -281,6 +281,7 @@
     3.4      <ClInclude Include="..\..\src\audio\dummy\SDL_dummyaudio.h" />
     3.5      <ClInclude Include="..\..\src\audio\windx5\SDL_dx5audio.h" />
     3.6      <ClInclude Include="..\..\src\SDL_error_c.h" />
     3.7 +    <ClInclude Include="..\..\src\SDL_hints_c.h" />
     3.8      <ClInclude Include="..\..\src\events\SDL_events_c.h" />
     3.9      <ClInclude Include="..\..\src\SDL_fatal.h" />
    3.10      <ClInclude Include="..\..\src\video\SDL_glesfuncs.h" />
    3.11 @@ -436,4 +437,4 @@
    3.12    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
    3.13    <ImportGroup Label="ExtensionTargets">
    3.14    </ImportGroup>
    3.15 -</Project>
    3.16 \ No newline at end of file
    3.17 +</Project>
     4.1 --- a/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Fri Jun 10 14:23:24 2011 +0100
     4.2 +++ b/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Fri Jun 10 14:23:36 2011 +0100
     4.3 @@ -122,6 +122,7 @@
     4.4  		04FFAB8C12E23B8D00BA343D /* SDL_spinlock.c in Sources */ = {isa = PBXBuildFile; fileRef = 04FFAB8A12E23B8D00BA343D /* SDL_spinlock.c */; };
     4.5  		04FFAB9612E23BDC00BA343D /* SDL_blendmode.h in Headers */ = {isa = PBXBuildFile; fileRef = 04FFAB9312E23BDC00BA343D /* SDL_blendmode.h */; settings = {ATTRIBUTES = (Public, ); }; };
     4.6  		04FFAB9812E23BDC00BA343D /* SDL_shape.h in Headers */ = {isa = PBXBuildFile; fileRef = 04FFAB9512E23BDC00BA343D /* SDL_shape.h */; settings = {ATTRIBUTES = (Public, ); }; };
     4.7 +		22C905CD13A22646003FE4E4 /* SDL_hints_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 22C905CC13A22646003FE4E4 /* SDL_hints_c.h */; };
     4.8  		56ED04E1118A8EE200A56AA6 /* SDL_power.c in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E0118A8EE200A56AA6 /* SDL_power.c */; };
     4.9  		56ED04E3118A8EFD00A56AA6 /* SDL_syspower.m in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */; };
    4.10  		FD24846D0E5655AE0021E198 /* SDL_uikitkeyboard.h in Headers */ = {isa = PBXBuildFile; fileRef = FD24846B0E5655AE0021E198 /* SDL_uikitkeyboard.h */; };
    4.11 @@ -376,6 +377,7 @@
    4.12  		04FFAB8A12E23B8D00BA343D /* SDL_spinlock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_spinlock.c; sourceTree = "<group>"; };
    4.13  		04FFAB9312E23BDC00BA343D /* SDL_blendmode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_blendmode.h; path = ../../include/SDL_blendmode.h; sourceTree = SOURCE_ROOT; };
    4.14  		04FFAB9512E23BDC00BA343D /* SDL_shape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_shape.h; path = ../../include/SDL_shape.h; sourceTree = SOURCE_ROOT; };
    4.15 +		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>"; };
    4.16  		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; };
    4.17  		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; };
    4.18  		FD0BBFEF0E3933DD00D833B1 /* SDL_uikitview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitview.h; sourceTree = "<group>"; };
    4.19 @@ -971,6 +973,7 @@
    4.20  				FD99B9D60DD52EDC00FB1D6B /* SDL_fatal.c */,
    4.21  				FD99B9D70DD52EDC00FB1D6B /* SDL_fatal.h */,
    4.22  				0442EC5412FE1C3F004C9285 /* SDL_hints.c */,
    4.23 +				22C905CC13A22646003FE4E4 /* SDL_hints_c.h */,
    4.24  				04BAC09B1300C1290055DE28 /* SDL_log.c */,
    4.25  				FD99B9D80DD52EDC00FB1D6B /* SDL.c */,
    4.26  			);
    4.27 @@ -1241,6 +1244,7 @@
    4.28  				04BAC0991300C0F70055DE28 /* SDL_log.h in Headers */,
    4.29  				04BAC09C1300C1290055DE28 /* SDL_assert_c.h in Headers */,
    4.30  				0417A516130C988500578583 /* SDL_keycode.h in Headers */,
    4.31 +				22C905CD13A22646003FE4E4 /* SDL_hints_c.h in Headers */,
    4.32  			);
    4.33  			runOnlyForDeploymentPostprocessing = 0;
    4.34  		};
     5.1 --- a/include/SDL_hints.h	Fri Jun 10 14:23:24 2011 +0100
     5.2 +++ b/include/SDL_hints.h	Fri Jun 10 14:23:36 2011 +0100
     5.3 @@ -120,6 +120,20 @@
     5.4  #define SDL_HINT_RENDER_VSYNC               "SDL_RENDER_VSYNC"
     5.5  	
     5.6  /**
     5.7 + *  \brief  A variable controlling whether the idle timer is disabled on iOS.
     5.8 + *
     5.9 + *  When an iOS app does not receive touches for some time, the screen is
    5.10 + *  dimmed automatically. For games where the accelerometer is the only input
    5.11 + *  this is problematic. This functionality can be disabled by setting this
    5.12 + *  hint.
    5.13 + *
    5.14 + *  This variable can be set to the following values:
    5.15 + *    "0"       - Enable idle timer
    5.16 + *    "1"       - Disable idle timer
    5.17 + */
    5.18 +#define SDL_HINT_IDLE_TIMER_DISABLED "SDL_IOS_IDLE_TIMER_DISABLED"
    5.19 +	
    5.20 +/**
    5.21   *  \brief  A variable controlling which orientations are allowed on iOS.
    5.22   *
    5.23   *  In some circumstances it is necessary to be able to explicitly control
     6.1 --- a/src/SDL_hints.c	Fri Jun 10 14:23:24 2011 +0100
     6.2 +++ b/src/SDL_hints.c	Fri Jun 10 14:23:36 2011 +0100
     6.3 @@ -21,6 +21,7 @@
     6.4  #include "SDL_config.h"
     6.5  
     6.6  #include "SDL_hints.h"
     6.7 +#include "SDL_hints_c.h"
     6.8  
     6.9  
    6.10  /* Assuming there aren't many hints set and they aren't being queried in
    6.11 @@ -30,11 +31,26 @@
    6.12      char *name;
    6.13      char *value;
    6.14      SDL_HintPriority priority;
    6.15 +    SDL_HintChangedCb callback;
    6.16      struct SDL_Hint *next;
    6.17  } SDL_Hint;
    6.18  
    6.19  static SDL_Hint *SDL_hints;
    6.20  
    6.21 +SDL_bool
    6.22 +SDL_RegisterHintChangedCb(const char *name, SDL_HintChangedCb hintCb)
    6.23 +{
    6.24 +    SDL_Hint *hint;
    6.25 +	
    6.26 +    for (hint = SDL_hints; hint; hint = hint->next) {
    6.27 +        if (SDL_strcmp(name, hint->name) == 0) {
    6.28 +            hint->callback = hintCb;
    6.29 +            return SDL_TRUE;
    6.30 +        }
    6.31 +    }
    6.32 +	
    6.33 +    return SDL_FALSE;
    6.34 +}
    6.35  
    6.36  SDL_bool
    6.37  SDL_SetHintWithPriority(const char *name, const char *value,
    6.38 @@ -59,6 +75,9 @@
    6.39                  return SDL_FALSE;
    6.40              }
    6.41              if (SDL_strcmp(hint->value, value) != 0) {
    6.42 +                if (hint->callback != NULL) {
    6.43 +                    (*hint->callback)(name, hint->value, value);
    6.44 +                }
    6.45                  SDL_free(hint->value);
    6.46                  hint->value = SDL_strdup(value);
    6.47              }
    6.48 @@ -75,6 +94,7 @@
    6.49      hint->name = SDL_strdup(name);
    6.50      hint->value = SDL_strdup(value);
    6.51      hint->priority = priority;
    6.52 +    hint->callback = NULL;
    6.53      hint->next = SDL_hints;
    6.54      SDL_hints = hint;
    6.55      return SDL_TRUE;
     7.1 --- a/src/video/uikit/SDL_uikitappdelegate.m	Fri Jun 10 14:23:24 2011 +0100
     7.2 +++ b/src/video/uikit/SDL_uikitappdelegate.m	Fri Jun 10 14:23:36 2011 +0100
     7.3 @@ -20,6 +20,9 @@
     7.4  */
     7.5  
     7.6  #import "../SDL_sysvideo.h"
     7.7 +#import "SDL_assert.h"
     7.8 +#import "SDL_hints.h"
     7.9 +#import "../../SDL_hints_c.h"
    7.10  
    7.11  #import "SDL_uikitappdelegate.h"
    7.12  #import "SDL_uikitopenglview.h"
    7.13 @@ -55,6 +58,13 @@
    7.14      return 0;
    7.15  }
    7.16  
    7.17 +static void SDL_IdleTimerDisabledChanged(const char *name, const char *oldValue, const char *newValue) {
    7.18 +    SDL_assert(SDL_strcmp(name, SDL_HINT_IDLE_TIMER_DISABLED) == 0);
    7.19 +    
    7.20 +    BOOL disable = (*newValue != '0');
    7.21 +    [UIApplication sharedApplication].idleTimerDisabled = disable;
    7.22 +}
    7.23 +
    7.24  @implementation SDLUIKitDelegate
    7.25  
    7.26  /* convenience method */
    7.27 @@ -75,6 +85,10 @@
    7.28  }
    7.29  
    7.30  - (void)postFinishLaunch {
    7.31 +    
    7.32 +    /* register a callback for the idletimer hint */
    7.33 +    SDL_SetHint(SDL_HINT_IDLE_TIMER_DISABLED, "0");
    7.34 +    SDL_RegisterHintChangedCb(SDL_HINT_IDLE_TIMER_DISABLED, &SDL_IdleTimerDisabledChanged);
    7.35  
    7.36      /* run the user's application, passing argc and argv */
    7.37      int exit_status = SDL_main(forward_argc, forward_argv);