Implemented SDL power APIs for iPhoneOS.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 30 Apr 2010 00:39:31 -0400
changeset 444442e1092225f9
parent 4443 c598e440c87c
child 4445 06becafcac89
Implemented SDL power APIs for iPhoneOS.
Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj
Xcode-iPhoneOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj
include/SDL_config_iphoneos.h
src/power/SDL_power.c
src/power/uikit/SDL_syspower.m
src/video/uikit/SDL_uikitopengles.m
     1.1 --- a/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Thu Apr 29 22:53:18 2010 -0400
     1.2 +++ b/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Fri Apr 30 00:39:31 2010 -0400
     1.3 @@ -65,6 +65,8 @@
     1.4  		04EC8B521025D12900431D42 /* SDL_config_iphoneos.h in Headers */ = {isa = PBXBuildFile; fileRef = 04EC8B501025D12900431D42 /* SDL_config_iphoneos.h */; };
     1.5  		04F2AF541104ABC300D6DDF7 /* SDL_assert.h in Headers */ = {isa = PBXBuildFile; fileRef = 04F2AF531104ABC300D6DDF7 /* SDL_assert.h */; };
     1.6  		04F2AF561104ABD200D6DDF7 /* SDL_assert.c in Sources */ = {isa = PBXBuildFile; fileRef = 04F2AF551104ABD200D6DDF7 /* SDL_assert.c */; };
     1.7 +		56ED04E1118A8EE200A56AA6 /* SDL_power.c in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E0118A8EE200A56AA6 /* SDL_power.c */; };
     1.8 +		56ED04E3118A8EFD00A56AA6 /* SDL_syspower.m in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */; };
     1.9  		FD24846D0E5655AE0021E198 /* SDL_uikitkeyboard.h in Headers */ = {isa = PBXBuildFile; fileRef = FD24846B0E5655AE0021E198 /* SDL_uikitkeyboard.h */; };
    1.10  		FD3F495C0DEA5B2100C5B771 /* begin_code.h in Headers */ = {isa = PBXBuildFile; fileRef = FD99B8CC0DD52EB400FB1D6B /* begin_code.h */; settings = {ATTRIBUTES = (Public, ); }; };
    1.11  		FD3F495D0DEA5B2100C5B771 /* close_code.h in Headers */ = {isa = PBXBuildFile; fileRef = FD99B8CD0DD52EB400FB1D6B /* close_code.h */; settings = {ATTRIBUTES = (Public, ); }; };
    1.12 @@ -247,6 +249,8 @@
    1.13  		1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
    1.14  		1D3623EB0D0F72F000981E51 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
    1.15  		1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
    1.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; };
    1.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; };
    1.18  		FD0BBFEF0E3933DD00D833B1 /* SDL_uikitview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitview.h; sourceTree = "<group>"; };
    1.19  		FD24846B0E5655AE0021E198 /* SDL_uikitkeyboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitkeyboard.h; sourceTree = "<group>"; };
    1.20  		FD3F4A700DEA620800C5B771 /* SDL_getenv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_getenv.c; sourceTree = "<group>"; };
    1.21 @@ -488,6 +492,23 @@
    1.22  			name = Frameworks;
    1.23  			sourceTree = "<group>";
    1.24  		};
    1.25 +		56ED04DE118A8E9A00A56AA6 /* power */ = {
    1.26 +			isa = PBXGroup;
    1.27 +			children = (
    1.28 +				56ED04E0118A8EE200A56AA6 /* SDL_power.c */,
    1.29 +				56ED04DF118A8EB700A56AA6 /* uikit */,
    1.30 +			);
    1.31 +			name = power;
    1.32 +			sourceTree = "<group>";
    1.33 +		};
    1.34 +		56ED04DF118A8EB700A56AA6 /* uikit */ = {
    1.35 +			isa = PBXGroup;
    1.36 +			children = (
    1.37 +				56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */,
    1.38 +			);
    1.39 +			name = uikit;
    1.40 +			sourceTree = "<group>";
    1.41 +		};
    1.42  		FD3F4A6F0DEA620800C5B771 /* stdlib */ = {
    1.43  			isa = PBXGroup;
    1.44  			children = (
    1.45 @@ -642,6 +663,7 @@
    1.46  				047677B60EA769DF008ABAF1 /* haptic */,
    1.47  				FD5F9D080E0E08B3008E885B /* joystick */,
    1.48  				FD8BD8150E27E25900B52CD5 /* loadso */,
    1.49 +				56ED04DE118A8E9A00A56AA6 /* power */,
    1.50  				FD3F4A6F0DEA620800C5B771 /* stdlib */,
    1.51  				FD99B9E00DD52EDC00FB1D6B /* thread */,
    1.52  				FD99BA1E0DD52EDC00FB1D6B /* timer */,
    1.53 @@ -1103,6 +1125,8 @@
    1.54  				043DD77110FD8A0000DED673 /* SDL_blendfillrect.c in Sources */,
    1.55  				043DD77210FD8A0000DED673 /* SDL_drawrect.c in Sources */,
    1.56  				04F2AF561104ABD200D6DDF7 /* SDL_assert.c in Sources */,
    1.57 +				56ED04E1118A8EE200A56AA6 /* SDL_power.c in Sources */,
    1.58 +				56ED04E3118A8EFD00A56AA6 /* SDL_syspower.m in Sources */,
    1.59  			);
    1.60  			runOnlyForDeploymentPostprocessing = 0;
    1.61  		};
     2.1 --- a/Xcode-iPhoneOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj	Thu Apr 29 22:53:18 2010 -0400
     2.2 +++ b/Xcode-iPhoneOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj	Fri Apr 30 00:39:31 2010 -0400
     2.3 @@ -7,6 +7,16 @@
     2.4  	objects = {
     2.5  
     2.6  /* Begin PBXBuildFile section */
     2.7 +		56ED04FE118A8FE400A56AA6 /* icon.bmp in Resources */ = {isa = PBXBuildFile; fileRef = FDA8AAD90E2D33B000EA573E /* icon.bmp */; };
     2.8 +		56ED0502118A8FE400A56AA6 /* libSDLiPhoneOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDLiPhoneOS.a */; };
     2.9 +		56ED0503118A8FE400A56AA6 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8980E2D111A00EA573E /* AudioToolbox.framework */; };
    2.10 +		56ED0504118A8FE400A56AA6 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8990E2D111A00EA573E /* QuartzCore.framework */; };
    2.11 +		56ED0505118A8FE400A56AA6 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89A0E2D111A00EA573E /* OpenGLES.framework */; };
    2.12 +		56ED0506118A8FE400A56AA6 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89B0E2D111A00EA573E /* CoreGraphics.framework */; };
    2.13 +		56ED0507118A8FE400A56AA6 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89C0E2D111A00EA573E /* UIKit.framework */; };
    2.14 +		56ED0508118A8FE400A56AA6 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89D0E2D111A00EA573E /* Foundation.framework */; };
    2.15 +		56ED0509118A8FE400A56AA6 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89E0E2D111A00EA573E /* CoreAudio.framework */; };
    2.16 +		56ED0511118A904200A56AA6 /* testpower.c in Sources */ = {isa = PBXBuildFile; fileRef = 56ED0510118A904200A56AA6 /* testpower.c */; };
    2.17  		FDA8A79B0E2D0F8B00EA573E /* common.c in Sources */ = {isa = PBXBuildFile; fileRef = FDA8A7840E2D0F1F00EA573E /* common.c */; };
    2.18  		FDA8A79C0E2D0F9300EA573E /* testwm2.c in Sources */ = {isa = PBXBuildFile; fileRef = FDA8A75F0E2D0F1600EA573E /* testwm2.c */; };
    2.19  		FDA8A89F0E2D111A00EA573E /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8980E2D111A00EA573E /* AudioToolbox.framework */; };
    2.20 @@ -288,6 +298,10 @@
    2.21  
    2.22  /* Begin PBXFileReference section */
    2.23  		1D6058910D05DD3D006BFB54 /* testwm2.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testwm2.app; sourceTree = BUILT_PRODUCTS_DIR; };
    2.24 +		56ED04F7118A8FCC00A56AA6 /* testpower-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "testpower-Info.plist"; sourceTree = "<group>"; };
    2.25 +		56ED050D118A8FE400A56AA6 /* testpower.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testpower.app; sourceTree = BUILT_PRODUCTS_DIR; };
    2.26 +		56ED050F118A8FE400A56AA6 /* Info copy.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info copy.plist"; sourceTree = "<group>"; };
    2.27 +		56ED0510118A904200A56AA6 /* testpower.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testpower.c; path = ../../test/testpower.c; sourceTree = SOURCE_ROOT; };
    2.28  		FD1B48AC0E3131CA007AB34E /* SDLiPhoneOS.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SDLiPhoneOS.xcodeproj; path = ../SDL/SDLiPhoneOS.xcodeproj; sourceTree = SOURCE_ROOT; };
    2.29  		FDA8A7400E2D0F1600EA573E /* testalpha.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testalpha.c; path = ../../test/testalpha.c; sourceTree = SOURCE_ROOT; };
    2.30  		FDA8A7410E2D0F1600EA573E /* testaudioinfo.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testaudioinfo.c; path = ../../test/testaudioinfo.c; sourceTree = SOURCE_ROOT; };
    2.31 @@ -386,6 +400,21 @@
    2.32  			);
    2.33  			runOnlyForDeploymentPostprocessing = 0;
    2.34  		};
    2.35 +		56ED0501118A8FE400A56AA6 /* Frameworks */ = {
    2.36 +			isa = PBXFrameworksBuildPhase;
    2.37 +			buildActionMask = 2147483647;
    2.38 +			files = (
    2.39 +				56ED0502118A8FE400A56AA6 /* libSDLiPhoneOS.a in Frameworks */,
    2.40 +				56ED0503118A8FE400A56AA6 /* AudioToolbox.framework in Frameworks */,
    2.41 +				56ED0504118A8FE400A56AA6 /* QuartzCore.framework in Frameworks */,
    2.42 +				56ED0505118A8FE400A56AA6 /* OpenGLES.framework in Frameworks */,
    2.43 +				56ED0506118A8FE400A56AA6 /* CoreGraphics.framework in Frameworks */,
    2.44 +				56ED0507118A8FE400A56AA6 /* UIKit.framework in Frameworks */,
    2.45 +				56ED0508118A8FE400A56AA6 /* Foundation.framework in Frameworks */,
    2.46 +				56ED0509118A8FE400A56AA6 /* CoreAudio.framework in Frameworks */,
    2.47 +			);
    2.48 +			runOnlyForDeploymentPostprocessing = 0;
    2.49 +		};
    2.50  		FDA8A9220E2D1C0B00EA573E /* Frameworks */ = {
    2.51  			isa = PBXFrameworksBuildPhase;
    2.52  			buildActionMask = 2147483647;
    2.53 @@ -824,6 +853,7 @@
    2.54  				FDD2C6B30E2E92D200B7A85F /* threadwin.app */,
    2.55  				FDD2C6F40E2E959E00B7A85F /* torturethread.app */,
    2.56  				FDC430000F0D866D009C87E1 /* torturethread.app */,
    2.57 +				56ED050D118A8FE400A56AA6 /* testpower.app */,
    2.58  			);
    2.59  			name = Products;
    2.60  			sourceTree = "<group>";
    2.61 @@ -831,11 +861,14 @@
    2.62  		29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
    2.63  			isa = PBXGroup;
    2.64  			children = (
    2.65 +				56ED0510118A904200A56AA6 /* testpower.c */,
    2.66  				FD1B48AC0E3131CA007AB34E /* SDLiPhoneOS.xcodeproj */,
    2.67  				FDA8AAD60E2D339A00EA573E /* Resources */,
    2.68  				FDA8A7C30E2D10FA00EA573E /* Linked Frameworks */,
    2.69  				FDA8A73B0E2D0F0400EA573E /* src */,
    2.70  				19C28FACFE9D520D11CA2CBB /* Products */,
    2.71 +				56ED04F7118A8FCC00A56AA6 /* testpower-Info.plist */,
    2.72 +				56ED050F118A8FE400A56AA6 /* Info copy.plist */,
    2.73  			);
    2.74  			name = CustomTemplate;
    2.75  			sourceTree = "<group>";
    2.76 @@ -941,6 +974,23 @@
    2.77  			productReference = 1D6058910D05DD3D006BFB54 /* testwm2.app */;
    2.78  			productType = "com.apple.product-type.application";
    2.79  		};
    2.80 +		56ED04FC118A8FE400A56AA6 /* testpower */ = {
    2.81 +			isa = PBXNativeTarget;
    2.82 +			buildConfigurationList = 56ED050A118A8FE400A56AA6 /* Build configuration list for PBXNativeTarget "testpower" */;
    2.83 +			buildPhases = (
    2.84 +				56ED04FD118A8FE400A56AA6 /* Resources */,
    2.85 +				56ED04FF118A8FE400A56AA6 /* Sources */,
    2.86 +				56ED0501118A8FE400A56AA6 /* Frameworks */,
    2.87 +			);
    2.88 +			buildRules = (
    2.89 +			);
    2.90 +			dependencies = (
    2.91 +			);
    2.92 +			name = testpower;
    2.93 +			productName = TestiPhoneOS;
    2.94 +			productReference = 56ED050D118A8FE400A56AA6 /* testpower.app */;
    2.95 +			productType = "com.apple.product-type.application";
    2.96 +		};
    2.97  		FDA8A91D0E2D1C0B00EA573E /* graywin */ = {
    2.98  			isa = PBXNativeTarget;
    2.99  			buildConfigurationList = FDA8A92C0E2D1C0B00EA573E /* Build configuration list for PBXNativeTarget "graywin" */;
   2.100 @@ -1437,6 +1487,7 @@
   2.101  				FDD2C46B0E2E77D700B7A85F /* testlock */,
   2.102  				FDD2C4A60E2E79C300B7A85F /* testpalette */,
   2.103  				FDD2C4F90E2E7F4800B7A85F /* testplatform */,
   2.104 +				56ED04FC118A8FE400A56AA6 /* testpower */,
   2.105  				FDD2C5170E2E807600B7A85F /* testsem */,
   2.106  				FDD2C53D0E2E80E400B7A85F /* testsprite2 */,
   2.107  				FDD2C5740E2E8C7400B7A85F /* testtimer */,
   2.108 @@ -1468,6 +1519,14 @@
   2.109  			);
   2.110  			runOnlyForDeploymentPostprocessing = 0;
   2.111  		};
   2.112 +		56ED04FD118A8FE400A56AA6 /* Resources */ = {
   2.113 +			isa = PBXResourcesBuildPhase;
   2.114 +			buildActionMask = 2147483647;
   2.115 +			files = (
   2.116 +				56ED04FE118A8FE400A56AA6 /* icon.bmp in Resources */,
   2.117 +			);
   2.118 +			runOnlyForDeploymentPostprocessing = 0;
   2.119 +		};
   2.120  		FDA8A91E0E2D1C0B00EA573E /* Resources */ = {
   2.121  			isa = PBXResourcesBuildPhase;
   2.122  			buildActionMask = 2147483647;
   2.123 @@ -1681,6 +1740,14 @@
   2.124  			);
   2.125  			runOnlyForDeploymentPostprocessing = 0;
   2.126  		};
   2.127 +		56ED04FF118A8FE400A56AA6 /* Sources */ = {
   2.128 +			isa = PBXSourcesBuildPhase;
   2.129 +			buildActionMask = 2147483647;
   2.130 +			files = (
   2.131 +				56ED0511118A904200A56AA6 /* testpower.c in Sources */,
   2.132 +			);
   2.133 +			runOnlyForDeploymentPostprocessing = 0;
   2.134 +		};
   2.135  		FDA8A91F0E2D1C0B00EA573E /* Sources */ = {
   2.136  			isa = PBXSourcesBuildPhase;
   2.137  			buildActionMask = 2147483647;
   2.138 @@ -1929,6 +1996,32 @@
   2.139  			};
   2.140  			name = Release;
   2.141  		};
   2.142 +		56ED050B118A8FE400A56AA6 /* Debug */ = {
   2.143 +			isa = XCBuildConfiguration;
   2.144 +			buildSettings = {
   2.145 +				ALWAYS_SEARCH_USER_PATHS = NO;
   2.146 +				COPY_PHASE_STRIP = NO;
   2.147 +				GCC_DYNAMIC_NO_PIC = NO;
   2.148 +				GCC_OPTIMIZATION_LEVEL = 0;
   2.149 +				GCC_PRECOMPILE_PREFIX_HEADER = YES;
   2.150 +				GCC_PREFIX_HEADER = "";
   2.151 +				INFOPLIST_FILE = "Info copy.plist";
   2.152 +				PRODUCT_NAME = testpower;
   2.153 +			};
   2.154 +			name = Debug;
   2.155 +		};
   2.156 +		56ED050C118A8FE400A56AA6 /* Release */ = {
   2.157 +			isa = XCBuildConfiguration;
   2.158 +			buildSettings = {
   2.159 +				ALWAYS_SEARCH_USER_PATHS = NO;
   2.160 +				COPY_PHASE_STRIP = YES;
   2.161 +				GCC_PRECOMPILE_PREFIX_HEADER = YES;
   2.162 +				GCC_PREFIX_HEADER = "";
   2.163 +				INFOPLIST_FILE = "Info copy.plist";
   2.164 +				PRODUCT_NAME = testpower;
   2.165 +			};
   2.166 +			name = Release;
   2.167 +		};
   2.168  		C01FCF4F08A954540054247B /* Debug */ = {
   2.169  			isa = XCBuildConfiguration;
   2.170  			buildSettings = {
   2.171 @@ -2674,6 +2767,15 @@
   2.172  			defaultConfigurationIsVisible = 0;
   2.173  			defaultConfigurationName = Release;
   2.174  		};
   2.175 +		56ED050A118A8FE400A56AA6 /* Build configuration list for PBXNativeTarget "testpower" */ = {
   2.176 +			isa = XCConfigurationList;
   2.177 +			buildConfigurations = (
   2.178 +				56ED050B118A8FE400A56AA6 /* Debug */,
   2.179 +				56ED050C118A8FE400A56AA6 /* Release */,
   2.180 +			);
   2.181 +			defaultConfigurationIsVisible = 0;
   2.182 +			defaultConfigurationName = Release;
   2.183 +		};
   2.184  		C01FCF4E08A954540054247B /* Build configuration list for PBXProject "TestiPhoneOS" */ = {
   2.185  			isa = XCConfigurationList;
   2.186  			buildConfigurations = (
     3.1 --- a/include/SDL_config_iphoneos.h	Thu Apr 29 22:53:18 2010 -0400
     3.2 +++ b/include/SDL_config_iphoneos.h	Fri Apr 30 00:39:31 2010 -0400
     3.3 @@ -142,7 +142,7 @@
     3.4  #define SDL_VIDEO_RENDER_OGL_ES	1
     3.5  
     3.6  /* Enable system power support */
     3.7 -#define SDL_POWER_MACOSX 1
     3.8 +#define SDL_POWER_UIKIT 1
     3.9  
    3.10  /* enable iPhone keyboard support */
    3.11  #define SDL_IPHONE_KEYBOARD 0
     4.1 --- a/src/power/SDL_power.c	Thu Apr 29 22:53:18 2010 -0400
     4.2 +++ b/src/power/SDL_power.c	Fri Apr 30 00:39:31 2010 -0400
     4.3 @@ -36,6 +36,7 @@
     4.4  SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState *, int *, int *);
     4.5  SDL_bool SDL_GetPowerInfo_BeOS(SDL_PowerState *, int *, int *);
     4.6  SDL_bool SDL_GetPowerInfo_NintendoDS(SDL_PowerState *, int *, int *);
     4.7 +SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *, int *, int *);
     4.8  
     4.9  #ifndef SDL_POWER_DISABLED
    4.10  #ifdef SDL_POWER_HARDWIRED
    4.11 @@ -61,7 +62,10 @@
    4.12  #ifdef SDL_POWER_WINDOWS        /* handles Win32, Win64, PocketPC. */
    4.13      SDL_GetPowerInfo_Windows,
    4.14  #endif
    4.15 -#ifdef SDL_POWER_MACOSX         /* handles Mac OS X, Darwin, iPhone. */
    4.16 +#ifdef SDL_POWER_UIKIT          /* handles iPhone/iPad/etc */
    4.17 +    SDL_GetPowerInfo_UIKit,
    4.18 +#endif
    4.19 +#ifdef SDL_POWER_MACOSX         /* handles Mac OS X, Darwin. */
    4.20      SDL_GetPowerInfo_MacOSX,
    4.21  #endif
    4.22  #ifdef SDL_POWER_NINTENDODS     /* handles Nintendo DS. */
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/power/uikit/SDL_syspower.m	Fri Apr 30 00:39:31 2010 -0400
     5.3 @@ -0,0 +1,100 @@
     5.4 +/*
     5.5 +    SDL - Simple DirectMedia Layer
     5.6 +    Copyright (C) 1997-2010 Sam Lantinga
     5.7 +
     5.8 +    This library is free software; you can redistribute it and/or
     5.9 +    modify it under the terms of the GNU Lesser General Public
    5.10 +    License as published by the Free Software Foundation; either
    5.11 +    version 2.1 of the License, or (at your option) any later version.
    5.12 +
    5.13 +    This library is distributed in the hope that it will be useful,
    5.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.16 +    Lesser General Public License for more details.
    5.17 +
    5.18 +    You should have received a copy of the GNU Lesser General Public
    5.19 +    License along with this library; if not, write to the Free Software
    5.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    5.21 +
    5.22 +    Sam Lantinga
    5.23 +    slouken@libsdl.org
    5.24 +*/
    5.25 +#include "SDL_config.h"
    5.26 +
    5.27 +#ifndef SDL_POWER_DISABLED
    5.28 +#ifdef SDL_POWER_UIKIT
    5.29 +
    5.30 +#import <UIKit/UIKit.h>
    5.31 +
    5.32 +#include "SDL_power.h"
    5.33 +#include "SDL_timer.h"
    5.34 +#include "SDL_assert.h"
    5.35 +
    5.36 +// turn off the battery monitor if it's been more than X ms since last check.
    5.37 +static const int BATTERY_MONITORING_TIMEOUT = 3000;
    5.38 +static Uint32 SDL_UIKitLastPowerInfoQuery = 0;
    5.39 +
    5.40 +void
    5.41 +SDL_UIKit_UpdateBatteryMonitoring(void)
    5.42 +{
    5.43 +    if (SDL_UIKitLastPowerInfoQuery) {
    5.44 +        const Uint32 prev = SDL_UIKitLastPowerInfoQuery;
    5.45 +        const UInt32 now = SDL_GetTicks();
    5.46 +        const UInt32 ticks = now - prev;
    5.47 +        // if timer wrapped (now < prev), shut down, too.
    5.48 +        if ((now < prev) || (ticks >= BATTERY_MONITORING_TIMEOUT)) {
    5.49 +            UIDevice *uidev = [UIDevice currentDevice];
    5.50 +            SDL_assert([uidev isBatteryMonitoringEnabled] == YES);
    5.51 +            [uidev setBatteryMonitoringEnabled:NO];
    5.52 +            SDL_UIKitLastPowerInfoQuery = 0;
    5.53 +        }
    5.54 +    }
    5.55 +}
    5.56 +
    5.57 +SDL_bool
    5.58 +SDL_GetPowerInfo_UIKit(SDL_PowerState * state, int *seconds, int *percent)
    5.59 +{
    5.60 +    UIDevice *uidev = [UIDevice currentDevice];
    5.61 +
    5.62 +    if (!SDL_UIKitLastPowerInfoQuery) {
    5.63 +        SDL_assert([uidev isBatteryMonitoringEnabled] == NO);
    5.64 +        [uidev setBatteryMonitoringEnabled:YES];
    5.65 +    }
    5.66 +
    5.67 +    // UIKit_GL_SwapWindow() (etc) will check this and disable the battery
    5.68 +    //  monitoring if the app hasn't queried it in the last X seconds.
    5.69 +    //  Apparently monitoring the battery burns battery life.  :)
    5.70 +    //  Apple's docs say not to monitor the battery unless you need it.
    5.71 +    SDL_UIKitLastPowerInfoQuery = SDL_GetTicks();
    5.72 +
    5.73 +    *seconds = -1;   // no API to estimate this in UIKit.
    5.74 +
    5.75 +    switch ([uidev batteryState])
    5.76 +    {
    5.77 +        case UIDeviceBatteryStateCharging:
    5.78 +            *state = SDL_POWERSTATE_CHARGING;
    5.79 +            break;
    5.80 +
    5.81 +        case UIDeviceBatteryStateFull:
    5.82 +            *state = SDL_POWERSTATE_CHARGED;
    5.83 +            break;
    5.84 +
    5.85 +        case UIDeviceBatteryStateUnplugged:
    5.86 +            *state = SDL_POWERSTATE_ON_BATTERY;
    5.87 +            break;
    5.88 +
    5.89 +        case UIDeviceBatteryStateUnknown:
    5.90 +        default:
    5.91 +            *state = SDL_POWERSTATE_UNKNOWN;
    5.92 +            break;
    5.93 +    }
    5.94 +
    5.95 +    const float level = [uidev batteryLevel];
    5.96 +    *percent = ( (level < 0.0f) ? -1 : (((int) (level + 0.5f)) * 100) );
    5.97 +    return SDL_TRUE;            /* always the definitive answer on iPhoneOS. */
    5.98 +}
    5.99 +
   5.100 +#endif /* SDL_POWER_UIKIT */
   5.101 +#endif /* SDL_POWER_DISABLED */
   5.102 +
   5.103 +/* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/video/uikit/SDL_uikitopengles.m	Thu Apr 29 22:53:18 2010 -0400
     6.2 +++ b/src/video/uikit/SDL_uikitopengles.m	Fri Apr 30 00:39:31 2010 -0400
     6.3 @@ -73,9 +73,14 @@
     6.4      return 0;
     6.5  }
     6.6  
     6.7 +extern void SDL_UIKit_UpdateBatteryMonitoring(void);
     6.8  
     6.9  void UIKit_GL_SwapWindow(_THIS, SDL_Window * window)
    6.10  {
    6.11 +    #ifdef SDL_POWER_UIKIT
    6.12 +    // Check once a frame to see if we should turn off the battery monitor.
    6.13 +    SDL_UIKit_UpdateBatteryMonitoring();
    6.14 +    #endif
    6.15  
    6.16  	SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
    6.17