diff --git a/include/modules/battery.hpp b/include/modules/battery.hpp index 42cf1647..614b36ab 100644 --- a/include/modules/battery.hpp +++ b/include/modules/battery.hpp @@ -6,7 +6,7 @@ #include #endif #include -#if #defined(__linux__) +#if defined(__linux__) #include #endif diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 13a49208..a4657409 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -177,6 +177,17 @@ const std::tuple waybar::modules::Battery::g uint32_t total_power = 0; // μW bool total_power_exists = false; #if defined(__FreeBSD__) + /* Allocate state of battery units reported via ACPI. */ + int battery_units = 0; + size_t battery_units_size = sizeof battery_units; + if( sysctlbyname("hw.acpi.battery.units", &battery_units, &battery_units_size, NULL, 0) != 0) { + throw std::runtime_error("sysctl hw.acpi.battery.units failed"); + } + + if(battery_units < 0) { + throw std::runtime_error("No battery units"); + } + int capacity; size_t size_capacity = sizeof capacity; if (sysctlbyname("hw.acpi.battery.life", &capacity, &size_capacity, NULL,0) != 0) {