SDL  2.0
SDL_power.h File Reference
#include "SDL_stdinc.h"
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_power.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  SDL_PowerState {
  SDL_POWERSTATE_UNKNOWN,
  SDL_POWERSTATE_ON_BATTERY,
  SDL_POWERSTATE_NO_BATTERY,
  SDL_POWERSTATE_CHARGING,
  SDL_POWERSTATE_CHARGED
}
 The basic state for the system's power supply. More...
 

Functions

SDL_PowerState SDL_GetPowerInfo (int *secs, int *pct)
 Get the current power supply details. More...
 

Detailed Description

Header for the SDL power management routines.

Definition in file SDL_power.h.

Enumeration Type Documentation

◆ SDL_PowerState

The basic state for the system's power supply.

Enumerator
SDL_POWERSTATE_UNKNOWN 

cannot determine power status

SDL_POWERSTATE_ON_BATTERY 

Not plugged in, running on the battery

SDL_POWERSTATE_NO_BATTERY 

Plugged in, no battery available

SDL_POWERSTATE_CHARGING 

Plugged in, charging battery

SDL_POWERSTATE_CHARGED 

Plugged in, battery charged

Definition at line 42 of file SDL_power.h.

43 {
44  SDL_POWERSTATE_UNKNOWN, /**< cannot determine power status */
45  SDL_POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */
46  SDL_POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */
47  SDL_POWERSTATE_CHARGING, /**< Plugged in, charging battery */
48  SDL_POWERSTATE_CHARGED /**< Plugged in, battery charged */

Function Documentation

◆ SDL_GetPowerInfo()

SDL_PowerState SDL_GetPowerInfo ( int *  secs,
int *  pct 
)

Get the current power supply details.

Parameters
secsSeconds of battery life left. You can pass a NULL here if you don't care. Will return -1 if we can't determine a value, or we're not running on a battery.
pctPercentage of battery life left, between 0 and 100. You can pass a NULL here if you don't care. Will return -1 if we can't determine a value, or we're not running on a battery.
Returns
The state of the battery (if any).

Definition at line 85 of file SDL_power.c.

86 {
87 #ifndef SDL_POWER_DISABLED
88  const int total = sizeof(implementations) / sizeof(implementations[0]);
90  int i;
91 #endif
92 
93  int _seconds, _percent;
94  /* Make these never NULL for platform-specific implementations. */
95  if (seconds == NULL) {
96  seconds = &_seconds;
97  }
98  if (percent == NULL) {
99  percent = &_percent;
100  }
101 
102 #ifndef SDL_POWER_DISABLED
103  for (i = 0; i < total; i++) {
104  if (implementations[i](&retval, seconds, percent)) {
105  return retval;
106  }
107  }
108 #endif
109 
110  /* nothing was definitive. */
111  *seconds = -1;
112  *percent = -1;
113  return SDL_POWERSTATE_UNKNOWN;
114 }

References i, implementations, NULL, retval, and SDL_POWERSTATE_UNKNOWN.

SDL_POWERSTATE_CHARGING
@ SDL_POWERSTATE_CHARGING
Definition: SDL_power.h:47
NULL
#define NULL
Definition: begin_code.h:167
SDL_POWERSTATE_ON_BATTERY
@ SDL_POWERSTATE_ON_BATTERY
Definition: SDL_power.h:45
retval
SDL_bool retval
Definition: testgamecontroller.c:65
implementations
static SDL_GetPowerInfo_Impl implementations[]
Definition: SDL_power.c:46
SDL_POWERSTATE_NO_BATTERY
@ SDL_POWERSTATE_NO_BATTERY
Definition: SDL_power.h:46
SDL_PowerState
SDL_PowerState
The basic state for the system's power supply.
Definition: SDL_power.h:43
SDL_POWERSTATE_CHARGED
@ SDL_POWERSTATE_CHARGED
Definition: SDL_power.h:48
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
SDL_POWERSTATE_UNKNOWN
@ SDL_POWERSTATE_UNKNOWN
Definition: SDL_power.h:44