From a453ea3c70195803e9962a97f9243c0c78d4ecdc Mon Sep 17 00:00:00 2001 From: "Lars-Ragnar A. Haugen" <31956036+haug1@users.noreply.github.com> Date: Mon, 6 May 2024 10:47:52 +0200 Subject: [PATCH] fix(#3210): tooltip-format on custom modules not working in some cases (#3213) --- include/modules/custom.hpp | 1 + src/modules/custom.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/modules/custom.hpp b/include/modules/custom.hpp index 2c7ba8a8..6c17c6e4 100644 --- a/include/modules/custom.hpp +++ b/include/modules/custom.hpp @@ -35,6 +35,7 @@ class Custom : public ALabel { std::string id_; std::string alt_; std::string tooltip_; + const bool tooltip_format_enabled_; std::vector class_; int percentage_; FILE* fp_; diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index ec3bb3fa..45e849cc 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -10,6 +10,7 @@ waybar::modules::Custom::Custom(const std::string& name, const std::string& id, name_(name), output_name_(output_name), id_(id), + tooltip_format_enabled_{config_["tooltip-format"].isString()}, percentage_(0), fp_(nullptr), pid_(-1) { @@ -166,16 +167,16 @@ auto waybar::modules::Custom::update() -> void { } else { label_.set_markup(str); if (tooltipEnabled()) { - if (text_ == tooltip_) { - if (label_.get_tooltip_markup() != str) { - label_.set_tooltip_markup(str); - } - } else if (config_["tooltip-format"].isString()) { + if (tooltip_format_enabled_) { auto tooltip = config_["tooltip-format"].asString(); tooltip = fmt::format(fmt::runtime(tooltip), text_, fmt::arg("alt", alt_), fmt::arg("icon", getIcon(percentage_, alt_)), fmt::arg("percentage", percentage_)); label_.set_tooltip_markup(tooltip); + } else if (text_ == tooltip_) { + if (label_.get_tooltip_markup() != str) { + label_.set_tooltip_markup(str); + } } else { if (label_.get_tooltip_markup() != tooltip_) { label_.set_tooltip_markup(tooltip_);