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

Commit

Permalink
Browse files Browse the repository at this point in the history
indent
  • Loading branch information
slouken committed Jun 10, 2009
1 parent bef03e4 commit b518b78
Show file tree
Hide file tree
Showing 18 changed files with 617 additions and 705 deletions.
696 changes: 303 additions & 393 deletions include/SDL_atomic.h

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/events/SDL_mouse.c
Expand Up @@ -369,6 +369,7 @@ SDL_SendProximity(int id, int x, int y, int type)
event.proximity.y = y;
event.proximity.cursor = mouse->current_end;
event.proximity.type = type;
event.proximity.windowID = mouse->focus;
posted = (SDL_PushEvent(&event) > 0);
if (type == SDL_PROXIMITYIN) {
mouse->proximity = SDL_TRUE;
Expand Down
40 changes: 20 additions & 20 deletions src/power/SDL_power.c
Expand Up @@ -27,22 +27,23 @@
* SDL_FALSE to try next implementation.
*/
typedef SDL_bool
(*SDL_GetPowerInfo_Impl)(SDL_PowerState *state, int *seconds, int *percent);

SDL_bool SDL_GetPowerInfo_Linux_sys_power(SDL_PowerState*, int*, int*);
SDL_bool SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState*, int*, int*);
SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState*, int*, int*);
SDL_bool SDL_GetPowerInfo_Windows(SDL_PowerState*, int*, int*);
SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState*, int*, int*);
SDL_bool SDL_GetPowerInfo_OS2(SDL_PowerState*, int*, int*);
SDL_bool SDL_GetPowerInfo_BeOS(SDL_PowerState*, int*, int*);
SDL_bool SDL_GetPowerInfo_NintendoDS(SDL_PowerState*, int*, int*);
(*SDL_GetPowerInfo_Impl) (SDL_PowerState * state, int *seconds,
int *percent);

SDL_bool SDL_GetPowerInfo_Linux_sys_power(SDL_PowerState *, int *, int *);
SDL_bool SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState *, int *, int *);
SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *, int *, int *);
SDL_bool SDL_GetPowerInfo_Windows(SDL_PowerState *, int *, int *);
SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState *, int *, int *);
SDL_bool SDL_GetPowerInfo_OS2(SDL_PowerState *, int *, int *);
SDL_bool SDL_GetPowerInfo_BeOS(SDL_PowerState *, int *, int *);
SDL_bool SDL_GetPowerInfo_NintendoDS(SDL_PowerState *, int *, int *);

#ifndef SDL_POWER_DISABLED
#ifdef SDL_POWER_HARDWIRED
/* This is for things that _never_ have a battery, like the Dreamcast, etc. */
static SDL_bool
SDL_GetPowerInfo_Hardwired(SDL_PowerState *state, int *seconds, int *percent)
SDL_GetPowerInfo_Hardwired(SDL_PowerState * state, int *seconds, int *percent)
{
*seconds = -1;
*percent = -1;
Expand All @@ -55,24 +56,24 @@ SDL_GetPowerInfo_Hardwired(SDL_PowerState *state, int *seconds, int *percent)

static SDL_GetPowerInfo_Impl implementations[] = {
#ifndef SDL_POWER_DISABLED
#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_sys_power,
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_MACOSX /* handles Mac OS X, Darwin, iPhone. */
#ifdef SDL_POWER_MACOSX /* handles Mac OS X, Darwin, iPhone. */
SDL_GetPowerInfo_MacOSX,
#endif
#ifdef SDL_POWER_OS2 /* handles OS/2, Warp, eComStation. */
#ifdef SDL_POWER_OS2 /* handles OS/2, Warp, eComStation. */
SDL_GetPowerInfo_OS2,
#endif
#ifdef SDL_POWER_NINTENDODS /* handles Nintendo DS. */
#ifdef SDL_POWER_NINTENDODS /* handles Nintendo DS. */
SDL_GetPowerInfo_NintendoDS,
#endif
#ifdef SDL_POWER_BEOS /* handles BeOS, Zeta, with euc.jp apm driver. */
#ifdef SDL_POWER_BEOS /* handles BeOS, Zeta, with euc.jp apm driver. */
SDL_GetPowerInfo_BeOS,
#endif
#ifdef SDL_POWER_HARDWIRED
Expand All @@ -84,7 +85,7 @@ static SDL_GetPowerInfo_Impl implementations[] = {
SDL_PowerState
SDL_GetPowerInfo(int *seconds, int *percent)
{
const int total = sizeof (implementations) / sizeof (implementations[0]);
const int total = sizeof(implementations) / sizeof(implementations[0]);
int _seconds, _percent;
SDL_PowerState retval;
int i;
Expand All @@ -99,7 +100,7 @@ SDL_GetPowerInfo(int *seconds, int *percent)
}

for (i = 0; i < total; i++) {
if (implementations[i](&retval, seconds, percent)) {
if (implementations[i] (&retval, seconds, percent)) {
return retval;
}
}
Expand All @@ -111,4 +112,3 @@ SDL_GetPowerInfo(int *seconds, int *percent)
}

/* vi: set ts=4 sw=4 expandtab: */

29 changes: 14 additions & 15 deletions src/power/beos/SDL_syspower.c
Expand Up @@ -41,7 +41,7 @@
#include "SDL_power.h"

SDL_bool
SDL_GetPowerInfo_BeOS(SDL_PowerState *state, int *seconds, int *percent)
SDL_GetPowerInfo_BeOS(SDL_PowerState * state, int *seconds, int *percent)
{
const int fd = open("/dev/misc/apm", O_RDONLY);
SDL_bool need_details = SDL_FALSE;
Expand All @@ -53,10 +53,10 @@ SDL_GetPowerInfo_BeOS(SDL_PowerState *state, int *seconds, int *percent)
uint32 battery_time;

if (fd == -1) {
return SDL_FALSE; /* maybe some other method will work? */
return SDL_FALSE; /* maybe some other method will work? */
}

memset(regs, '\0', sizeof (regs));
memset(regs, '\0', sizeof(regs));
regs[0] = APM_FUNC_OFFSET + APM_FUNC_GET_POWER_STATUS;
regs[1] = APM_DEVICE_ALL;
rc = ioctl(fd, APM_BIOS_CALL, regs);
Expand All @@ -73,7 +73,7 @@ SDL_GetPowerInfo_BeOS(SDL_PowerState *state, int *seconds, int *percent)
battery_time = (uint32) regs[3];

/* in theory, _something_ should be set in battery_flags, right? */
if (battery_flags == 0x00) { /* older APM BIOS? Less fields. */
if (battery_flags == 0x00) { /* older APM BIOS? Less fields. */
battery_time = 0xFFFF;
if (battery_status == 0xFF) {
battery_flags = 0xFF;
Expand All @@ -82,23 +82,23 @@ SDL_GetPowerInfo_BeOS(SDL_PowerState *state, int *seconds, int *percent)
}
}

if ( (battery_time != 0xFFFF) && (battery_time & (1 << 15)) ) {
if ((battery_time != 0xFFFF) && (battery_time & (1 << 15))) {
/* 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;
}

Expand All @@ -108,19 +108,18 @@ SDL_GetPowerInfo_BeOS(SDL_PowerState *state, int *seconds, int *percent)
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_BEOS */
#endif /* SDL_POWER_DISABLED */

/* vi: set ts=4 sw=4 expandtab: */

61 changes: 30 additions & 31 deletions src/power/linux/SDL_syspower.c
Expand Up @@ -34,28 +34,28 @@
#include "SDL_power.h"

SDL_bool
SDL_GetPowerInfo_Linux_sys_power(SDL_PowerState *state,
SDL_GetPowerInfo_Linux_sys_power(SDL_PowerState * state,
int *seconds, int *percent)
{
return SDL_FALSE; /* !!! FIXME: write me. */
return SDL_FALSE; /* !!! FIXME: write me. */
#if 0
const int fd = open("/sys/power", O_RDONLY);
if (fd == -1) {
return SDL_FALSE; /* can't use this interface. */
return SDL_FALSE; /* can't use this interface. */
}
return SDL_TRUE;
#endif
}

SDL_bool
SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState *state,
int *seconds, int *percent)
SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState * state,
int *seconds, int *percent)
{
return SDL_FALSE; /* !!! FIXME: write me. */
return SDL_FALSE; /* !!! FIXME: write me. */
#if 0
const int fd = open("/proc/acpi", O_RDONLY);
if (fd == -1) {
return SDL_FALSE; /* can't use this interface. */
return SDL_FALSE; /* can't use this interface. */
}
return SDL_TRUE;
#endif
Expand All @@ -67,7 +67,7 @@ next_string(char **_ptr, char **_str)
char *ptr = *_ptr;
char *str = *_str;

while (*ptr == ' ') { /* skip any spaces... */
while (*ptr == ' ') { /* skip any spaces... */
ptr++;
}

Expand All @@ -91,14 +91,14 @@ static SDL_bool
int_string(char *str, int *val)
{
char *endptr = NULL;
*val = (int) strtol(str+2, &endptr, 16);
*val = (int) strtol(str + 2, &endptr, 16);
return ((*str != '\0') && (*endptr == '\0'));
}

/* 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_GetPowerInfo_Linux_proc_apm(SDL_PowerState * state,
int *seconds, int *percent)
{
SDL_bool need_details = SDL_FALSE;
int ac_status = 0;
Expand All @@ -113,44 +113,44 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *state,
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);
br = read(fd, buf, sizeof(buf) - 1);
close(fd);

if (br < 0) {
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[strlen(str) - 1] == '%') {
Expand All @@ -160,27 +160,27 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *state,
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 (strcmp(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;
Expand All @@ -193,10 +193,10 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *state,
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;
}
}
Expand All @@ -208,4 +208,3 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *state,
#endif /* SDL_POWER_DISABLED */

/* vi: set ts=4 sw=4 expandtab: */

0 comments on commit b518b78

Please sign in to comment.