Merge remote-tracking branch 'origin/master' into wp_scales
This commit is contained in:
@@ -41,6 +41,9 @@ auto waybar::modules::Cpu::update() -> void {
|
||||
auto icons = std::vector<std::string>{state};
|
||||
fmt::dynamic_format_arg_store<fmt::format_context> store;
|
||||
store.push_back(fmt::arg("load", load1));
|
||||
store.push_back(fmt::arg("load1", load1));
|
||||
store.push_back(fmt::arg("load5", load5));
|
||||
store.push_back(fmt::arg("load15", load15));
|
||||
store.push_back(fmt::arg("usage", total_usage));
|
||||
store.push_back(fmt::arg("icon", getIcon(total_usage, icons)));
|
||||
store.push_back(fmt::arg("max_frequency", max_frequency));
|
||||
|
||||
@@ -20,6 +20,24 @@ waybar::modules::Temperature::Temperature(const std::string& id, const Json::Val
|
||||
if (check_set_path(item.asString())) break;
|
||||
};
|
||||
|
||||
auto find_hwmon_by_name = [](const std::string& name) -> std::optional<std::filesystem::path> {
|
||||
for (const auto& entry : std::filesystem::directory_iterator("/sys/class/hwmon")) {
|
||||
std::ifstream f(entry.path() / "name");
|
||||
std::string hwname;
|
||||
if (f >> hwname && hwname == name) {
|
||||
return entry.path();
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
};
|
||||
|
||||
// ensure either hwmon-name OR old paths are used, not both
|
||||
if (config_["hwmon-name"].isString() &&
|
||||
(!config_["hwmon-path"].isNull() || !config_["hwmon-path-abs"].isNull())) {
|
||||
throw std::runtime_error(
|
||||
"hwmon-name cannot be used together with hwmon-path or hwmon-path-abs");
|
||||
}
|
||||
|
||||
// if hwmon_path is an array, loop to find first valid item
|
||||
traverseAsArray(config_["hwmon-path"], [this](const std::string& path) {
|
||||
if (!std::filesystem::exists(path)) return false;
|
||||
@@ -40,6 +58,20 @@ waybar::modules::Temperature::Temperature(const std::string& id, const Json::Val
|
||||
});
|
||||
}
|
||||
|
||||
if (file_path_.empty() && config_["hwmon-name"].isString()) {
|
||||
if (!config_["input-filename"].isString()) {
|
||||
throw std::runtime_error("hwmon-name requires input-filename to be set");
|
||||
}
|
||||
|
||||
auto hwmon = find_hwmon_by_name(config_["hwmon-name"].asString());
|
||||
|
||||
if (!hwmon) {
|
||||
throw std::runtime_error("hwmon-name '" + config_["hwmon-name"].asString() + "' not found");
|
||||
}
|
||||
|
||||
file_path_ = hwmon->string() + "/" + config_["input-filename"].asString();
|
||||
}
|
||||
|
||||
if (file_path_.empty()) {
|
||||
auto zone = config_["thermal-zone"].isInt() ? config_["thermal-zone"].asInt() : 0;
|
||||
file_path_ = fmt::format("/sys/class/thermal/thermal_zone{}/temp", zone);
|
||||
|
||||
Reference in New Issue
Block a user