1 /* 2 DSDL 3 Copyright (C) 2025 Inochi2D Project <luna@foxgirls.gay> 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 23 Simple DirectMedia Layer 24 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> 25 26 This software is provided 'as-is', without any express or implied 27 warranty. In no event will the authors be held liable for any damages 28 arising from the use of this software. 29 30 Permission is granted to anyone to use this software for any purpose, 31 including commercial applications, and to alter it and redistribute it 32 freely, subject to the following restrictions: 33 34 1. The origin of this software must not be misrepresented; you must not 35 claim that you wrote the original software. If you use this software 36 in a product, an acknowledgment in the product documentation would be 37 appreciated but is not required. 38 2. Altered source versions must be plainly marked as such, and must not be 39 misrepresented as being the original software. 40 3. This notice may not be removed or altered from any source distribution. 41 */ 42 43 /** 44 SDL Power Handling 45 46 See_Also: 47 $(LINK2 https://wiki.libsdl.org/SDL3/CategoryPower, SDL3 Mouse Documentation) 48 49 Copyright: © 2025 Inochi2D Project, © 1997-2025 Sam Lantinga 50 License: Subject to the terms of the Zlib License, as written in the LICENSE file. 51 Authors: 52 Luna Nielsen 53 */ 54 module sdl.power; 55 import sdl.stdc; 56 57 extern(C) nothrow @nogc: 58 59 enum SDL_PowerState { 60 61 /** 62 Error determining power status 63 */ 64 SDL_POWERSTATE_ERROR = -1, 65 66 /** 67 Cannot determine power status 68 */ 69 SDL_POWERSTATE_UNKNOWN, 70 71 /** 72 Not plugged in, running on the battery 73 */ 74 SDL_POWERSTATE_ON_BATTERY, 75 76 /** 77 Plugged in, no battery available 78 */ 79 SDL_POWERSTATE_NO_BATTERY, 80 81 /** 82 Plugged in, charging battery 83 */ 84 SDL_POWERSTATE_CHARGING, 85 86 /** 87 Plugged in, battery charged 88 */ 89 SDL_POWERSTATE_CHARGED 90 } 91 92 /** 93 Get the current power supply details. 94 95 You should never take a battery status as absolute truth. Batteries 96 (especially failing batteries) are delicate hardware, and the values 97 reported here are best estimates based on what that hardware reports. It's 98 not uncommon for older batteries to lose stored power much faster than it 99 reports, or completely drain when reporting it has 20 percent left, etc. 100 101 Battery status can change at any time; if you are concerned with power 102 state, you should call this function frequently, and perhaps ignore changes 103 until they seem to be stable for a few seconds. 104 105 It's possible a platform can only report battery percentage or time left 106 but not both. 107 108 Params: 109 seconds = a pointer filled in with the seconds of battery life left, 110 or NULL to ignore. This will be filled in with -1 if we 111 can't determine a value or there is no battery. 112 percent = a pointer filled in with the percentage of battery life 113 left, between 0 and 100, or NULL to ignore. This will be 114 filled in with -1 we can't determine a value or there is no 115 battery. 116 117 Returns: 118 The current battery state or `SDL_POWERSTATE_ERROR` on failure; 119 call SDL_GetError() for more information. 120 */ 121 extern SDL_PowerState SDL_GetPowerInfo(int *seconds, int *percent);