Merge pull request #4900 from AlisonB319/ab319/fix-hover-2

fix: sync tooltip updates without resetting hover state
This commit is contained in:
Alexis Rouillard
2026-03-04 22:42:16 +01:00
committed by GitHub
2 changed files with 14 additions and 7 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_;
std::string last_tooltip_markup_;
const bool tooltip_format_enabled_; const bool tooltip_format_enabled_;
std::vector<std::string> class_; std::vector<std::string> class_;
int percentage_; int percentage_;

View File

@@ -1,6 +1,7 @@
#include "modules/custom.hpp" #include "modules/custom.hpp"
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <utility>
#include "util/scope_guard.hpp" #include "util/scope_guard.hpp"
@@ -180,17 +181,22 @@ auto waybar::modules::Custom::update() -> void {
} else { } else {
label_.set_markup(str); label_.set_markup(str);
if (tooltipEnabled()) { if (tooltipEnabled()) {
std::string tooltip_markup;
if (tooltip_format_enabled_) { if (tooltip_format_enabled_) {
auto tooltip = config_["tooltip-format"].asString(); auto tooltip = config_["tooltip-format"].asString();
tooltip = fmt::format(fmt::runtime(tooltip), fmt::arg("text", text_), tooltip_markup = fmt::format(fmt::runtime(tooltip), fmt::arg("text", text_),
fmt::arg("tooltip", tooltip_), fmt::arg("alt", alt_), fmt::arg("tooltip", tooltip_), 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);
} else if (text_ == tooltip_) { } else if (text_ == tooltip_) {
label_.set_tooltip_markup(str); tooltip_markup = str;
} else { } else {
label_.set_tooltip_markup(tooltip_); tooltip_markup = tooltip_;
}
if (last_tooltip_markup_ != tooltip_markup) {
label_.set_tooltip_markup(tooltip_markup);
last_tooltip_markup_ = std::move(tooltip_markup);
} }
} }
auto style = label_.get_style_context(); auto style = label_.get_style_context();