SDL_power.h 3.4 KB

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