Added support for absolute device paths for the temperature module.

pull/624/head
BoostCookie 2020-03-12 22:04:00 +01:00
parent 4471d4aba1
commit 2f975f870a
2 changed files with 11 additions and 0 deletions

View File

@ -20,6 +20,14 @@ Addressed by *temperature*
typeof: string ++ typeof: string ++
The temperature path to use, e.g. */sys/class/hwmon/hwmon2/temp1_input* instead of one in */sys/class/thermal/*. The temperature path to use, e.g. */sys/class/hwmon/hwmon2/temp1_input* instead of one in */sys/class/thermal/*.
*hwmon-path-abs*: ++
typeof: string ++
The path of the hwmon-directory of the device, e.g. */sys/devices/pci0000:00/0000:00:18.3/hwmon*. (Note that the subdirectory *hwmon/hwmon#*, where *#* is a number is not part of the path!) Has to be used together with *input-filename*.
*input-filename*: ++
typeof: string ++
The temperature filename of your *hwmon-path-abs*, e.g. *temp1_input*
*critical-threshold*: ++ *critical-threshold*: ++
typeof: integer ++ typeof: integer ++
The threshold before it is considered critical (Celsius). The threshold before it is considered critical (Celsius).

View File

@ -1,9 +1,12 @@
#include "modules/temperature.hpp" #include "modules/temperature.hpp"
#include <filesystem>
waybar::modules::Temperature::Temperature(const std::string& id, const Json::Value& config) waybar::modules::Temperature::Temperature(const std::string& id, const Json::Value& config)
: ALabel(config, "temperature", id, "{temperatureC}°C", 10) { : ALabel(config, "temperature", id, "{temperatureC}°C", 10) {
if (config_["hwmon-path"].isString()) { if (config_["hwmon-path"].isString()) {
file_path_ = config_["hwmon-path"].asString(); file_path_ = config_["hwmon-path"].asString();
} else if (config_["hwmon-path-abs"].isString() && config_["input-filename"].isString()) {
file_path_ = (*std::filesystem::directory_iterator(config_["hwmon-path-abs"].asString())).path().u8string() + "/" + config_["input-filename"].asString();
} else { } else {
auto zone = config_["thermal-zone"].isInt() ? config_["thermal-zone"].asInt() : 0; auto zone = config_["thermal-zone"].isInt() ? config_["thermal-zone"].asInt() : 0;
file_path_ = fmt::format("/sys/class/thermal/thermal_zone{}/temp", zone); file_path_ = fmt::format("/sys/class/thermal/thermal_zone{}/temp", zone);