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, or NULL to ignore. this gets filled in with -1 if 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, or NULL to ignore. this gets filled in with -1 when 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