23 #ifndef SDL_POWER_DISABLED
26 #include <Carbon/Carbon.h>
27 #include <IOKit/ps/IOPowerSources.h>
28 #include <IOKit/ps/IOPSKeys.h>
33 #define STRMATCH(a,b) (CFStringCompare(a, b, 0) == kCFCompareEqualTo)
35 CFDictionaryGetValueIfPresent(dict, CFSTR(k), (const void **) v)
40 SDL_bool * charging,
int *seconds,
int *percent)
52 if ((GETVAL(kIOPSIsPresentKey, &bval)) && (bval == kCFBooleanFalse)) {
56 if (!GETVAL(kIOPSPowerSourceStateKey, &strval)) {
60 if (STRMATCH(strval, CFSTR(kIOPSACPowerValue))) {
62 }
else if (!STRMATCH(strval, CFSTR(kIOPSBatteryPowerValue))) {
66 if ((GETVAL(kIOPSIsChargingKey, &bval)) && (bval == kCFBooleanTrue)) {
70 if (GETVAL(kIOPSMaxCapacityKey, &numval)) {
72 CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
79 if (GETVAL(kIOPSMaxCapacityKey, &numval)) {
81 CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
88 if (GETVAL(kIOPSTimeToEmptyKey, &numval)) {
90 CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
93 if ((val == 0) && (is_ac)) {
103 if (GETVAL(kIOPSCurrentCapacityKey, &numval)) {
105 CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
109 if ((pct > 0) && (maxpct > 0)) {
110 pct = (
int) ((((
double) pct) / ((
double) maxpct)) * 100.0);
121 if ((secs < 0) && (*seconds < 0)) {
122 if ((pct < 0) && (*percent < 0)) {
125 if (pct > *percent) {
128 }
else if (secs > *seconds) {
146 CFTypeRef blob = IOPSCopyPowerSourcesInfo();
153 CFArrayRef list = IOPSCopyPowerSourcesList(blob);
159 const CFIndex total = CFArrayGetCount(list);
161 for (i = 0; i < total; i++) {
162 CFTypeRef ps = (CFTypeRef) CFArrayGetValueAtIndex(list, i);
163 CFDictionaryRef dict =
164 IOPSGetPowerSourceDescription(blob, ps);
166 checkps(dict, &have_ac, &have_battery, &charging,
173 }
else if (charging) {
175 }
else if (have_ac) {
GLuint const GLfloat * val
SDL_PowerState
The basic state for the system's power supply.
SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState *, int *, int *)