diff --git a/include/modules/custom.hpp b/include/modules/custom.hpp index 937ab76f..074ed04a 100644 --- a/include/modules/custom.hpp +++ b/include/modules/custom.hpp @@ -25,6 +25,7 @@ class Custom : public ALabel { std::string tooltip_; std::string class_; std::string prevclass_; + int percentage_; waybar::util::SleeperThread thread_; waybar::util::command::res output_; waybar::util::JsonParser parser_; diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 68d98462..c75760dd 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -87,7 +87,9 @@ auto waybar::modules::Custom::update() -> void parseOutputRaw(); } - auto str = fmt::format(format_, text_); + auto str = fmt::format(format_, text_, + fmt::arg("icon", getIcon(percentage_)), + fmt::arg("percentage", percentage_)); label_.set_markup(str); if (text_ == tooltip_) { label_.set_tooltip_text(str); @@ -139,6 +141,11 @@ void waybar::modules::Custom::parseOutputJson() text_ = parsed["text"].asString(); tooltip_ = parsed["tooltip"].asString(); class_ = parsed["class"].asString(); + if (!parsed["percentage"].asString().empty() && parsed["percentage"].isUInt()) { + percentage_ = parsed["percentage"].asUInt(); + } else { + percentage_ = 0; + } break; } }