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] [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;