Signed-off-by: Alex Henrie alexhenrie24@gmail.com --- dlls/kernel32/powermgnt.c | 46 +++++++++++++++++++++++++++++-------- dlls/kernel32/tests/power.c | 1 - 2 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/dlls/kernel32/powermgnt.c b/dlls/kernel32/powermgnt.c index 7efd84d410..13e7e391de 100644 --- a/dlls/kernel32/powermgnt.c +++ b/dlls/kernel32/powermgnt.c @@ -45,19 +45,45 @@ BOOL WINAPI GetDevicePowerState(HANDLE hDevice, BOOL* pfOn) */ BOOL WINAPI GetSystemPowerStatus(LPSYSTEM_POWER_STATUS ps) { - WARN("(%p): stub, harmless.\n", ps); + SYSTEM_BATTERY_STATE bs;
- if (ps) + 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; + + if (FAILED(NtPowerInformation(SystemBatteryState, NULL, 0, &bs, sizeof(bs)))) + return FALSE; + + ps->ACLineStatus = bs.AcOnLine; + + if (bs.BatteryPresent) { - ps->ACLineStatus = 255; - ps->BatteryFlag = 255; - ps->BatteryLifePercent = 255; - ps->SystemStatusFlag = 0; - ps->BatteryLifeTime = ~0u; - ps->BatteryFullLifeTime = ~0u; - return TRUE; + ps->BatteryLifePercent = bs.MaxCapacity ? bs.RemainingCapacity / bs.MaxCapacity : 100; + ps->BatteryLifeTime = bs.EstimatedTime; + if (!bs.Charging && (LONG)bs.Rate < 0) + ps->BatteryFullLifeTime = 3600 * bs.MaxCapacity / -(LONG)bs.Rate; + + ps->BatteryFlag = 0; + if (bs.Charging) + ps->BatteryFlag |= BATTERY_FLAG_CHARGING; + 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; } - return FALSE; + else + { + ps->BatteryFlag = BATTERY_FLAG_NO_BATTERY; + } + + return TRUE; }
/*********************************************************************** diff --git a/dlls/kernel32/tests/power.c b/dlls/kernel32/tests/power.c index ae5ce980c2..74a16537e1 100644 --- a/dlls/kernel32/tests/power.c +++ b/dlls/kernel32/tests/power.c @@ -44,7 +44,6 @@ void test_GetSystemPowerStatus(void) if (ps.BatteryLifePercent < 5) expected_capacity_flags |= BATTERY_FLAG_CRITICAL; capacity_flags = (ps.BatteryFlag & ~BATTERY_FLAG_CHARGING); -todo_wine ok(capacity_flags == expected_capacity_flags, "expected %u%%-charged battery to have capacity flags 0x%02x, got 0x%02x\n", ps.BatteryLifePercent, expected_capacity_flags, capacity_flags);