Merge pull request #5212 from bjnobre/fix/dynamic-tooltip-updates

fix(tooltips): keep dynamic tooltips from resetting hover delay
This commit is contained in:
Alexis Rouillard
2026-07-21 21:13:14 +02:00
committed by GitHub
2 changed files with 25 additions and 1 deletions
+2
View File
@@ -4,6 +4,7 @@
#include <fmt/format.h> #include <fmt/format.h>
#include <glibmm/markup.h> #include <glibmm/markup.h>
#include <gtkmm/label.h> #include <gtkmm/label.h>
#include <gtkmm/tooltip.h>
#include <json/json.h> #include <json/json.h>
#include <optional> #include <optional>
@@ -92,6 +93,7 @@ class ALabel : public AModule {
// no collation weight, so two different icons compare equal. // no collation weight, so two different icons compare equal.
std::optional<std::string> last_label_markup_; std::optional<std::string> last_label_markup_;
std::optional<std::string> last_tooltip_markup_; std::optional<std::string> last_tooltip_markup_;
Glib::RefPtr<Gtk::Tooltip> active_tooltip_;
}; };
} // namespace waybar } // namespace waybar
+23 -1
View File
@@ -42,6 +42,26 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st
} }
label_.get_style_context()->add_class(MODULE_CLASS); label_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(label_); event_box_.add(label_);
if (tooltipEnabled()) {
// Keep dynamic tooltip contents out of GtkWidget's tooltip-markup property.
// Setting that property queues a display-wide tooltip query, which restarts
// GTK's hover delay when modules update faster than the delay can expire.
label_.set_has_tooltip(true);
label_.signal_query_tooltip().connect(
[this](int, int, bool, const Glib::RefPtr<Gtk::Tooltip>& tooltip) {
if (!last_tooltip_markup_.has_value() || last_tooltip_markup_->empty()) {
active_tooltip_.reset();
return false;
}
active_tooltip_ = tooltip;
tooltip->set_markup(*last_tooltip_markup_);
return true;
});
event_box_.signal_leave_notify_event().connect([this](GdkEventCrossing*) {
active_tooltip_.reset();
return false;
});
}
if (config_["max-length"].isUInt()) { if (config_["max-length"].isUInt()) {
label_.set_max_width_chars(config_["max-length"].asInt()); label_.set_max_width_chars(config_["max-length"].asInt());
label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END); label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END);
@@ -162,8 +182,10 @@ bool ALabel::setTooltipMarkup(const Glib::ustring& markup) {
return false; return false;
} }
label_.set_tooltip_markup(markup);
last_tooltip_markup_ = markup.raw(); last_tooltip_markup_ = markup.raw();
if (active_tooltip_) {
active_tooltip_->set_markup(markup);
}
return true; return true;
} }