Signed-off-by: Alex Henrie alexhenrie24@gmail.com --- dlls/kernel32/powermgnt.c | 72 +++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 10 deletions(-)
diff --git a/dlls/kernel32/powermgnt.c b/dlls/kernel32/powermgnt.c index 7efd84d410..1382f19c50 100644 --- a/dlls/kernel32/powermgnt.c +++ b/dlls/kernel32/powermgnt.c @@ -18,6 +18,8 @@ */
#include <stdarg.h> +#include <stdlib.h> +#include <unistd.h>
#define NONAMELESSUNION #define NONAMELESSSTRUCT @@ -45,19 +47,69 @@ BOOL WINAPI GetDevicePowerState(HANDLE hDevice, BOOL* pfOn) */ BOOL WINAPI GetSystemPowerStatus(LPSYSTEM_POWER_STATUS ps) { - WARN("(%p): stub, harmless.\n", ps); +#ifdef linux + FILE *f; + char s[16]; + BOOL unknown; +#endif + + TRACE("(%p)\n", ps); + + ps->ACLineStatus = AC_LINE_UNKNOWN; + ps->BatteryFlag = BATTERY_FLAG_UNKNOWN; + ps->BatteryLifePercent = BATTERY_PERCENTAGE_UNKNOWN; + ps->SystemStatusFlag = 0; + ps->BatteryLifeTime = BATTERY_LIFE_UNKNOWN; + ps->BatteryFullLifeTime = BATTERY_LIFE_UNKNOWN; + +#ifdef linux + if ((f = fopen("/sys/class/power_supply/AC/online", "r"))) + { + if (fgets(s, sizeof(s), f)) + ps->ACLineStatus = atoi(s); + fclose(f); + }
- if (ps) + if (access("/sys/class/power_supply/BAT0", F_OK) == -1) { - ps->ACLineStatus = 255; - ps->BatteryFlag = 255; - ps->BatteryLifePercent = 255; - ps->SystemStatusFlag = 0; - ps->BatteryLifeTime = ~0u; - ps->BatteryFullLifeTime = ~0u; - return TRUE; + ps->BatteryFlag = BATTERY_FLAG_NO_BATTERY; } - return FALSE; + else + { + ps->BatteryFlag = 0; + unknown = TRUE; + if ((f = fopen("/sys/class/power_supply/BAT0/capacity", "r"))) + { + if (fgets(s, sizeof(s), f)) + { + ps->BatteryLifePercent = atoi(s); + if (ps->BatteryLifePercent > 66) + ps->BatteryFlag |= BATTERY_FLAG_HIGH; + if (ps->BatteryLifePercent < 33) + ps->BatteryFlag |= BATTERY_FLAG_LOW; + if (ps->BatteryLifePercent < 5) + ps->BatteryFlag |= BATTERY_FLAG_CRITICAL; + unknown = FALSE; + } + fclose(f); + } + if ((f = fopen("/sys/class/power_supply/BAT0/status", "r"))) + { + if (fgets(s, sizeof(s), f)) + { + if (strcmp(s, "Charging") == 0) + ps->BatteryFlag |= BATTERY_FLAG_CHARGING; + unknown = FALSE; + } + fclose(f); + } + if (unknown) ps->BatteryFlag = BATTERY_FLAG_UNKNOWN; + } +#else + FIXME("Not implemented on this platform\n"); +#endif + + return TRUE; }
/***********************************************************************