mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Custom modules can control tooltip and CSS class
This commit is contained in:
parent
c3e185546d
commit
341d3300fa
@ -15,8 +15,13 @@ class Custom : public ALabel {
|
||||
private:
|
||||
void delayWorker();
|
||||
void continuousWorker();
|
||||
void parseOutput();
|
||||
|
||||
const std::string name_;
|
||||
std::string text_;
|
||||
std::string tooltip_;
|
||||
std::string class_;
|
||||
std::string prevclass_;
|
||||
waybar::util::SleeperThread thread_;
|
||||
waybar::util::command::res output_;
|
||||
};
|
||||
|
@ -72,9 +72,47 @@ auto waybar::modules::Custom::update() -> void
|
||||
label_.set_name("");
|
||||
} else {
|
||||
label_.set_name("custom-" + name_);
|
||||
auto str = fmt::format(format_, output_.out);
|
||||
|
||||
parseOutput();
|
||||
auto str = fmt::format(format_, text_);
|
||||
label_.set_text(str);
|
||||
if (text_ == tooltip_) {
|
||||
label_.set_tooltip_text(str);
|
||||
} else {
|
||||
label_.set_tooltip_text(tooltip_);
|
||||
}
|
||||
if (class_ != "") {
|
||||
if (prevclass_ != "") {
|
||||
label_.get_style_context()->remove_class(prevclass_);
|
||||
}
|
||||
label_.get_style_context()->add_class(class_);
|
||||
prevclass_ = class_;
|
||||
} else {
|
||||
label_.get_style_context()->remove_class(prevclass_);
|
||||
prevclass_ = "";
|
||||
}
|
||||
|
||||
label_.show();
|
||||
}
|
||||
}
|
||||
|
||||
void waybar::modules::Custom::parseOutput()
|
||||
{
|
||||
std::istringstream output(output_.out);
|
||||
std::string line;
|
||||
int i = 0;
|
||||
while (getline(output, line)) {
|
||||
if (i == 0) {
|
||||
text_ = line;
|
||||
tooltip_ = line;
|
||||
class_ = "";
|
||||
} else if (i == 1) {
|
||||
tooltip_ = line;
|
||||
} else if (i == 2) {
|
||||
class_ = line;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user