diff --git a/configure.ac b/configure.ac index 4fdb1ef33df..3abc230c2d5 100644 --- a/configure.ac +++ b/configure.ac @@ -434,6 +434,7 @@ AC_CHECK_HEADERS(\ arpa/nameser.h \ asm/types.h \ asm/user.h \ + dev/acpica/acpiio.h \ dirent.h \ elf.h \ float.h \ diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c index 941c69190fb..76cfe30b5be 100644 --- a/dlls/ntdll/unix/system.c +++ b/dlls/ntdll/unix/system.c @@ -69,6 +69,9 @@ # include # include #endif +#ifdef HAVE_DEV_ACPICA_ACPIIO_H +# include +#endif #define NONAMELESSUNION #include "ntstatus.h" @@ -3516,6 +3519,49 @@ static NTSTATUS fill_battery_state( SYSTEM_BATTERY_STATE *bs ) return STATUS_SUCCESS; } +#elif defined(__FreeBSD__) + +static NTSTATUS fill_battery_state( SYSTEM_BATTERY_STATE *bs ) +{ + size_t len; + int state = 0; + int rate_mW = 0; + int time_mins = -1; + int life_percent = 0; + + bs->BatteryPresent = TRUE; + len = sizeof(state); + bs->BatteryPresent &= !sysctlbyname("hw.acpi.battery.state", &state, &len, NULL, 0); + len = sizeof(rate_mW); + bs->BatteryPresent &= !sysctlbyname("hw.acpi.battery.rate", &rate_mW, &len, NULL, 0); + len = sizeof(time_mins); + bs->BatteryPresent &= !sysctlbyname("hw.acpi.battery.time", &time_mins, &len, NULL, 0); + len = sizeof(life_percent); + bs->BatteryPresent &= !sysctlbyname("hw.acpi.battery.life", &life_percent, &len, NULL, 0); + + if (bs->BatteryPresent) + { + bs->AcOnLine = (time_mins == -1); + bs->Charging = state & ACPI_BATT_STAT_CHARGING; + bs->Discharging = state & ACPI_BATT_STAT_DISCHARG; + + bs->Rate = (rate_mW >= 0 ? -rate_mW : 0); + if (time_mins >= 0 && life_percent > 0) + { + bs->EstimatedTime = 60 * time_mins; + bs->RemainingCapacity = bs->EstimatedTime * rate_mW / 3600; + bs->MaxCapacity = bs->RemainingCapacity * 100 / life_percent; + } + else + { + bs->EstimatedTime = ~0u; + bs->RemainingCapacity = life_percent; + bs->MaxCapacity = 100; + } + } + return STATUS_SUCCESS; +} + #else static NTSTATUS fill_battery_state( SYSTEM_BATTERY_STATE *bs ) diff --git a/include/config.h.in b/include/config.h.in index a0165765a85..9e650c04f7f 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -49,6 +49,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_CUPS_PPD_H +/* Define to 1 if you have the header file. */ +#undef HAVE_DEV_ACPICA_ACPIIO_H + /* Define to 1 if you have the header file. */ #undef HAVE_DIRENT_H