feat: ability to add multiple classes

This commit is contained in:
Alex 2019-04-15 10:18:27 +02:00
parent 57c99dc526
commit 6aee51479d
2 changed files with 17 additions and 14 deletions

View File

@ -26,8 +26,7 @@ class Custom : public ALabel {
std::string text_; std::string text_;
std::string alt_; std::string alt_;
std::string tooltip_; std::string tooltip_;
std::string class_; std::vector<std::string> class_;
std::string prevclass_;
int percentage_; int percentage_;
waybar::util::SleeperThread thread_; waybar::util::SleeperThread thread_;
waybar::util::command::res output_; waybar::util::command::res output_;

View File

@ -108,15 +108,12 @@ auto waybar::modules::Custom::update() -> void
label_.set_tooltip_text(tooltip_); label_.set_tooltip_text(tooltip_);
} }
} }
if (class_ != "") { auto classes = label_.get_style_context()->list_classes();
if (prevclass_ != "") { for (auto const &c : classes) {
label_.get_style_context()->remove_class(prevclass_); label_.get_style_context()->remove_class(c);
} }
label_.get_style_context()->add_class(class_); for (auto const &c : class_) {
prevclass_ = class_; label_.get_style_context()->add_class(c);
} else {
label_.get_style_context()->remove_class(prevclass_);
prevclass_ = "";
} }
event_box_.show(); event_box_.show();
@ -136,11 +133,11 @@ void waybar::modules::Custom::parseOutputRaw()
text_ = line; text_ = line;
} }
tooltip_ = line; tooltip_ = line;
class_ = ""; class_.clear();
} else if (i == 1) { } else if (i == 1) {
tooltip_ = line; tooltip_ = line;
} else if (i == 2) { } else if (i == 2) {
class_ = line; class_.push_back(line);
} else { } else {
break; break;
} }
@ -152,6 +149,7 @@ void waybar::modules::Custom::parseOutputJson()
{ {
std::istringstream output(output_.out); std::istringstream output(output_.out);
std::string line; std::string line;
class_.clear();
while (getline(output, line)) { while (getline(output, line)) {
auto parsed = parser_.parse(line); auto parsed = parser_.parse(line);
if (config_["escape"].isBool() && config_["escape"].asBool()) { if (config_["escape"].isBool() && config_["escape"].asBool()) {
@ -165,7 +163,13 @@ void waybar::modules::Custom::parseOutputJson()
alt_ = parsed["alt"].asString(); alt_ = parsed["alt"].asString();
} }
tooltip_ = parsed["tooltip"].asString(); tooltip_ = parsed["tooltip"].asString();
class_ = parsed["class"].asString(); if (parsed["class"].isString()) {
class_.push_back(parsed["class"].asString());
} else if (parsed["class"].isArray()) {
for (auto const &c : parsed["class"]) {
class_.push_back(c.asString());
}
}
if (!parsed["percentage"].asString().empty() && parsed["percentage"].isUInt()) { if (!parsed["percentage"].asString().empty() && parsed["percentage"].isUInt()) {
percentage_ = parsed["percentage"].asUInt(); percentage_ = parsed["percentage"].asUInt();
} else { } else {