Merge branch 'master' into issue-1681

This commit is contained in:
Alexis Rouillard
2023-07-04 22:49:35 +02:00
committed by GitHub
174 changed files with 6310 additions and 1503 deletions

View File

@ -4,7 +4,7 @@
waybar::modules::Custom::Custom(const std::string& name, const std::string& id,
const Json::Value& config)
: AButton(config, "custom-" + name, id, "{}"),
: ALabel(config, "custom-" + name, id, "{}"),
name_(name),
id_(id),
percentage_(0),
@ -21,6 +21,7 @@ waybar::modules::Custom::Custom(const std::string& name, const std::string& id,
waybar::modules::Custom::~Custom() {
if (pid_ != -1) {
killpg(pid_, SIGTERM);
waitpid(pid_, NULL, 0);
pid_ = -1;
}
}
@ -95,6 +96,7 @@ void waybar::modules::Custom::continuousWorker() {
output_ = {0, output};
dp.emit();
}
free(buff);
};
}
@ -111,13 +113,13 @@ void waybar::modules::Custom::handleEvent() {
}
bool waybar::modules::Custom::handleScroll(GdkEventScroll* e) {
auto ret = AButton::handleScroll(e);
auto ret = ALabel::handleScroll(e);
handleEvent();
return ret;
}
bool waybar::modules::Custom::handleToggle(GdkEventButton* const& e) {
auto ret = AButton::handleToggle(e);
auto ret = ALabel::handleToggle(e);
handleEvent();
return ret;
}
@ -133,39 +135,39 @@ auto waybar::modules::Custom::update() -> void {
} else {
parseOutputRaw();
}
auto str = fmt::format(format_, text_, fmt::arg("alt", alt_),
auto str = fmt::format(fmt::runtime(format_), text_, fmt::arg("alt", alt_),
fmt::arg("icon", getIcon(percentage_, alt_)),
fmt::arg("percentage", percentage_));
if (str.empty()) {
event_box_.hide();
} else {
label_->set_markup(str);
label_.set_markup(str);
if (tooltipEnabled()) {
if (text_ == tooltip_) {
if (button_.get_tooltip_markup() != str) {
button_.set_tooltip_markup(str);
if (label_.get_tooltip_markup() != str) {
label_.set_tooltip_markup(str);
}
} else {
if (button_.get_tooltip_markup() != tooltip_) {
button_.set_tooltip_markup(tooltip_);
if (label_.get_tooltip_markup() != tooltip_) {
label_.set_tooltip_markup(tooltip_);
}
}
}
auto classes = button_.get_style_context()->list_classes();
auto classes = label_.get_style_context()->list_classes();
for (auto const& c : classes) {
if (c == id_) continue;
button_.get_style_context()->remove_class(c);
label_.get_style_context()->remove_class(c);
}
for (auto const& c : class_) {
button_.get_style_context()->add_class(c);
label_.get_style_context()->add_class(c);
}
button_.get_style_context()->add_class("flat");
button_.get_style_context()->add_class("text-button");
label_.get_style_context()->add_class("flat");
label_.get_style_context()->add_class("text-button");
event_box_.show();
}
}
// Call parent update
AButton::update();
ALabel::update();
}
void waybar::modules::Custom::parseOutputRaw() {
@ -216,8 +218,8 @@ void waybar::modules::Custom::parseOutputJson() {
class_.push_back(c.asString());
}
}
if (!parsed["percentage"].asString().empty() && parsed["percentage"].isUInt()) {
percentage_ = parsed["percentage"].asUInt();
if (!parsed["percentage"].asString().empty() && parsed["percentage"].isNumeric()) {
percentage_ = (int)lround(parsed["percentage"].asFloat());
} else {
percentage_ = 0;
}