Add test if there is battery
parent
45e44e03bd
commit
9d5f0e45c0
|
@ -6,7 +6,7 @@
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#endif
|
#endif
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
#if #defined(__linux__)
|
#if defined(__linux__)
|
||||||
#include <sys/inotify.h>
|
#include <sys/inotify.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -177,6 +177,17 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
|
||||||
uint32_t total_power = 0; // μW
|
uint32_t total_power = 0; // μW
|
||||||
bool total_power_exists = false;
|
bool total_power_exists = false;
|
||||||
#if defined(__FreeBSD__)
|
#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;
|
int capacity;
|
||||||
size_t size_capacity = sizeof capacity;
|
size_t size_capacity = sizeof capacity;
|
||||||
if (sysctlbyname("hw.acpi.battery.life", &capacity, &size_capacity, NULL,0) != 0) {
|
if (sysctlbyname("hw.acpi.battery.life", &capacity, &size_capacity, NULL,0) != 0) {
|
||||||
|
|
Loading…
Reference in New Issue