Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
This commit is contained in:
@@ -30,7 +30,7 @@ typedef SDL_bool (*SDL_GetPowerInfo_Impl)(SDL_PowerState *state, int *seconds,
|
||||
|
||||
#ifndef SDL_POWER_DISABLED
|
||||
#ifdef SDL_POWER_HARDWIRED
|
||||
/* This is for things that _never_ have a battery */
|
||||
// This is for things that _never_ have a battery
|
||||
static SDL_bool SDL_GetPowerInfo_Hardwired(SDL_PowerState *state, int *seconds, int *percent)
|
||||
{
|
||||
*seconds = -1;
|
||||
@@ -41,40 +41,40 @@ static SDL_bool SDL_GetPowerInfo_Hardwired(SDL_PowerState *state, int *seconds,
|
||||
#endif
|
||||
|
||||
static SDL_GetPowerInfo_Impl implementations[] = {
|
||||
#ifdef SDL_POWER_LINUX /* in order of preference. More than could work. */
|
||||
#ifdef SDL_POWER_LINUX // in order of preference. More than could work.
|
||||
SDL_GetPowerInfo_Linux_org_freedesktop_upower,
|
||||
SDL_GetPowerInfo_Linux_sys_class_power_supply,
|
||||
SDL_GetPowerInfo_Linux_proc_acpi,
|
||||
SDL_GetPowerInfo_Linux_proc_apm,
|
||||
#endif
|
||||
#ifdef SDL_POWER_WINDOWS /* handles Win32, Win64, PocketPC. */
|
||||
#ifdef SDL_POWER_WINDOWS // handles Win32, Win64, PocketPC.
|
||||
SDL_GetPowerInfo_Windows,
|
||||
#endif
|
||||
#ifdef SDL_POWER_UIKIT /* handles iPhone/iPad/etc */
|
||||
#ifdef SDL_POWER_UIKIT // handles iPhone/iPad/etc
|
||||
SDL_GetPowerInfo_UIKit,
|
||||
#endif
|
||||
#ifdef SDL_POWER_MACOSX /* handles macOS, Darwin. */
|
||||
#ifdef SDL_POWER_MACOSX // handles macOS, Darwin.
|
||||
SDL_GetPowerInfo_MacOSX,
|
||||
#endif
|
||||
#ifdef SDL_POWER_HAIKU /* with BeOS euc.jp apm driver. Does this work on Haiku? */
|
||||
#ifdef SDL_POWER_HAIKU // with BeOS euc.jp apm driver. Does this work on Haiku?
|
||||
SDL_GetPowerInfo_Haiku,
|
||||
#endif
|
||||
#ifdef SDL_POWER_ANDROID /* handles Android. */
|
||||
#ifdef SDL_POWER_ANDROID // handles Android.
|
||||
SDL_GetPowerInfo_Android,
|
||||
#endif
|
||||
#ifdef SDL_POWER_PSP /* handles PSP. */
|
||||
#ifdef SDL_POWER_PSP // handles PSP.
|
||||
SDL_GetPowerInfo_PSP,
|
||||
#endif
|
||||
#ifdef SDL_POWER_VITA /* handles PSVita. */
|
||||
#ifdef SDL_POWER_VITA // handles PSVita.
|
||||
SDL_GetPowerInfo_VITA,
|
||||
#endif
|
||||
#ifdef SDL_POWER_N3DS /* handles N3DS. */
|
||||
#ifdef SDL_POWER_N3DS // handles N3DS.
|
||||
SDL_GetPowerInfo_N3DS,
|
||||
#endif
|
||||
#ifdef SDL_POWER_WINRT /* handles WinRT */
|
||||
#ifdef SDL_POWER_WINRT // handles WinRT
|
||||
SDL_GetPowerInfo_WinRT,
|
||||
#endif
|
||||
#ifdef SDL_POWER_EMSCRIPTEN /* handles Emscripten */
|
||||
#ifdef SDL_POWER_EMSCRIPTEN // handles Emscripten
|
||||
SDL_GetPowerInfo_Emscripten,
|
||||
#endif
|
||||
|
||||
@@ -93,7 +93,7 @@ SDL_PowerState SDL_GetPowerInfo(int *seconds, int *percent)
|
||||
#endif
|
||||
|
||||
int _seconds, _percent;
|
||||
/* Make these never NULL for platform-specific implementations. */
|
||||
// Make these never NULL for platform-specific implementations.
|
||||
if (!seconds) {
|
||||
seconds = &_seconds;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ SDL_PowerState SDL_GetPowerInfo(int *seconds, int *percent)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* nothing was definitive. */
|
||||
// nothing was definitive.
|
||||
*seconds = -1;
|
||||
*percent = -1;
|
||||
return SDL_POWERSTATE_UNKNOWN;
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
/* These are functions that need to be implemented by a port of SDL */
|
||||
// These are functions that need to be implemented by a port of SDL
|
||||
|
||||
#ifndef SDL_syspower_h_
|
||||
#define SDL_syspower_h_
|
||||
|
||||
/* Not all of these are available in a given build. Use #ifdefs, etc. */
|
||||
// Not all of these are available in a given build. Use #ifdefs, etc.
|
||||
SDL_bool SDL_GetPowerInfo_Linux_org_freedesktop_upower(SDL_PowerState *, int *, int *);
|
||||
SDL_bool SDL_GetPowerInfo_Linux_sys_class_power_supply(SDL_PowerState *, int *, int *);
|
||||
SDL_bool SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState *, int *, int *);
|
||||
@@ -41,7 +41,7 @@ SDL_bool SDL_GetPowerInfo_N3DS(SDL_PowerState *, int *, int *);
|
||||
SDL_bool SDL_GetPowerInfo_WinRT(SDL_PowerState *, int *, int *);
|
||||
SDL_bool SDL_GetPowerInfo_Emscripten(SDL_PowerState *, int *, int *);
|
||||
|
||||
/* this one is static in SDL_power.c */
|
||||
// this one is static in SDL_power.c
|
||||
/* SDL_bool SDL_GetPowerInfo_Hardwired(SDL_PowerState *, int *, int *);*/
|
||||
|
||||
#endif /* SDL_syspower_h_ */
|
||||
#endif // SDL_syspower_h_
|
||||
|
||||
@@ -56,5 +56,5 @@ SDL_bool SDL_GetPowerInfo_Android(SDL_PowerState *state, int *seconds, int *perc
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
#endif /* SDL_POWER_ANDROID */
|
||||
#endif /* SDL_POWER_DISABLED */
|
||||
#endif // SDL_POWER_ANDROID
|
||||
#endif // SDL_POWER_DISABLED
|
||||
|
||||
@@ -55,5 +55,5 @@ SDL_bool SDL_GetPowerInfo_Emscripten(SDL_PowerState *state, int *seconds, int *p
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
#endif /* SDL_POWER_EMSCRIPTEN */
|
||||
#endif /* SDL_POWER_DISABLED */
|
||||
#endif // SDL_POWER_EMSCRIPTEN
|
||||
#endif // SDL_POWER_DISABLED
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
/* uses BeOS euc.jp apm driver. */
|
||||
/* !!! FIXME: does this thing even work on Haiku? */
|
||||
// uses BeOS euc.jp apm driver.
|
||||
// !!! FIXME: does this thing even work on Haiku?
|
||||
|
||||
#ifndef SDL_POWER_DISABLED
|
||||
#ifdef SDL_POWER_HAIKU
|
||||
@@ -33,7 +33,7 @@
|
||||
#include <ctype.h>
|
||||
#include <drivers/Drivers.h>
|
||||
|
||||
/* These values are from apm.h ... */
|
||||
// These values are from apm.h ...
|
||||
#define APM_DEVICE_PATH "/dev/misc/apm"
|
||||
#define APM_FUNC_OFFSET 0x5300
|
||||
#define APM_FUNC_GET_POWER_STATUS 10
|
||||
@@ -53,7 +53,7 @@ SDL_bool SDL_GetPowerInfo_Haiku(SDL_PowerState *state, int *seconds, int *percen
|
||||
int rc;
|
||||
|
||||
if (fd == -1) {
|
||||
return SDL_FALSE; /* maybe some other method will work? */
|
||||
return SDL_FALSE; // maybe some other method will work?
|
||||
}
|
||||
|
||||
SDL_memset(regs, '\0', sizeof(regs));
|
||||
@@ -72,8 +72,8 @@ SDL_bool SDL_GetPowerInfo_Haiku(SDL_PowerState *state, int *seconds, int *percen
|
||||
battery_life = regs[2] & 0xFF;
|
||||
battery_time = (uint32)regs[3];
|
||||
|
||||
/* in theory, _something_ should be set in battery_flags, right? */
|
||||
if (battery_flags == 0x00) { /* older APM BIOS? Less fields. */
|
||||
// in theory, _something_ should be set in battery_flags, right?
|
||||
if (battery_flags == 0x00) { // older APM BIOS? Less fields.
|
||||
battery_time = 0xFFFF;
|
||||
if (battery_status == 0xFF) {
|
||||
battery_flags = 0xFF;
|
||||
@@ -83,22 +83,22 @@ SDL_bool SDL_GetPowerInfo_Haiku(SDL_PowerState *state, int *seconds, int *percen
|
||||
}
|
||||
|
||||
if ((battery_time != 0xFFFF) && (battery_time & (1 << 15))) {
|
||||
/* time is in minutes, not seconds */
|
||||
// time is in minutes, not seconds
|
||||
battery_time = (battery_time & 0x7FFF) * 60;
|
||||
}
|
||||
|
||||
if (battery_flags == 0xFF) { /* unknown state */
|
||||
if (battery_flags == 0xFF) { // unknown state
|
||||
*state = SDL_POWERSTATE_UNKNOWN;
|
||||
} else if (battery_flags & (1 << 7)) { /* no battery */
|
||||
} else if (battery_flags & (1 << 7)) { // no battery
|
||||
*state = SDL_POWERSTATE_NO_BATTERY;
|
||||
} else if (battery_flags & (1 << 3)) { /* charging */
|
||||
} else if (battery_flags & (1 << 3)) { // charging
|
||||
*state = SDL_POWERSTATE_CHARGING;
|
||||
need_details = SDL_TRUE;
|
||||
} else if (ac_status == 1) {
|
||||
*state = SDL_POWERSTATE_CHARGED; /* on AC, not charging. */
|
||||
*state = SDL_POWERSTATE_CHARGED; // on AC, not charging.
|
||||
need_details = SDL_TRUE;
|
||||
} else {
|
||||
*state = SDL_POWERSTATE_ON_BATTERY; /* not on AC. */
|
||||
*state = SDL_POWERSTATE_ON_BATTERY; // not on AC.
|
||||
need_details = SDL_TRUE;
|
||||
}
|
||||
|
||||
@@ -108,16 +108,16 @@ SDL_bool SDL_GetPowerInfo_Haiku(SDL_PowerState *state, int *seconds, int *percen
|
||||
const int pct = (int)battery_life;
|
||||
const int secs = (int)battery_time;
|
||||
|
||||
if (pct != 255) { /* 255 == unknown */
|
||||
*percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
|
||||
if (pct != 255) { // 255 == unknown
|
||||
*percent = (pct > 100) ? 100 : pct; // clamp between 0%, 100%
|
||||
}
|
||||
if (secs != 0xFFFF) { /* 0xFFFF == unknown */
|
||||
if (secs != 0xFFFF) { // 0xFFFF == unknown
|
||||
*seconds = secs;
|
||||
}
|
||||
}
|
||||
|
||||
return SDL_TRUE; /* the definitive answer if APM driver replied. */
|
||||
return SDL_TRUE; // the definitive answer if APM driver replied.
|
||||
}
|
||||
|
||||
#endif /* SDL_POWER_HAIKU */
|
||||
#endif /* SDL_POWER_DISABLED */
|
||||
#endif // SDL_POWER_HAIKU
|
||||
#endif // SDL_POWER_DISABLED
|
||||
|
||||
@@ -46,7 +46,7 @@ static int open_power_file(const char *base, const char *node, const char *key)
|
||||
const size_t pathlen = SDL_strlen(base) + SDL_strlen(node) + SDL_strlen(key) + 3;
|
||||
char *path = SDL_stack_alloc(char, pathlen);
|
||||
if (!path) {
|
||||
return -1; /* oh well. */
|
||||
return -1; // oh well.
|
||||
}
|
||||
|
||||
(void)SDL_snprintf(path, pathlen, "%s/%s/%s", base, node, key);
|
||||
@@ -68,7 +68,7 @@ static SDL_bool read_power_file(const char *base, const char *node, const char *
|
||||
if (br < 0) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
buf[br] = '\0'; /* null-terminate the string. */
|
||||
buf[br] = '\0'; // null-terminate the string.
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
@@ -77,11 +77,11 @@ static SDL_bool make_proc_acpi_key_val(char **_ptr, char **_key, char **_val)
|
||||
char *ptr = *_ptr;
|
||||
|
||||
while (*ptr == ' ') {
|
||||
ptr++; /* skip whitespace. */
|
||||
ptr++; // skip whitespace.
|
||||
}
|
||||
|
||||
if (*ptr == '\0') {
|
||||
return SDL_FALSE; /* EOF. */
|
||||
return SDL_FALSE; // EOF.
|
||||
}
|
||||
|
||||
*_key = ptr;
|
||||
@@ -91,17 +91,17 @@ static SDL_bool make_proc_acpi_key_val(char **_ptr, char **_key, char **_val)
|
||||
}
|
||||
|
||||
if (*ptr == '\0') {
|
||||
return SDL_FALSE; /* (unexpected) EOF. */
|
||||
return SDL_FALSE; // (unexpected) EOF.
|
||||
}
|
||||
|
||||
*(ptr++) = '\0'; /* terminate the key. */
|
||||
*(ptr++) = '\0'; // terminate the key.
|
||||
|
||||
while (*ptr == ' ') {
|
||||
ptr++; /* skip whitespace. */
|
||||
ptr++; // skip whitespace.
|
||||
}
|
||||
|
||||
if (*ptr == '\0') {
|
||||
return SDL_FALSE; /* (unexpected) EOF. */
|
||||
return SDL_FALSE; // (unexpected) EOF.
|
||||
}
|
||||
|
||||
*_val = ptr;
|
||||
@@ -111,10 +111,10 @@ static SDL_bool make_proc_acpi_key_val(char **_ptr, char **_key, char **_val)
|
||||
}
|
||||
|
||||
if (*ptr != '\0') {
|
||||
*(ptr++) = '\0'; /* terminate the value. */
|
||||
*(ptr++) = '\0'; // terminate the value.
|
||||
}
|
||||
|
||||
*_ptr = ptr; /* store for next time. */
|
||||
*_ptr = ptr; // store for next time.
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ static void check_proc_acpi_battery(const char *node, SDL_bool *have_battery,
|
||||
*have_battery = SDL_TRUE;
|
||||
}
|
||||
} else if (SDL_strcasecmp(key, "charging state") == 0) {
|
||||
/* !!! FIXME: what exactly _does_ charging/discharging mean? */
|
||||
// !!! FIXME: what exactly _does_ charging/discharging mean?
|
||||
if (SDL_strcasecmp(val, "charging/discharging") == 0) {
|
||||
charge = SDL_TRUE;
|
||||
} else if (SDL_strcasecmp(val, "charging") == 0) {
|
||||
@@ -182,7 +182,7 @@ static void check_proc_acpi_battery(const char *node, SDL_bool *have_battery,
|
||||
}
|
||||
}
|
||||
|
||||
/* !!! FIXME: calculate (secs). */
|
||||
// !!! FIXME: calculate (secs).
|
||||
|
||||
/*
|
||||
* We pick the battery that claims to have the most minutes left.
|
||||
@@ -190,7 +190,7 @@ static void check_proc_acpi_battery(const char *node, SDL_bool *have_battery,
|
||||
*/
|
||||
if ((secs < 0) && (*seconds < 0)) {
|
||||
if ((pct < 0) && (*percent < 0)) {
|
||||
choose = SDL_TRUE; /* at least we know there's a battery. */
|
||||
choose = SDL_TRUE; // at least we know there's a battery.
|
||||
}
|
||||
if (pct > *percent) {
|
||||
choose = SDL_TRUE;
|
||||
@@ -242,7 +242,7 @@ SDL_bool SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState *state, int *seconds, i
|
||||
|
||||
dirp = opendir(proc_acpi_battery_path);
|
||||
if (!dirp) {
|
||||
return SDL_FALSE; /* can't use this interface. */
|
||||
return SDL_FALSE; // can't use this interface.
|
||||
} else {
|
||||
while ((dent = readdir(dirp)) != NULL) {
|
||||
const char *node = dent->d_name;
|
||||
@@ -254,7 +254,7 @@ SDL_bool SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState *state, int *seconds, i
|
||||
|
||||
dirp = opendir(proc_acpi_ac_adapter_path);
|
||||
if (!dirp) {
|
||||
return SDL_FALSE; /* can't use this interface. */
|
||||
return SDL_FALSE; // can't use this interface.
|
||||
} else {
|
||||
while ((dent = readdir(dirp)) != NULL) {
|
||||
const char *node = dent->d_name;
|
||||
@@ -273,7 +273,7 @@ SDL_bool SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState *state, int *seconds, i
|
||||
*state = SDL_POWERSTATE_ON_BATTERY;
|
||||
}
|
||||
|
||||
return SDL_TRUE; /* definitive answer. */
|
||||
return SDL_TRUE; // definitive answer.
|
||||
}
|
||||
|
||||
static SDL_bool next_string(char **_ptr, char **_str)
|
||||
@@ -281,7 +281,7 @@ static SDL_bool next_string(char **_ptr, char **_str)
|
||||
char *ptr = *_ptr;
|
||||
char *str;
|
||||
|
||||
while (*ptr == ' ') { /* skip any spaces... */
|
||||
while (*ptr == ' ') { // skip any spaces...
|
||||
ptr++;
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ static SDL_bool int_string(char *str, int *val)
|
||||
return (*str != '\0') && (*endptr == '\0');
|
||||
}
|
||||
|
||||
/* http://lxr.linux.no/linux+v2.6.29/drivers/char/apm-emulation.c */
|
||||
// http://lxr.linux.no/linux+v2.6.29/drivers/char/apm-emulation.c
|
||||
SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *state, int *seconds, int *percent)
|
||||
{
|
||||
SDL_bool need_details = SDL_FALSE;
|
||||
@@ -326,7 +326,7 @@ SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *state, int *seconds, in
|
||||
ssize_t br;
|
||||
|
||||
if (fd == -1) {
|
||||
return SDL_FALSE; /* can't use this interface. */
|
||||
return SDL_FALSE; // can't use this interface.
|
||||
}
|
||||
|
||||
br = read(fd, buf, sizeof(buf) - 1);
|
||||
@@ -336,34 +336,34 @@ SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *state, int *seconds, in
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
buf[br] = '\0'; /* null-terminate the string. */
|
||||
if (!next_string(&ptr, &str)) { /* driver version */
|
||||
buf[br] = '\0'; // null-terminate the string.
|
||||
if (!next_string(&ptr, &str)) { // driver version
|
||||
return SDL_FALSE;
|
||||
}
|
||||
if (!next_string(&ptr, &str)) { /* BIOS version */
|
||||
if (!next_string(&ptr, &str)) { // BIOS version
|
||||
return SDL_FALSE;
|
||||
}
|
||||
if (!next_string(&ptr, &str)) { /* APM flags */
|
||||
if (!next_string(&ptr, &str)) { // APM flags
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
if (!next_string(&ptr, &str)) { /* AC line status */
|
||||
if (!next_string(&ptr, &str)) { // AC line status
|
||||
return SDL_FALSE;
|
||||
} else if (!int_string(str, &ac_status)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
if (!next_string(&ptr, &str)) { /* battery status */
|
||||
if (!next_string(&ptr, &str)) { // battery status
|
||||
return SDL_FALSE;
|
||||
} else if (!int_string(str, &battery_status)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
if (!next_string(&ptr, &str)) { /* battery flag */
|
||||
if (!next_string(&ptr, &str)) { // battery flag
|
||||
return SDL_FALSE;
|
||||
} else if (!int_string(str, &battery_flag)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
if (!next_string(&ptr, &str)) { /* remaining battery life percent */
|
||||
if (!next_string(&ptr, &str)) { // remaining battery life percent
|
||||
return SDL_FALSE;
|
||||
}
|
||||
if (str[SDL_strlen(str) - 1] == '%') {
|
||||
@@ -373,27 +373,27 @@ SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *state, int *seconds, in
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
if (!next_string(&ptr, &str)) { /* remaining battery life time */
|
||||
if (!next_string(&ptr, &str)) { // remaining battery life time
|
||||
return SDL_FALSE;
|
||||
} else if (!int_string(str, &battery_time)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
if (!next_string(&ptr, &str)) { /* remaining battery life time units */
|
||||
if (!next_string(&ptr, &str)) { // remaining battery life time units
|
||||
return SDL_FALSE;
|
||||
} else if (SDL_strcasecmp(str, "min") == 0) {
|
||||
battery_time *= 60;
|
||||
}
|
||||
|
||||
if (battery_flag == 0xFF) { /* unknown state */
|
||||
if (battery_flag == 0xFF) { // unknown state
|
||||
*state = SDL_POWERSTATE_UNKNOWN;
|
||||
} else if (battery_flag & (1 << 7)) { /* no battery */
|
||||
} else if (battery_flag & (1 << 7)) { // no battery
|
||||
*state = SDL_POWERSTATE_NO_BATTERY;
|
||||
} else if (battery_flag & (1 << 3)) { /* charging */
|
||||
} else if (battery_flag & (1 << 3)) { // charging
|
||||
*state = SDL_POWERSTATE_CHARGING;
|
||||
need_details = SDL_TRUE;
|
||||
} else if (ac_status == 1) {
|
||||
*state = SDL_POWERSTATE_CHARGED; /* on AC, not charging. */
|
||||
*state = SDL_POWERSTATE_CHARGED; // on AC, not charging.
|
||||
need_details = SDL_TRUE;
|
||||
} else {
|
||||
*state = SDL_POWERSTATE_ON_BATTERY;
|
||||
@@ -406,10 +406,10 @@ SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *state, int *seconds, in
|
||||
const int pct = battery_percent;
|
||||
const int secs = battery_time;
|
||||
|
||||
if (pct >= 0) { /* -1 == unknown */
|
||||
*percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
|
||||
if (pct >= 0) { // -1 == unknown
|
||||
*percent = (pct > 100) ? 100 : pct; // clamp between 0%, 100%
|
||||
}
|
||||
if (secs >= 0) { /* -1 == unknown */
|
||||
if (secs >= 0) { // -1 == unknown
|
||||
*seconds = secs;
|
||||
}
|
||||
}
|
||||
@@ -428,7 +428,7 @@ SDL_bool SDL_GetPowerInfo_Linux_sys_class_power_supply(SDL_PowerState *state, in
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
*state = SDL_POWERSTATE_NO_BATTERY; /* assume we're just plugged in. */
|
||||
*state = SDL_POWERSTATE_NO_BATTERY; // assume we're just plugged in.
|
||||
*seconds = -1;
|
||||
*percent = -1;
|
||||
|
||||
@@ -443,11 +443,11 @@ SDL_bool SDL_GetPowerInfo_Linux_sys_class_power_supply(SDL_PowerState *state, in
|
||||
int power;
|
||||
|
||||
if ((SDL_strcmp(name, ".") == 0) || (SDL_strcmp(name, "..") == 0)) {
|
||||
continue; /* skip these, of course. */
|
||||
continue; // skip these, of course.
|
||||
} else if (!read_power_file(base, name, "type", str, sizeof(str))) {
|
||||
continue; /* Don't know _what_ we're looking at. Give up on it. */
|
||||
continue; // Don't know _what_ we're looking at. Give up on it.
|
||||
} else if (SDL_strcasecmp(str, "Battery\n") != 0) {
|
||||
continue; /* we don't care about UPS and such. */
|
||||
continue; // we don't care about UPS and such.
|
||||
}
|
||||
|
||||
/* if the scope is "device," it might be something like a PS4
|
||||
@@ -456,15 +456,15 @@ SDL_bool SDL_GetPowerInfo_Linux_sys_class_power_supply(SDL_PowerState *state, in
|
||||
assume it's a system battery if not specified. */
|
||||
if (read_power_file(base, name, "scope", str, sizeof(str))) {
|
||||
if (SDL_strcasecmp(str, "Device\n") == 0) {
|
||||
continue; /* skip external devices with their own batteries. */
|
||||
continue; // skip external devices with their own batteries.
|
||||
}
|
||||
}
|
||||
|
||||
/* some drivers don't offer this, so if it's not explicitly reported assume it's present. */
|
||||
// some drivers don't offer this, so if it's not explicitly reported assume it's present.
|
||||
if (read_power_file(base, name, "present", str, sizeof(str)) && (SDL_strcmp(str, "0\n") == 0)) {
|
||||
st = SDL_POWERSTATE_NO_BATTERY;
|
||||
} else if (!read_power_file(base, name, "status", str, sizeof(str))) {
|
||||
st = SDL_POWERSTATE_UNKNOWN; /* uh oh */
|
||||
st = SDL_POWERSTATE_UNKNOWN; // uh oh
|
||||
} else if (SDL_strcasecmp(str, "Charging\n") == 0) {
|
||||
st = SDL_POWERSTATE_CHARGING;
|
||||
} else if (SDL_strcasecmp(str, "Discharging\n") == 0) {
|
||||
@@ -472,19 +472,19 @@ SDL_bool SDL_GetPowerInfo_Linux_sys_class_power_supply(SDL_PowerState *state, in
|
||||
} else if ((SDL_strcasecmp(str, "Full\n") == 0) || (SDL_strcasecmp(str, "Not charging\n") == 0)) {
|
||||
st = SDL_POWERSTATE_CHARGED;
|
||||
} else {
|
||||
st = SDL_POWERSTATE_UNKNOWN; /* uh oh */
|
||||
st = SDL_POWERSTATE_UNKNOWN; // uh oh
|
||||
}
|
||||
|
||||
if (!read_power_file(base, name, "capacity", str, sizeof(str))) {
|
||||
pct = -1;
|
||||
} else {
|
||||
pct = SDL_atoi(str);
|
||||
pct = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
|
||||
pct = (pct > 100) ? 100 : pct; // clamp between 0%, 100%
|
||||
}
|
||||
|
||||
if (read_power_file(base, name, "time_to_empty_now", str, sizeof(str))) {
|
||||
secs = SDL_atoi(str);
|
||||
secs = (secs <= 0) ? -1 : secs; /* 0 == unknown */
|
||||
secs = (secs <= 0) ? -1 : secs; // 0 == unknown
|
||||
} else if (st == SDL_POWERSTATE_ON_BATTERY) {
|
||||
/* energy is Watt*hours and power is Watts */
|
||||
energy = (read_power_file(base, name, "energy_now", str, sizeof(str))) ? SDL_atoi(str) : -1;
|
||||
@@ -500,7 +500,7 @@ SDL_bool SDL_GetPowerInfo_Linux_sys_class_power_supply(SDL_PowerState *state, in
|
||||
*/
|
||||
if ((secs < 0) && (*seconds < 0)) {
|
||||
if ((pct < 0) && (*percent < 0)) {
|
||||
choose = SDL_TRUE; /* at least we know there's a battery. */
|
||||
choose = SDL_TRUE; // at least we know there's a battery.
|
||||
} else if (pct > *percent) {
|
||||
choose = SDL_TRUE;
|
||||
}
|
||||
@@ -516,10 +516,10 @@ SDL_bool SDL_GetPowerInfo_Linux_sys_class_power_supply(SDL_PowerState *state, in
|
||||
}
|
||||
|
||||
closedir(dirp);
|
||||
return SDL_TRUE; /* don't look any further. */
|
||||
return SDL_TRUE; // don't look any further.
|
||||
}
|
||||
|
||||
/* d-bus queries to org.freedesktop.UPower. */
|
||||
// d-bus queries to org.freedesktop.UPower.
|
||||
#ifdef SDL_USE_LIBDBUS
|
||||
#define UPOWER_DBUS_NODE "org.freedesktop.UPower"
|
||||
#define UPOWER_DBUS_PATH "/org/freedesktop/UPower"
|
||||
@@ -537,13 +537,13 @@ static void check_upower_device(DBusConnection *conn, const char *path, SDL_Powe
|
||||
double d = 0.0;
|
||||
|
||||
if (!SDL_DBus_QueryPropertyOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "Type", DBUS_TYPE_UINT32, &ui32)) {
|
||||
return; /* Don't know _what_ we're looking at. Give up on it. */
|
||||
} else if (ui32 != 2) { /* 2==Battery*/
|
||||
return; /* we don't care about UPS and such. */
|
||||
return; // Don't know _what_ we're looking at. Give up on it.
|
||||
} else if (ui32 != 2) { // 2==Battery
|
||||
return; // we don't care about UPS and such.
|
||||
} else if (!SDL_DBus_QueryPropertyOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "PowerSupply", DBUS_TYPE_BOOLEAN, &ui32)) {
|
||||
return;
|
||||
} else if (!ui32) {
|
||||
return; /* we don't care about random devices with batteries, like wireless controllers, etc */
|
||||
return; // we don't care about random devices with batteries, like wireless controllers, etc
|
||||
}
|
||||
|
||||
if (!SDL_DBus_QueryPropertyOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "IsPresent", DBUS_TYPE_BOOLEAN, &ui32)) {
|
||||
@@ -558,8 +558,8 @@ static void check_upower_device(DBusConnection *conn, const char *path, SDL_Powe
|
||||
SDL_DBus_CallMethodOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "Refresh", DBUS_TYPE_INVALID, DBUS_TYPE_INVALID);
|
||||
|
||||
if (!SDL_DBus_QueryPropertyOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "State", DBUS_TYPE_UINT32, &ui32)) {
|
||||
st = SDL_POWERSTATE_UNKNOWN; /* uh oh */
|
||||
} else if (ui32 == 1) { /* 1 == charging */
|
||||
st = SDL_POWERSTATE_UNKNOWN; // uh oh
|
||||
} else if (ui32 == 1) { // 1 == charging
|
||||
st = SDL_POWERSTATE_CHARGING;
|
||||
} else if ((ui32 == 2) || (ui32 == 3) || (ui32 == 6)) {
|
||||
/* 2 == discharging;
|
||||
@@ -574,22 +574,22 @@ static void check_upower_device(DBusConnection *conn, const char *path, SDL_Powe
|
||||
* lower than 100% threshold */
|
||||
st = SDL_POWERSTATE_CHARGED;
|
||||
} else {
|
||||
st = SDL_POWERSTATE_UNKNOWN; /* uh oh */
|
||||
st = SDL_POWERSTATE_UNKNOWN; // uh oh
|
||||
}
|
||||
}
|
||||
|
||||
if (!SDL_DBus_QueryPropertyOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "Percentage", DBUS_TYPE_DOUBLE, &d)) {
|
||||
pct = -1; /* some old/cheap batteries don't set this property. */
|
||||
pct = -1; // some old/cheap batteries don't set this property.
|
||||
} else {
|
||||
pct = (int)d;
|
||||
pct = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
|
||||
pct = (pct > 100) ? 100 : pct; // clamp between 0%, 100%
|
||||
}
|
||||
|
||||
if (!SDL_DBus_QueryPropertyOnConnection(conn, UPOWER_DBUS_NODE, path, UPOWER_DEVICE_DBUS_INTERFACE, "TimeToEmpty", DBUS_TYPE_INT64, &si64)) {
|
||||
secs = -1;
|
||||
} else {
|
||||
secs = (int)si64;
|
||||
secs = (secs <= 0) ? -1 : secs; /* 0 == unknown */
|
||||
secs = (secs <= 0) ? -1 : secs; // 0 == unknown
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -598,7 +598,7 @@ static void check_upower_device(DBusConnection *conn, const char *path, SDL_Powe
|
||||
*/
|
||||
if ((secs < 0) && (*seconds < 0)) {
|
||||
if ((pct < 0) && (*percent < 0)) {
|
||||
choose = SDL_TRUE; /* at least we know there's a battery. */
|
||||
choose = SDL_TRUE; // at least we know there's a battery.
|
||||
} else if (pct > *percent) {
|
||||
choose = SDL_TRUE;
|
||||
}
|
||||
@@ -626,11 +626,11 @@ SDL_bool SDL_GetPowerInfo_Linux_org_freedesktop_upower(SDL_PowerState *state, in
|
||||
if (!dbus || !SDL_DBus_CallMethodOnConnection(dbus->system_conn, UPOWER_DBUS_NODE, UPOWER_DBUS_PATH, UPOWER_DBUS_INTERFACE, "EnumerateDevices",
|
||||
DBUS_TYPE_INVALID,
|
||||
DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &paths, &numpaths, DBUS_TYPE_INVALID)) {
|
||||
return SDL_FALSE; /* try a different approach than UPower. */
|
||||
return SDL_FALSE; // try a different approach than UPower.
|
||||
}
|
||||
|
||||
retval = SDL_TRUE; /* Clearly we can use this interface. */
|
||||
*state = SDL_POWERSTATE_NO_BATTERY; /* assume we're just plugged in. */
|
||||
retval = SDL_TRUE; // Clearly we can use this interface.
|
||||
*state = SDL_POWERSTATE_NO_BATTERY; // assume we're just plugged in.
|
||||
*seconds = -1;
|
||||
*percent = -1;
|
||||
|
||||
@@ -639,10 +639,10 @@ SDL_bool SDL_GetPowerInfo_Linux_org_freedesktop_upower(SDL_PowerState *state, in
|
||||
}
|
||||
|
||||
dbus->free_string_array(paths);
|
||||
#endif /* SDL_USE_LIBDBUS */
|
||||
#endif // SDL_USE_LIBDBUS
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif /* SDL_POWER_LINUX */
|
||||
#endif /* SDL_POWER_DISABLED */
|
||||
#endif // SDL_POWER_LINUX
|
||||
#endif // SDL_POWER_DISABLED
|
||||
|
||||
@@ -27,16 +27,16 @@
|
||||
#include <IOKit/ps/IOPowerSources.h>
|
||||
#include <IOKit/ps/IOPSKeys.h>
|
||||
|
||||
/* CoreFoundation is so verbose... */
|
||||
// CoreFoundation is so verbose...
|
||||
#define STRMATCH(a, b) (CFStringCompare(a, b, 0) == kCFCompareEqualTo)
|
||||
#define GETVAL(k, v) \
|
||||
CFDictionaryGetValueIfPresent(dict, CFSTR(k), (const void **)v)
|
||||
|
||||
/* Note that AC power sources also include a laptop battery it is charging. */
|
||||
// Note that AC power sources also include a laptop battery it is charging.
|
||||
static void checkps(CFDictionaryRef dict, SDL_bool *have_ac, SDL_bool *have_battery,
|
||||
SDL_bool *charging, int *seconds, int *percent)
|
||||
{
|
||||
CFStringRef strval; /* don't CFRelease() this. */
|
||||
CFStringRef strval; // don't CFRelease() this.
|
||||
CFBooleanRef bval;
|
||||
CFNumberRef numval;
|
||||
SDL_bool charge = SDL_FALSE;
|
||||
@@ -47,7 +47,7 @@ static void checkps(CFDictionaryRef dict, SDL_bool *have_ac, SDL_bool *have_batt
|
||||
int pct = -1;
|
||||
|
||||
if ((GETVAL(kIOPSIsPresentKey, &bval)) && (bval == kCFBooleanFalse)) {
|
||||
return; /* nothing to see here. */
|
||||
return; // nothing to see here.
|
||||
}
|
||||
|
||||
if (!GETVAL(kIOPSPowerSourceStateKey, &strval)) {
|
||||
@@ -57,7 +57,7 @@ static void checkps(CFDictionaryRef dict, SDL_bool *have_ac, SDL_bool *have_batt
|
||||
if (STRMATCH(strval, CFSTR(kIOPSACPowerValue))) {
|
||||
is_ac = *have_ac = SDL_TRUE;
|
||||
} else if (!STRMATCH(strval, CFSTR(kIOPSBatteryPowerValue))) {
|
||||
return; /* not a battery? */
|
||||
return; // not a battery?
|
||||
}
|
||||
|
||||
if ((GETVAL(kIOPSIsChargingKey, &bval)) && (bval == kCFBooleanTrue)) {
|
||||
@@ -86,14 +86,14 @@ static void checkps(CFDictionaryRef dict, SDL_bool *have_ac, SDL_bool *have_batt
|
||||
SInt32 val = -1;
|
||||
CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
|
||||
|
||||
/* macOS reports 0 minutes until empty if you're plugged in. :( */
|
||||
// macOS reports 0 minutes until empty if you're plugged in. :(
|
||||
if ((val == 0) && (is_ac)) {
|
||||
val = -1; /* !!! FIXME: calc from timeToFull and capacity? */
|
||||
val = -1; // !!! FIXME: calc from timeToFull and capacity?
|
||||
}
|
||||
|
||||
secs = (int)val;
|
||||
if (secs > 0) {
|
||||
secs *= 60; /* value is in minutes, so convert to seconds. */
|
||||
secs *= 60; // value is in minutes, so convert to seconds.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ static void checkps(CFDictionaryRef dict, SDL_bool *have_ac, SDL_bool *have_batt
|
||||
*/
|
||||
if ((secs < 0) && (*seconds < 0)) {
|
||||
if ((pct < 0) && (*percent < 0)) {
|
||||
choose = SDL_TRUE; /* at least we know there's a battery. */
|
||||
choose = SDL_TRUE; // at least we know there's a battery.
|
||||
}
|
||||
if (pct > *percent) {
|
||||
choose = SDL_TRUE;
|
||||
@@ -147,7 +147,7 @@ SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState *state, int *seconds, int *perce
|
||||
if (blob != NULL) {
|
||||
CFArrayRef list = IOPSCopyPowerSourcesList(blob);
|
||||
if (list != NULL) {
|
||||
/* don't CFRelease() the list items, or dictionaries! */
|
||||
// don't CFRelease() the list items, or dictionaries!
|
||||
SDL_bool have_ac = SDL_FALSE;
|
||||
SDL_bool have_battery = SDL_FALSE;
|
||||
SDL_bool charging = SDL_FALSE;
|
||||
@@ -178,8 +178,8 @@ SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState *state, int *seconds, int *perce
|
||||
CFRelease(blob);
|
||||
}
|
||||
|
||||
return SDL_TRUE; /* always the definitive answer on macOS. */
|
||||
return SDL_TRUE; // always the definitive answer on macOS.
|
||||
}
|
||||
|
||||
#endif /* SDL_POWER_MACOSX */
|
||||
#endif /* SDL_POWER_DISABLED */
|
||||
#endif // SDL_POWER_MACOSX
|
||||
#endif // SDL_POWER_DISABLED
|
||||
|
||||
@@ -36,7 +36,7 @@ SDL_bool SDL_GetPowerInfo_N3DS(SDL_PowerState *state, int *seconds, int *percent
|
||||
{
|
||||
*state = GetPowerState();
|
||||
*percent = GetBatteryPercentage();
|
||||
*seconds = -1; /* libctru doesn't provide a way to estimate battery life */
|
||||
*seconds = -1; // libctru doesn't provide a way to estimate battery life
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
@@ -99,4 +99,4 @@ static int GetBatteryPercentage(void)
|
||||
return (int)SDL_round(data[0] + data[1] / 256.0);
|
||||
}
|
||||
|
||||
#endif /* !SDL_POWER_DISABLED && SDL_POWER_N3DS */
|
||||
#endif // !SDL_POWER_DISABLED && SDL_POWER_N3DS
|
||||
|
||||
@@ -54,8 +54,8 @@ SDL_bool SDL_GetPowerInfo_PSP(SDL_PowerState *state, int *seconds, int *percent)
|
||||
*seconds = scePowerGetBatteryLifeTime() * 60;
|
||||
}
|
||||
|
||||
return SDL_TRUE; /* always the definitive answer on PSP. */
|
||||
return SDL_TRUE; // always the definitive answer on PSP.
|
||||
}
|
||||
|
||||
#endif /* SDL_POWER_PSP */
|
||||
#endif /* SDL_POWER_DISABLED */
|
||||
#endif // SDL_POWER_PSP
|
||||
#endif // SDL_POWER_DISABLED
|
||||
|
||||
@@ -25,4 +25,4 @@
|
||||
void SDL_UIKit_UpdateBatteryMonitoring(void);
|
||||
SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *state, int *seconds, int *percent);
|
||||
|
||||
#endif /* SDL_POWER_UIKIT */
|
||||
#endif // SDL_POWER_UIKIT
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "SDL_syspower.h"
|
||||
|
||||
#ifndef SDL_PLATFORM_TVOS
|
||||
/* turn off the battery monitor if it's been more than X ms since last check. */
|
||||
// turn off the battery monitor if it's been more than X ms since last check.
|
||||
static const int BATTERY_MONITORING_TIMEOUT = 3000;
|
||||
static Uint64 SDL_UIKitLastPowerInfoQuery = 0;
|
||||
|
||||
@@ -46,9 +46,9 @@ void SDL_UIKit_UpdateBatteryMonitoring(void)
|
||||
#else
|
||||
void SDL_UIKit_UpdateBatteryMonitoring(void)
|
||||
{
|
||||
/* Do nothing. */
|
||||
// Do nothing.
|
||||
}
|
||||
#endif /* !SDL_PLATFORM_TVOS */
|
||||
#endif // !SDL_PLATFORM_TVOS
|
||||
|
||||
SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *state, int *seconds, int *percent)
|
||||
{
|
||||
@@ -56,7 +56,7 @@ SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *state, int *seconds, int *percen
|
||||
*state = SDL_POWERSTATE_NO_BATTERY;
|
||||
*seconds = -1;
|
||||
*percent = -1;
|
||||
#else /* SDL_PLATFORM_TVOS */
|
||||
#else // SDL_PLATFORM_TVOS
|
||||
@autoreleasepool {
|
||||
UIDevice *uidev = [UIDevice currentDevice];
|
||||
|
||||
@@ -72,7 +72,7 @@ SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *state, int *seconds, int *percen
|
||||
*/
|
||||
SDL_UIKitLastPowerInfoQuery = SDL_GetTicks();
|
||||
|
||||
*seconds = -1; /* no API to estimate this in UIKit. */
|
||||
*seconds = -1; // no API to estimate this in UIKit.
|
||||
|
||||
switch (uidev.batteryState) {
|
||||
case UIDeviceBatteryStateCharging:
|
||||
@@ -96,10 +96,10 @@ SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *state, int *seconds, int *percen
|
||||
const float level = uidev.batteryLevel;
|
||||
*percent = ((level < 0.0f) ? -1 : ((int)((level * 100) + 0.5f)));
|
||||
}
|
||||
#endif /* SDL_PLATFORM_TVOS */
|
||||
#endif // SDL_PLATFORM_TVOS
|
||||
|
||||
return SDL_TRUE; /* always the definitive answer on iOS. */
|
||||
return SDL_TRUE; // always the definitive answer on iOS.
|
||||
}
|
||||
|
||||
#endif /* SDL_POWER_UIKIT */
|
||||
#endif /* SDL_POWER_DISABLED */
|
||||
#endif // SDL_POWER_UIKIT
|
||||
#endif // SDL_POWER_DISABLED
|
||||
|
||||
@@ -54,8 +54,8 @@ SDL_bool SDL_GetPowerInfo_VITA(SDL_PowerState *state, int *seconds, int *percent
|
||||
*seconds = scePowerGetBatteryLifeTime() * 60;
|
||||
}
|
||||
|
||||
return SDL_TRUE; /* always the definitive answer on VITA. */
|
||||
return SDL_TRUE; // always the definitive answer on VITA.
|
||||
}
|
||||
|
||||
#endif /* SDL_POWER_VITA */
|
||||
#endif /* SDL_POWER_DISABLED */
|
||||
#endif // SDL_POWER_VITA
|
||||
#endif // SDL_POWER_DISABLED
|
||||
|
||||
@@ -30,22 +30,22 @@ SDL_bool SDL_GetPowerInfo_Windows(SDL_PowerState *state, int *seconds, int *perc
|
||||
SYSTEM_POWER_STATUS status;
|
||||
SDL_bool need_details = SDL_FALSE;
|
||||
|
||||
/* This API should exist back to Win95. */
|
||||
// This API should exist back to Win95.
|
||||
if (!GetSystemPowerStatus(&status)) {
|
||||
/* !!! FIXME: push GetLastError() into SDL_GetError() */
|
||||
// !!! FIXME: push GetLastError() into SDL_GetError()
|
||||
*state = SDL_POWERSTATE_UNKNOWN;
|
||||
} else if (status.BatteryFlag == 0xFF) { /* unknown state */
|
||||
} else if (status.BatteryFlag == 0xFF) { // unknown state
|
||||
*state = SDL_POWERSTATE_UNKNOWN;
|
||||
} else if (status.BatteryFlag & (1 << 7)) { /* no battery */
|
||||
} else if (status.BatteryFlag & (1 << 7)) { // no battery
|
||||
*state = SDL_POWERSTATE_NO_BATTERY;
|
||||
} else if (status.BatteryFlag & (1 << 3)) { /* charging */
|
||||
} else if (status.BatteryFlag & (1 << 3)) { // charging
|
||||
*state = SDL_POWERSTATE_CHARGING;
|
||||
need_details = SDL_TRUE;
|
||||
} else if (status.ACLineStatus == 1) {
|
||||
*state = SDL_POWERSTATE_CHARGED; /* on AC, not charging. */
|
||||
*state = SDL_POWERSTATE_CHARGED; // on AC, not charging.
|
||||
need_details = SDL_TRUE;
|
||||
} else {
|
||||
*state = SDL_POWERSTATE_ON_BATTERY; /* not on AC. */
|
||||
*state = SDL_POWERSTATE_ON_BATTERY; // not on AC.
|
||||
need_details = SDL_TRUE;
|
||||
}
|
||||
|
||||
@@ -55,16 +55,16 @@ SDL_bool SDL_GetPowerInfo_Windows(SDL_PowerState *state, int *seconds, int *perc
|
||||
const int pct = (int)status.BatteryLifePercent;
|
||||
const int secs = (int)status.BatteryLifeTime;
|
||||
|
||||
if (pct != 255) { /* 255 == unknown */
|
||||
*percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
|
||||
if (pct != 255) { // 255 == unknown
|
||||
*percent = (pct > 100) ? 100 : pct; // clamp between 0%, 100%
|
||||
}
|
||||
if (secs != 0xFFFFFFFF) { /* ((DWORD)-1) == unknown */
|
||||
if (secs != 0xFFFFFFFF) { // ((DWORD)-1) == unknown
|
||||
*seconds = secs;
|
||||
}
|
||||
}
|
||||
|
||||
return SDL_TRUE; /* always the definitive answer on Windows. */
|
||||
return SDL_TRUE; // always the definitive answer on Windows.
|
||||
}
|
||||
|
||||
#endif /* SDL_POWER_WINDOWS */
|
||||
#endif /* SDL_POWER_DISABLED */
|
||||
#endif // SDL_POWER_WINDOWS
|
||||
#endif // SDL_POWER_DISABLED
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
extern "C" SDL_bool
|
||||
SDL_GetPowerInfo_WinRT(SDL_PowerState *state, int *seconds, int *percent)
|
||||
{
|
||||
/* TODO, WinRT: Battery info is available on at least one WinRT platform (Windows Phone 8). Implement SDL_GetPowerInfo_WinRT as appropriate. */
|
||||
// TODO, WinRT: Battery info is available on at least one WinRT platform (Windows Phone 8). Implement SDL_GetPowerInfo_WinRT as appropriate.
|
||||
/* Notes:
|
||||
- the Win32 function, GetSystemPowerStatus, is not available for use on WinRT
|
||||
- Windows Phone 8 has a 'Battery' class, which is documented as available for C++
|
||||
@@ -35,5 +35,5 @@ SDL_GetPowerInfo_WinRT(SDL_PowerState *state, int *seconds, int *percent)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
#endif /* SDL_POWER_WINRT */
|
||||
#endif /* SDL_POWER_DISABLED */
|
||||
#endif // SDL_POWER_WINRT
|
||||
#endif // SDL_POWER_DISABLED
|
||||
|
||||
Reference in New Issue
Block a user