feat(temperature): format-icons
This commit is contained in:
parent
62f8af8a39
commit
fcb23d3104
|
@ -13,7 +13,7 @@ class ALabel : public IModule {
|
|||
ALabel(const Json::Value &, const std::string &format, uint16_t interval = 0);
|
||||
virtual ~ALabel();
|
||||
virtual auto update() -> void;
|
||||
virtual std::string getIcon(uint16_t, const std::string &alt = "");
|
||||
virtual std::string getIcon(uint16_t, const std::string &alt = "", uint16_t max = 0);
|
||||
virtual operator Gtk::Widget &();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -78,8 +78,9 @@
|
|||
// "thermal-zone": 2,
|
||||
// "hwmon-path": "/sys/class/hwmon/hwmon2/temp1_input",
|
||||
"critical-threshold": 80,
|
||||
// "format-critical": "{temperatureC}°C ",
|
||||
"format": "{temperatureC}°C "
|
||||
// "format-critical": "{temperatureC}°C {icon}",
|
||||
"format": "{temperatureC}°C {icon}",
|
||||
"format-icons": ["", "", ""]
|
||||
},
|
||||
"backlight": {
|
||||
// "device": "acpi_video1",
|
||||
|
|
|
@ -109,7 +109,7 @@ bool waybar::ALabel::handleScroll(GdkEventScroll* e) {
|
|||
return true;
|
||||
}
|
||||
|
||||
std::string waybar::ALabel::getIcon(uint16_t percentage, const std::string& alt) {
|
||||
std::string waybar::ALabel::getIcon(uint16_t percentage, const std::string& alt, uint16_t max) {
|
||||
auto format_icons = config_["format-icons"];
|
||||
if (format_icons.isObject()) {
|
||||
if (!alt.empty() && (format_icons[alt].isString() || format_icons[alt].isArray())) {
|
||||
|
@ -120,7 +120,7 @@ std::string waybar::ALabel::getIcon(uint16_t percentage, const std::string& alt)
|
|||
}
|
||||
if (format_icons.isArray()) {
|
||||
auto size = format_icons.size();
|
||||
auto idx = std::clamp(percentage / (100 / size), 0U, size - 1);
|
||||
auto idx = std::clamp(percentage / ((max == 0 ? 100 : max) / size), 0U, size - 1);
|
||||
format_icons = format_icons[idx];
|
||||
}
|
||||
if (format_icons.isString()) {
|
||||
|
@ -130,6 +130,9 @@ std::string waybar::ALabel::getIcon(uint16_t percentage, const std::string& alt)
|
|||
}
|
||||
|
||||
std::string waybar::ALabel::getState(uint8_t value) {
|
||||
if (!config_["states"].isObject()) {
|
||||
return "";
|
||||
}
|
||||
// Get current state
|
||||
std::vector<std::pair<std::string, uint8_t>> states;
|
||||
if (config_["states"].isObject()) {
|
||||
|
|
|
@ -32,8 +32,11 @@ auto waybar::modules::Temperature::update() -> void {
|
|||
} else {
|
||||
label_.get_style_context()->remove_class("critical");
|
||||
}
|
||||
label_.set_markup(fmt::format(
|
||||
format, fmt::arg("temperatureC", temperature_c), fmt::arg("temperatureF", temperature_f)));
|
||||
auto max_temp = config_["critical-threshold"].isInt() ? config_["critical-threshold"].asInt() : 0;
|
||||
label_.set_markup(fmt::format(format,
|
||||
fmt::arg("temperatureC", temperature_c),
|
||||
fmt::arg("temperatureF", temperature_f),
|
||||
fmt::arg("icon", getIcon(temperature_c, "", max_temp))));
|
||||
}
|
||||
|
||||
std::tuple<uint16_t, uint16_t> waybar::modules::Temperature::getTemperature() {
|
||||
|
|
Loading…
Reference in New Issue