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
+6 -6
View File
@@ -77,9 +77,9 @@ auto Language::update() -> void {
if (!format_.empty()) {
label_.show();
label_.set_markup(layoutName);
setLabelMarkup(layoutName);
if (tooltip_enabled) {
label_.set_tooltip_markup(tooltipContent);
setTooltipMarkup(tooltipContent);
}
} else {
label_.hide();
@@ -93,9 +93,8 @@ auto Language::update() -> void {
} else {
tooltipFormat = "{long}";
}
auto tooltipText = trim(fmt::format(
fmt::runtime(tooltipFormat),
fmt::arg("long", layout_.full_name),
auto tooltipText =
trim(fmt::format(fmt::runtime(tooltipFormat), fmt::arg("long", layout_.full_name),
fmt::arg("short", layout_.short_name),
fmt::arg("shortDescription", layout_.short_description),
fmt::arg("variant", layout_.variant)));
@@ -185,7 +184,8 @@ void Language::initLanguage() {
auto Language::removeXkbLayoutCssClass() -> void {
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 {
label_.get_style_context()->add_class(layout_.short_name);
+5 -6
View File
@@ -67,7 +67,7 @@ auto Window::update() -> void {
fmt::arg("class", windowData_.class_name),
fmt::arg("initialClass", windowData_.initial_class_name)),
config_["rewrite"]);
label_.set_markup(label_text);
setLabelMarkup(label_text);
} else {
label_.hide();
}
@@ -78,13 +78,12 @@ auto Window::update() -> void {
tooltip_format = config_["tooltip-format"].asString();
}
if (!tooltip_format.empty()) {
label_.set_tooltip_markup(
fmt::format(fmt::runtime(tooltip_format), fmt::arg("title", windowName),
setTooltipMarkup(fmt::format(fmt::runtime(tooltip_format), fmt::arg("title", windowName),
fmt::arg("initialTitle", windowData_.initial_title),
fmt::arg("class", windowData_.class_name),
fmt::arg("initialClass", windowData_.initial_class_name)));
} else if (!label_text.empty()) {
label_.set_tooltip_markup(label_text);
setTooltipMarkup(label_text);
}
}
@@ -222,8 +221,8 @@ void Window::queryActiveWorkspace() {
std::vector<Json::Value> visibleWindows;
std::ranges::copy_if(workspaceWindows, std::back_inserter(visibleWindows),
[&](const Json::Value& window) { return !window["hidden"].asBool(); });
solo_ = 1 == std::count_if(
visibleWindows.begin(), visibleWindows.end(),
solo_ =
1 == std::count_if(visibleWindows.begin(), visibleWindows.end(),
[&](const Json::Value& window) { return !window["floating"].asBool(); });
allFloating_ = std::ranges::all_of(
visibleWindows, [&](const Json::Value& window) { return window["floating"].asBool(); });
+2 -9
View File
@@ -63,16 +63,9 @@ auto waybar::modules::IdleInhibitor::update() -> void {
}
std::string status_text = status ? "activated" : "deactivated";
label_.set_markup(fmt::format(fmt::runtime(format_), fmt::arg("status", status_text),
fmt::arg("icon", getIcon(0, status_text))));
updateLabelAndTooltipForState(status_text, format_, "{status}", fmt::arg("status", status_text),
fmt::arg("icon", getIcon(0, 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
ALabel::update();
}
+3 -3
View File
@@ -124,7 +124,7 @@ auto Language::update() -> void {
fmt::runtime(format_), fmt::arg("short", layout_.short_name),
fmt::arg("shortDescription", layout_.short_description), fmt::arg("long", layout_.full_name),
fmt::arg("variant", layout_.variant), fmt::arg("flag", layout_.country_flag())));
label_.set_markup(display_layout);
setLabelMarkup(display_layout);
if (tooltipEnabled()) {
if (tooltip_format_ != "") {
auto tooltip_display_layout = trim(
@@ -132,9 +132,9 @@ auto Language::update() -> void {
fmt::arg("shortDescription", layout_.short_description),
fmt::arg("long", layout_.full_name), fmt::arg("variant", layout_.variant),
fmt::arg("flag", layout_.country_flag())));
label_.set_tooltip_markup(tooltip_display_layout);
setTooltipMarkup(tooltip_display_layout);
} 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 {
if (count_ || show_empty_) {
event_box_.show();
label_.set_markup(
setLabelMarkup(
fmt::format(fmt::runtime(format_),
fmt::arg("icon", getIcon(count_, "", config_["format-icons"].size())),
fmt::arg("count", count_)));
if (tooltip_enabled_) {
label_.set_tooltip_markup(tooltip_text_);
setTooltipMarkup(tooltip_text_);
}
} else {
event_box_.hide();