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 }

## Functions

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

## Enumeration Type Documentation

## SDL_PowerState

enum SDL_PowerState

# CategoryPower

Header for the SDL power management routines. 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.

{
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 */
} SDL_PowerState;
SDL_PowerState
SDL_PowerState
Definition SDL_power.h:43
SDL_POWERSTATE_NO_BATTERY
@ SDL_POWERSTATE_NO_BATTERY
Definition SDL_power.h:46
SDL_POWERSTATE_CHARGING
@ SDL_POWERSTATE_CHARGING
Definition SDL_power.h:47
SDL_POWERSTATE_CHARGED
@ SDL_POWERSTATE_CHARGED
Definition SDL_power.h:48
SDL_POWERSTATE_UNKNOWN
@ SDL_POWERSTATE_UNKNOWN
Definition SDL_power.h:44
SDL_POWERSTATE_ON_BATTERY
@ SDL_POWERSTATE_ON_BATTERY
Definition SDL_power.h:45

## 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

  seconds | seconds 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.
  percent | percentage 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
  an SDL_PowerState enum representing the current battery state.

Since
  This function is available since SDL 2.0.0.