Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/ALabel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <fmt/format.h>
#include <glibmm/markup.h>
#include <gtkmm/label.h>
#include <gtkmm/tooltip.h>
#include <json/json.h>

#include <optional>
Expand Down Expand Up @@ -92,6 +93,7 @@ class ALabel : public AModule {
// no collation weight, so two different icons compare equal.
std::optional<std::string> last_label_markup_;
std::optional<std::string> last_tooltip_markup_;
Glib::RefPtr<Gtk::Tooltip> active_tooltip_;
};

} // namespace waybar
24 changes: 23 additions & 1 deletion src/ALabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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()) {
label_.set_max_width_chars(config_["max-length"].asInt());
label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END);
Expand Down Expand Up @@ -162,8 +182,10 @@ bool ALabel::setTooltipMarkup(const Glib::ustring& markup) {
return false;
}

label_.set_tooltip_markup(markup);
last_tooltip_markup_ = markup.raw();
if (active_tooltip_) {
active_tooltip_->set_markup(markup);
}
return true;
}

Expand Down
Loading