SDL_GetPowerInfo(3)
β¨ SDL_GetPowerInfo β¨
okay bestie, welcome to SDL_GetPowerInfo(3) β it lives in the SDL3 FUNCTIONS section and it's literally your little battery-psychic π
πΈ NAME πΈ
SDL_GetPowerInfo β get the current power supply details πβ¨
π SYNOPSIS π
#include <SDL3/SDL_power.h>
SDL_PowerState SDL_GetPowerInfo(int *seconds, int *percent);
π DESCRIPTION π
okay so first thing first, queen: never take a battery status as absolute truth. not even once. batteries β especially the failing ones, bless them β are delicate hardware π₯Ί and the values reported here are best estimates based on what that hardware says. it's genuinely not uncommon for older batteries to lose stored power much faster than it reports, or to fully drain while still claiming it has 20 percent left, etc. the drama. the betrayal. π
also, battery status can change at any time, so if you actually care about power state, call this function frequently β and maybe ignore changes until they seem stable for a few seconds π. vibe check the battery, don't trust one single reading.
it's also possible a platform can only report battery percentage or time left but not both. so like, pick your fave, ig π
and heads up: on some platforms, retrieving power supply details might be expensive π. so if you want to display continuous status, you could call this function every minute or so β no need to spam it, it's not that deep.
π FUNCTION PARAMETERS π
secondsβ a pointer filled in with the seconds of battery life left, orNULLto ignore. this gets filled in with-1if we can't determine a value or there's no battery at all πͺ«percentβ a pointer filled in with the percentage of battery life left, between 0 and 100, orNULLto ignore. this gets filled in with-1when we can't determine a value or there's no battery π
β RETURN VALUE β
returns the current battery state, or SDL_POWERSTATE_ERROR on failure π β and if that happens, call SDL_GetError() for more info, bestie, it'll tell you what went wrong π«Ά
π THREAD SAFETY π
this function is not thread safe. periodt. π
π¦ AVAILABILITY π¦
this function is available since SDL 3.2.0 β¨
made with love by the Simple Directmedia Layer girlies π β this is from SDL 3.4.18, and yes, it's still called SDL_GetPowerInfo(3) π go check your battery, bestie, and hydrate while you're at it πΈ
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms