SDL
3.0
SDL_power.h
Go to the documentation of this file.
1
/*
2
Simple DirectMedia Layer
3
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5
This software is provided 'as-is', without any express or implied
6
warranty. In no event will the authors be held liable for any damages
7
arising from the use of this software.
8
9
Permission is granted to anyone to use this software for any purpose,
10
including commercial applications, and to alter it and redistribute it
11
freely, subject to the following restrictions:
12
13
1. The origin of this software must not be misrepresented; you must not
14
claim that you wrote the original software. If you use this software
15
in a product, an acknowledgment in the product documentation would be
16
appreciated but is not required.
17
2. Altered source versions must be plainly marked as such, and must not be
18
misrepresented as being the original software.
19
3. This notice may not be removed or altered from any source distribution.
20
*/
21
22
#ifndef SDL_power_h_
23
#define SDL_power_h_
24
25
/**
26
* # CategoryPower
27
*
28
* SDL power management routines.
29
*/
30
31
#include <
SDL3/SDL_stdinc.h
>
32
#include <
SDL3/SDL_error.h
>
33
34
#include <
SDL3/SDL_begin_code.h
>
35
/* Set up for C function definitions, even when using C++ */
36
#ifdef __cplusplus
37
extern
"C"
{
38
#endif
39
40
/**
41
* The basic state for the system's power supply.
42
*
43
* These are results returned by SDL_GetPowerInfo().
44
*
45
* \since This enum is available since SDL 3.1.3
46
*/
47
typedef
enum
SDL_PowerState
48
{
49
SDL_POWERSTATE_ERROR
= -1,
/**< error determining power status */
50
SDL_POWERSTATE_UNKNOWN
,
/**< cannot determine power status */
51
SDL_POWERSTATE_ON_BATTERY
,
/**< Not plugged in, running on the battery */
52
SDL_POWERSTATE_NO_BATTERY
,
/**< Plugged in, no battery available */
53
SDL_POWERSTATE_CHARGING
,
/**< Plugged in, charging battery */
54
SDL_POWERSTATE_CHARGED
/**< Plugged in, battery charged */
55
}
SDL_PowerState
;
56
57
/**
58
* Get the current power supply details.
59
*
60
* You should never take a battery status as absolute truth. Batteries
61
* (especially failing batteries) are delicate hardware, and the values
62
* reported here are best estimates based on what that hardware reports. It's
63
* not uncommon for older batteries to lose stored power much faster than it
64
* reports, or completely drain when reporting it has 20 percent left, etc.
65
*
66
* Battery status can change at any time; if you are concerned with power
67
* state, you should call this function frequently, and perhaps ignore changes
68
* until they seem to be stable for a few seconds.
69
*
70
* It's possible a platform can only report battery percentage or time left
71
* but not both.
72
*
73
* \param seconds a pointer filled in with the seconds of battery life left,
74
* or NULL to ignore. This will be filled in with -1 if we
75
* can't determine a value or there is no battery.
76
* \param percent a pointer filled in with the percentage of battery life
77
* left, between 0 and 100, or NULL to ignore. This will be
78
* filled in with -1 we can't determine a value or there is no
79
* battery.
80
* \returns the current battery state or `SDL_POWERSTATE_ERROR` on failure;
81
* call SDL_GetError() for more information.
82
*
83
* \since This function is available since SDL 3.1.3.
84
*/
85
extern
SDL_DECLSPEC
SDL_PowerState
SDLCALL
SDL_GetPowerInfo
(
int
*seconds,
int
*percent);
86
87
/* Ends C function definitions when using C++ */
88
#ifdef __cplusplus
89
}
90
#endif
91
#include <
SDL3/SDL_close_code.h
>
92
93
#endif
/* SDL_power_h_ */
SDL_begin_code.h
SDL_close_code.h
SDL_error.h
SDL_GetPowerInfo
SDL_PowerState SDL_GetPowerInfo(int *seconds, int *percent)
SDL_PowerState
SDL_PowerState
Definition
SDL_power.h:48
SDL_POWERSTATE_NO_BATTERY
@ SDL_POWERSTATE_NO_BATTERY
Definition
SDL_power.h:52
SDL_POWERSTATE_CHARGING
@ SDL_POWERSTATE_CHARGING
Definition
SDL_power.h:53
SDL_POWERSTATE_CHARGED
@ SDL_POWERSTATE_CHARGED
Definition
SDL_power.h:54
SDL_POWERSTATE_UNKNOWN
@ SDL_POWERSTATE_UNKNOWN
Definition
SDL_power.h:50
SDL_POWERSTATE_ON_BATTERY
@ SDL_POWERSTATE_ON_BATTERY
Definition
SDL_power.h:51
SDL_POWERSTATE_ERROR
@ SDL_POWERSTATE_ERROR
Definition
SDL_power.h:49
SDL_stdinc.h
include
SDL3
SDL_power.h
Generated by
1.9.8