fix(#3210): tooltip-format on custom modules not working in some cases (#3213)

master
Lars-Ragnar A. Haugen 2024-05-06 10:47:52 +02:00 committed by GitHub
parent 8e8ce0c6bc
commit a453ea3c70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View File

@ -35,6 +35,7 @@ class Custom : public ALabel {
std::string id_; std::string id_;
std::string alt_; std::string alt_;
std::string tooltip_; std::string tooltip_;
const bool tooltip_format_enabled_;
std::vector<std::string> class_; std::vector<std::string> class_;
int percentage_; int percentage_;
FILE* fp_; FILE* fp_;

View File

@ -10,6 +10,7 @@ waybar::modules::Custom::Custom(const std::string& name, const std::string& id,
name_(name), name_(name),
output_name_(output_name), output_name_(output_name),
id_(id), id_(id),
tooltip_format_enabled_{config_["tooltip-format"].isString()},
percentage_(0), percentage_(0),
fp_(nullptr), fp_(nullptr),
pid_(-1) { pid_(-1) {
@ -166,16 +167,16 @@ auto waybar::modules::Custom::update() -> void {
} else { } else {
label_.set_markup(str); label_.set_markup(str);
if (tooltipEnabled()) { if (tooltipEnabled()) {
if (text_ == tooltip_) { if (tooltip_format_enabled_) {
if (label_.get_tooltip_markup() != str) {
label_.set_tooltip_markup(str);
}
} else if (config_["tooltip-format"].isString()) {
auto tooltip = config_["tooltip-format"].asString(); auto tooltip = config_["tooltip-format"].asString();
tooltip = fmt::format(fmt::runtime(tooltip), text_, fmt::arg("alt", alt_), tooltip = fmt::format(fmt::runtime(tooltip), text_, fmt::arg("alt", alt_),
fmt::arg("icon", getIcon(percentage_, alt_)), fmt::arg("icon", getIcon(percentage_, alt_)),
fmt::arg("percentage", percentage_)); fmt::arg("percentage", percentage_));
label_.set_tooltip_markup(tooltip); label_.set_tooltip_markup(tooltip);
} else if (text_ == tooltip_) {
if (label_.get_tooltip_markup() != str) {
label_.set_tooltip_markup(str);
}
} else { } else {
if (label_.get_tooltip_markup() != tooltip_) { if (label_.get_tooltip_markup() != tooltip_) {
label_.set_tooltip_markup(tooltip_); label_.set_tooltip_markup(tooltip_);