SDL 3.0
SDL_power.h File Reference
+ 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_ERROR = -1 ,
  SDL_POWERSTATE_UNKNOWN ,
  SDL_POWERSTATE_ON_BATTERY ,
  SDL_POWERSTATE_NO_BATTERY ,
  SDL_POWERSTATE_CHARGING ,
  SDL_POWERSTATE_CHARGED
}
 

Functions

SDL_PowerState SDL_GetPowerInfo (int *seconds, int *percent)
 

Enumeration Type Documentation

◆ SDL_PowerState

CategoryPower

SDL power management routines.

There is a single function in this category: SDL_GetPowerInfo().

This function is useful for games on the go. This allows an app to know if it's running on a draining battery, which can be useful if the app wants to reduce processing, or perhaps framerate, to extend the duration of the battery's charge. Perhaps the app just wants to show a battery meter when fullscreen, or alert the user when the power is getting extremely low, so they can save their game. The basic state for the system's power supply.

These are results returned by SDL_GetPowerInfo().

Since
This enum is available since SDL 3.2.0.
Enumerator
SDL_POWERSTATE_ERROR 

error determining power status

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 56 of file SDL_power.h.

57{
58 SDL_POWERSTATE_ERROR = -1, /**< error determining power status */
59 SDL_POWERSTATE_UNKNOWN, /**< cannot determine power status */
60 SDL_POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */
61 SDL_POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */
62 SDL_POWERSTATE_CHARGING, /**< Plugged in, charging battery */
63 SDL_POWERSTATE_CHARGED /**< Plugged in, battery charged */
SDL_PowerState
Definition SDL_power.h:57
@ SDL_POWERSTATE_NO_BATTERY
Definition SDL_power.h:61
@ SDL_POWERSTATE_CHARGING
Definition SDL_power.h:62
@ SDL_POWERSTATE_CHARGED
Definition SDL_power.h:63
@ SDL_POWERSTATE_UNKNOWN
Definition SDL_power.h:59
@ SDL_POWERSTATE_ON_BATTERY
Definition SDL_power.h:60
@ SDL_POWERSTATE_ERROR
Definition SDL_power.h:58

Function Documentation

◆ SDL_GetPowerInfo()

SDL_PowerState SDL_GetPowerInfo ( int * seconds,
int * percent )
extern

Get the current power supply details.

You should never take a battery status as absolute truth. Batteries (especially failing batteries) are delicate hardware, and the values reported here are best estimates based on what that hardware reports. It's not uncommon for older batteries to lose stored power much faster than it reports, or completely drain when reporting it has 20 percent left, etc.

Battery status can change at any time; if you are concerned with power state, you should call this function frequently, and perhaps ignore changes until they seem to be stable for a few seconds.

It's possible a platform can only report battery percentage or time left but not both.

Parameters
secondsa pointer filled in with the seconds of battery life left, or NULL to ignore. This will be filled in with -1 if we can't determine a value or there is no battery.
percenta pointer filled in with the percentage of battery life left, between 0 and 100, or NULL to ignore. This will be filled in with -1 we can't determine a value or there is no battery.
Returns
the current battery state or SDL_POWERSTATE_ERROR on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.2.0.