Merge pull request #129 from Robinhuett/custom-module-icon

Add format-icons to custom module
This commit is contained in:
Alex 2018-12-26 11:42:25 +01:00 committed by GitHub
commit 513278597a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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_;

View File

@ -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;
}
}