Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
77 lines (63 loc) · 2.56 KB

SDL_syspower.c

File metadata and controls

77 lines (63 loc) · 2.56 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2009 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#ifndef SDL_POWER_DISABLED
#ifdef SDL_POWER_WINDOWS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "SDL_power.h"
SDL_bool
Jun 10, 2009
Jun 10, 2009
33
SDL_GetPowerInfo_Windows(SDL_PowerState * state, int *seconds, int *percent)
34
35
36
37
38
39
40
41
{
SYSTEM_POWER_STATUS status;
SDL_bool need_details = SDL_FALSE;
/* This API should exist back to Win95 and Windows CE. */
if (!GetSystemPowerStatus(&status)) {
/* !!! FIXME: push GetLastError() into SDL_GetError() */
*state = SDL_POWERSTATE_UNKNOWN;
Jun 10, 2009
Jun 10, 2009
42
} else if (status.BatteryFlag == 0xFF) { /* unknown state */
43
*state = SDL_POWERSTATE_UNKNOWN;
Jun 10, 2009
Jun 10, 2009
44
} else if (status.BatteryFlag & (1 << 7)) { /* no battery */
45
*state = SDL_POWERSTATE_NO_BATTERY;
Jun 10, 2009
Jun 10, 2009
46
} else if (status.BatteryFlag & (1 << 3)) { /* charging */
47
48
49
*state = SDL_POWERSTATE_CHARGING;
need_details = SDL_TRUE;
} else if (status.ACLineStatus == 1) {
Jun 10, 2009
Jun 10, 2009
50
*state = SDL_POWERSTATE_CHARGED; /* on AC, not charging. */
51
52
need_details = SDL_TRUE;
} else {
Jun 10, 2009
Jun 10, 2009
53
*state = SDL_POWERSTATE_ON_BATTERY; /* not on AC. */
54
55
56
57
58
59
60
61
62
need_details = SDL_TRUE;
}
*percent = -1;
*seconds = -1;
if (need_details) {
const int pct = (int) status.BatteryLifePercent;
const int secs = (int) status.BatteryLifeTime;
Jun 10, 2009
Jun 10, 2009
63
64
if (pct != 255) { /* 255 == unknown */
*percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
Jun 10, 2009
Jun 10, 2009
66
if (secs != 0xFFFFFFFF) { /* ((DWORD)-1) == unknown */
67
68
69
70
*seconds = secs;
}
}
Jun 10, 2009
Jun 10, 2009
71
return SDL_TRUE; /* always the definitive answer on Windows. */
72
73
74
75
76
77
}
#endif /* SDL_POWER_WINDOWS */
#endif /* SDL_POWER_DISABLED */
/* vi: set ts=4 sw=4 expandtab: */