From c3e91cd228bc7625985ff25c33bffc5c9dbcdc72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bartoletti?= Date: Tue, 4 Oct 2022 07:29:16 +0200 Subject: [PATCH 1/4] [FreeBSD] Use thermal-zone The zone was hardcoded in #1702. This commit allows to use the "thermal-zone" variable. Follow up #1702 --- src/modules/temperature.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/temperature.cpp b/src/modules/temperature.cpp index eea1198e..80584dad 100644 --- a/src/modules/temperature.cpp +++ b/src/modules/temperature.cpp @@ -81,8 +81,11 @@ float waybar::modules::Temperature::getTemperature() { int temp; size_t size = sizeof temp; - if (sysctlbyname("hw.acpi.thermal.tz0.temperature", &temp, &size, NULL, 0) != 0) { - throw std::runtime_error("sysctl hw.acpi.thermal.tz0.temperature or dev.cpu.0.temperature failed"); + auto zone = config_["thermal-zone"].isInt() ? config_["thermal-zone"].asInt() : 0; + auto sysctl_thermal = fmt::format("hw.acpi.thermal.tz{}.temperature", zone); + + if (sysctlbyname(sysctl_thermal.c_str(), &temp, &size, NULL, 0) != 0) { + throw std::runtime_error(fmt::format("sysctl {} failed",sysctl_thermal)); } auto temperature_c = ((float)temp-2732)/10; return temperature_c; From 089823658664f2ec15f9a6dd31a851ad879dcf99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bartoletti?= Date: Tue, 4 Oct 2022 07:37:05 +0200 Subject: [PATCH 2/4] remove useless include --- src/modules/temperature.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/temperature.cpp b/src/modules/temperature.cpp index 80584dad..de41753e 100644 --- a/src/modules/temperature.cpp +++ b/src/modules/temperature.cpp @@ -4,7 +4,6 @@ #if defined(__FreeBSD__) // clang-format off -#include #include // clang-format on #endif From 1ca660460a44dd4d781a214daa29e6ba7c95247c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bartoletti?= Date: Tue, 4 Oct 2022 08:03:54 +0200 Subject: [PATCH 3/4] apply clang-format --- src/modules/temperature.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/modules/temperature.cpp b/src/modules/temperature.cpp index de41753e..3178c12b 100644 --- a/src/modules/temperature.cpp +++ b/src/modules/temperature.cpp @@ -10,7 +10,6 @@ waybar::modules::Temperature::Temperature(const std::string& id, const Json::Value& config) : ALabel(config, "temperature", id, "{temperatureC}°C", 10) { - #if defined(__FreeBSD__) // try to read sysctl? #else @@ -84,12 +83,12 @@ float waybar::modules::Temperature::getTemperature() { auto sysctl_thermal = fmt::format("hw.acpi.thermal.tz{}.temperature", zone); if (sysctlbyname(sysctl_thermal.c_str(), &temp, &size, NULL, 0) != 0) { - throw std::runtime_error(fmt::format("sysctl {} failed",sysctl_thermal)); + throw std::runtime_error(fmt::format("sysctl {} failed", sysctl_thermal)); } - auto temperature_c = ((float)temp-2732)/10; + auto temperature_c = ((float)temp - 2732) / 10; return temperature_c; -#else // Linux +#else // Linux std::ifstream temp(file_path_); if (!temp.is_open()) { throw std::runtime_error("Can't open " + file_path_); From ddf3e112401b0da2d34d8113bab48881e3ec5662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bartoletti?= Date: Tue, 4 Oct 2022 11:28:32 +0200 Subject: [PATCH 4/4] remove clang-format lines --- src/modules/temperature.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/modules/temperature.cpp b/src/modules/temperature.cpp index 3178c12b..243cbcc9 100644 --- a/src/modules/temperature.cpp +++ b/src/modules/temperature.cpp @@ -3,9 +3,7 @@ #include #if defined(__FreeBSD__) -// clang-format off #include -// clang-format on #endif waybar::modules::Temperature::Temperature(const std::string& id, const Json::Value& config)