Path: blob/master/thirdparty/sdl/include/SDL3/SDL_power.h
9912 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/2021#ifndef SDL_power_h_22#define SDL_power_h_2324/**25* # CategoryPower26*27* SDL power management routines.28*29* There is a single function in this category: SDL_GetPowerInfo().30*31* This function is useful for games on the go. This allows an app to know if32* it's running on a draining battery, which can be useful if the app wants to33* reduce processing, or perhaps framerate, to extend the duration of the34* battery's charge. Perhaps the app just wants to show a battery meter when35* fullscreen, or alert the user when the power is getting extremely low, so36* they can save their game.37*/3839#include <SDL3/SDL_stdinc.h>40#include <SDL3/SDL_error.h>4142#include <SDL3/SDL_begin_code.h>43/* Set up for C function definitions, even when using C++ */44#ifdef __cplusplus45extern "C" {46#endif4748/**49* The basic state for the system's power supply.50*51* These are results returned by SDL_GetPowerInfo().52*53* \since This enum is available since SDL 3.2.0.54*/55typedef enum SDL_PowerState56{57SDL_POWERSTATE_ERROR = -1, /**< error determining power status */58SDL_POWERSTATE_UNKNOWN, /**< cannot determine power status */59SDL_POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */60SDL_POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */61SDL_POWERSTATE_CHARGING, /**< Plugged in, charging battery */62SDL_POWERSTATE_CHARGED /**< Plugged in, battery charged */63} SDL_PowerState;6465/**66* Get the current power supply details.67*68* You should never take a battery status as absolute truth. Batteries69* (especially failing batteries) are delicate hardware, and the values70* reported here are best estimates based on what that hardware reports. It's71* not uncommon for older batteries to lose stored power much faster than it72* reports, or completely drain when reporting it has 20 percent left, etc.73*74* Battery status can change at any time; if you are concerned with power75* state, you should call this function frequently, and perhaps ignore changes76* until they seem to be stable for a few seconds.77*78* It's possible a platform can only report battery percentage or time left79* but not both.80*81* On some platforms, retrieving power supply details might be expensive. If82* you want to display continuous status you could call this function every83* minute or so.84*85* \param seconds a pointer filled in with the seconds of battery life left,86* or NULL to ignore. This will be filled in with -1 if we87* can't determine a value or there is no battery.88* \param percent a pointer filled in with the percentage of battery life89* left, between 0 and 100, or NULL to ignore. This will be90* filled in with -1 we can't determine a value or there is no91* battery.92* \returns the current battery state or `SDL_POWERSTATE_ERROR` on failure;93* call SDL_GetError() for more information.94*95* \since This function is available since SDL 3.2.0.96*/97extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetPowerInfo(int *seconds, int *percent);9899/* Ends C function definitions when using C++ */100#ifdef __cplusplus101}102#endif103#include <SDL3/SDL_close_code.h>104105#endif /* SDL_power_h_ */106107108