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

Latest commit

 

History

History
86 lines (72 loc) · 2.71 KB

SDL_syspower.c

File metadata and controls

86 lines (72 loc) · 2.71 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Jan 24, 2010
Jan 24, 2010
3
Copyright (C) 1997-2010 Sam Lantinga
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
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)
Jan 24, 2011
Jan 24, 2011
35
36
37
#ifdef _WIN32_WCE
SYSTEM_POWER_STATUS_EX status;
#else
38
SYSTEM_POWER_STATUS status;
Jan 24, 2011
Jan 24, 2011
39
#endif
40
41
42
SDL_bool need_details = SDL_FALSE;
/* This API should exist back to Win95 and Windows CE. */
Jan 24, 2011
Jan 24, 2011
43
44
45
46
47
48
#ifdef _WIN32_WCE
if (!GetSystemPowerStatusEx(&status, FALSE))
#else
if (!GetSystemPowerStatus(&status))
#endif
{
49
50
/* !!! FIXME: push GetLastError() into SDL_GetError() */
*state = SDL_POWERSTATE_UNKNOWN;
Jun 10, 2009
Jun 10, 2009
51
} else if (status.BatteryFlag == 0xFF) { /* unknown state */
52
*state = SDL_POWERSTATE_UNKNOWN;
Jun 10, 2009
Jun 10, 2009
53
} else if (status.BatteryFlag & (1 << 7)) { /* no battery */
54
*state = SDL_POWERSTATE_NO_BATTERY;
Jun 10, 2009
Jun 10, 2009
55
} else if (status.BatteryFlag & (1 << 3)) { /* charging */
56
57
58
*state = SDL_POWERSTATE_CHARGING;
need_details = SDL_TRUE;
} else if (status.ACLineStatus == 1) {
Jun 10, 2009
Jun 10, 2009
59
*state = SDL_POWERSTATE_CHARGED; /* on AC, not charging. */
60
61
need_details = SDL_TRUE;
} else {
Jun 10, 2009
Jun 10, 2009
62
*state = SDL_POWERSTATE_ON_BATTERY; /* not on AC. */
63
64
65
66
67
68
69
70
71
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
72
73
if (pct != 255) { /* 255 == unknown */
*percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
Jun 10, 2009
Jun 10, 2009
75
if (secs != 0xFFFFFFFF) { /* ((DWORD)-1) == unknown */
76
77
78
79
*seconds = secs;
}
}
Jun 10, 2009
Jun 10, 2009
80
return SDL_TRUE; /* always the definitive answer on Windows. */
81
82
83
84
85
86
}
#endif /* SDL_POWER_WINDOWS */
#endif /* SDL_POWER_DISABLED */
/* vi: set ts=4 sw=4 expandtab: */