From 0ada5ac8b06e1962f9368758b0d114a1ce52a22f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bartoletti?= Date: Tue, 4 Oct 2022 06:39:29 +0200 Subject: [PATCH] Battery::getAdapterStatus: better code format --- src/modules/battery.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 5f4734c1..143cc1b0 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -535,7 +535,15 @@ const std::tuple waybar::modules::Battery::g } const std::string waybar::modules::Battery::getAdapterStatus(uint8_t capacity) const { -#if defined(__linux__) +#if defined(__FreeBSD__) + int state; + size_t size_state = sizeof state; + if (sysctlbyname("hw.acpi.battery.state", &state, &size_state, NULL,0) != 0) { + throw std::runtime_error("sysctl hw.acpi.battery.state failed"); + } + bool online = state == 2; + { +#else if (!adapter_.empty()) { bool online; std::string status; @@ -556,9 +564,7 @@ const std::string waybar::modules::Battery::getAdapterStatus(uint8_t capacity) c return "Plugged"; } return "Discharging"; -#if defined(__linux__) } -#endif return "Unknown"; }