refactor(tooltip): migrate modules to ALabel generic tooltip helper

Migrate idle_inhibitor, sway/language, sway/scratchpad,
hyprland/language and hyprland/window to the shared label/tooltip
setters. idle_inhibitor uses updateLabelAndTooltipForState; the others
keep their custom label/tooltip resolution (trim, precomputed tooltip,
rewriteString, per-lang/variant formats) and switch to the dedup-aware
setLabelMarkup/setTooltipMarkup.
This commit is contained in:
Alex
2026-07-04 00:00:15 +02:00
parent a91dcbe595
commit db4941efe7
5 changed files with 25 additions and 33 deletions
+9 -9
View File
@@ -77,9 +77,9 @@ auto Language::update() -> void {
if (!format_.empty()) { if (!format_.empty()) {
label_.show(); label_.show();
label_.set_markup(layoutName); setLabelMarkup(layoutName);
if (tooltip_enabled) { if (tooltip_enabled) {
label_.set_tooltip_markup(tooltipContent); setTooltipMarkup(tooltipContent);
} }
} else { } else {
label_.hide(); label_.hide();
@@ -93,12 +93,11 @@ auto Language::update() -> void {
} else { } else {
tooltipFormat = "{long}"; tooltipFormat = "{long}";
} }
auto tooltipText = trim(fmt::format( auto tooltipText =
fmt::runtime(tooltipFormat), trim(fmt::format(fmt::runtime(tooltipFormat), fmt::arg("long", layout_.full_name),
fmt::arg("long", layout_.full_name), fmt::arg("short", layout_.short_name),
fmt::arg("short", layout_.short_name), fmt::arg("shortDescription", layout_.short_description),
fmt::arg("shortDescription", layout_.short_description), fmt::arg("variant", layout_.variant)));
fmt::arg("variant", layout_.variant)));
label_.set_tooltip_text(tooltipText); label_.set_tooltip_text(tooltipText);
} else { } else {
label_.set_tooltip_text(""); label_.set_tooltip_text("");
@@ -185,7 +184,8 @@ void Language::initLanguage() {
auto Language::removeXkbLayoutCssClass() -> void { auto Language::removeXkbLayoutCssClass() -> void {
label_.get_style_context()->remove_class(layout_.short_name); label_.get_style_context()->remove_class(layout_.short_name);
spdlog::debug("hyprland language try to remove currently short_name css class {}", layout_.short_name); spdlog::debug("hyprland language try to remove currently short_name css class {}",
layout_.short_name);
} }
auto Language::addXkbLayoutCssClass() -> void { auto Language::addXkbLayoutCssClass() -> void {
label_.get_style_context()->add_class(layout_.short_name); label_.get_style_context()->add_class(layout_.short_name);
+9 -10
View File
@@ -67,7 +67,7 @@ auto Window::update() -> void {
fmt::arg("class", windowData_.class_name), fmt::arg("class", windowData_.class_name),
fmt::arg("initialClass", windowData_.initial_class_name)), fmt::arg("initialClass", windowData_.initial_class_name)),
config_["rewrite"]); config_["rewrite"]);
label_.set_markup(label_text); setLabelMarkup(label_text);
} else { } else {
label_.hide(); label_.hide();
} }
@@ -78,13 +78,12 @@ auto Window::update() -> void {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();
} }
if (!tooltip_format.empty()) { if (!tooltip_format.empty()) {
label_.set_tooltip_markup( setTooltipMarkup(fmt::format(fmt::runtime(tooltip_format), fmt::arg("title", windowName),
fmt::format(fmt::runtime(tooltip_format), fmt::arg("title", windowName), fmt::arg("initialTitle", windowData_.initial_title),
fmt::arg("initialTitle", windowData_.initial_title), fmt::arg("class", windowData_.class_name),
fmt::arg("class", windowData_.class_name), fmt::arg("initialClass", windowData_.initial_class_name)));
fmt::arg("initialClass", windowData_.initial_class_name)));
} else if (!label_text.empty()) { } else if (!label_text.empty()) {
label_.set_tooltip_markup(label_text); setTooltipMarkup(label_text);
} }
} }
@@ -222,9 +221,9 @@ void Window::queryActiveWorkspace() {
std::vector<Json::Value> visibleWindows; std::vector<Json::Value> visibleWindows;
std::ranges::copy_if(workspaceWindows, std::back_inserter(visibleWindows), std::ranges::copy_if(workspaceWindows, std::back_inserter(visibleWindows),
[&](const Json::Value& window) { return !window["hidden"].asBool(); }); [&](const Json::Value& window) { return !window["hidden"].asBool(); });
solo_ = 1 == std::count_if( solo_ =
visibleWindows.begin(), visibleWindows.end(), 1 == std::count_if(visibleWindows.begin(), visibleWindows.end(),
[&](const Json::Value& window) { return !window["floating"].asBool(); }); [&](const Json::Value& window) { return !window["floating"].asBool(); });
allFloating_ = std::ranges::all_of( allFloating_ = std::ranges::all_of(
visibleWindows, [&](const Json::Value& window) { return window["floating"].asBool(); }); visibleWindows, [&](const Json::Value& window) { return window["floating"].asBool(); });
fullscreen_ = windowData_.fullscreen; fullscreen_ = windowData_.fullscreen;
+2 -9
View File
@@ -63,16 +63,9 @@ auto waybar::modules::IdleInhibitor::update() -> void {
} }
std::string status_text = status ? "activated" : "deactivated"; std::string status_text = status ? "activated" : "deactivated";
label_.set_markup(fmt::format(fmt::runtime(format_), fmt::arg("status", status_text), updateLabelAndTooltipForState(status_text, format_, "{status}", fmt::arg("status", status_text),
fmt::arg("icon", getIcon(0, status_text)))); fmt::arg("icon", getIcon(0, status_text)));
label_.get_style_context()->add_class(status_text); label_.get_style_context()->add_class(status_text);
if (tooltipEnabled()) {
auto config = config_[status ? "tooltip-format-activated" : "tooltip-format-deactivated"];
auto tooltip_format = config.isString() ? config.asString() : "{status}";
label_.set_tooltip_markup(fmt::format(fmt::runtime(tooltip_format),
fmt::arg("status", status_text),
fmt::arg("icon", getIcon(0, status_text))));
}
// Call parent update // Call parent update
ALabel::update(); ALabel::update();
} }
+3 -3
View File
@@ -124,7 +124,7 @@ auto Language::update() -> void {
fmt::runtime(format_), fmt::arg("short", layout_.short_name), fmt::runtime(format_), fmt::arg("short", layout_.short_name),
fmt::arg("shortDescription", layout_.short_description), fmt::arg("long", layout_.full_name), fmt::arg("shortDescription", layout_.short_description), fmt::arg("long", layout_.full_name),
fmt::arg("variant", layout_.variant), fmt::arg("flag", layout_.country_flag()))); fmt::arg("variant", layout_.variant), fmt::arg("flag", layout_.country_flag())));
label_.set_markup(display_layout); setLabelMarkup(display_layout);
if (tooltipEnabled()) { if (tooltipEnabled()) {
if (tooltip_format_ != "") { if (tooltip_format_ != "") {
auto tooltip_display_layout = trim( auto tooltip_display_layout = trim(
@@ -132,9 +132,9 @@ auto Language::update() -> void {
fmt::arg("shortDescription", layout_.short_description), fmt::arg("shortDescription", layout_.short_description),
fmt::arg("long", layout_.full_name), fmt::arg("variant", layout_.variant), fmt::arg("long", layout_.full_name), fmt::arg("variant", layout_.variant),
fmt::arg("flag", layout_.country_flag()))); fmt::arg("flag", layout_.country_flag())));
label_.set_tooltip_markup(tooltip_display_layout); setTooltipMarkup(tooltip_display_layout);
} else { } else {
label_.set_tooltip_markup(display_layout); setTooltipMarkup(display_layout);
} }
} }
+2 -2
View File
@@ -31,12 +31,12 @@ Scratchpad::Scratchpad(const std::string& id, const Json::Value& config)
auto Scratchpad::update() -> void { auto Scratchpad::update() -> void {
if (count_ || show_empty_) { if (count_ || show_empty_) {
event_box_.show(); event_box_.show();
label_.set_markup( setLabelMarkup(
fmt::format(fmt::runtime(format_), fmt::format(fmt::runtime(format_),
fmt::arg("icon", getIcon(count_, "", config_["format-icons"].size())), fmt::arg("icon", getIcon(count_, "", config_["format-icons"].size())),
fmt::arg("count", count_))); fmt::arg("count", count_)));
if (tooltip_enabled_) { if (tooltip_enabled_) {
label_.set_tooltip_markup(tooltip_text_); setTooltipMarkup(tooltip_text_);
} }
} else { } else {
event_box_.hide(); event_box_.hide();