refactor(modules): use ALabel dedup tooltip helper in simpleclock, systemd-failed-units, upower
simpleclock: migrate to updateLabelAndTooltip (label + tooltip share the localtime arg; default tooltip falls back to the label format). systemd-failed-units: use setLabelMarkup/setTooltipMarkup dedup setters; label/tooltip formats are selected by different conditions so the combined helper does not apply. upower: use setLabelMarkup for the label; tooltip stays a custom GTK widget. mpd already uses the dedup setters (label/tooltip use different truncated args), so no change.
This commit is contained in:
@@ -18,18 +18,7 @@ auto waybar::modules::Clock::update() -> void {
|
||||
tzset(); // Update timezone information
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto localtime = fmt::localtime(std::chrono::system_clock::to_time_t(now));
|
||||
auto text = fmt::format(fmt::runtime(format_), localtime);
|
||||
label_.set_markup(text);
|
||||
|
||||
if (tooltipEnabled()) {
|
||||
if (config_["tooltip-format"].isString()) {
|
||||
auto tooltip_format = config_["tooltip-format"].asString();
|
||||
auto tooltip_text = fmt::format(fmt::runtime(tooltip_format), localtime);
|
||||
label_.set_tooltip_markup(tooltip_text);
|
||||
} else {
|
||||
label_.set_tooltip_markup(text);
|
||||
}
|
||||
}
|
||||
updateLabelAndTooltip(format_, format_, localtime);
|
||||
// Call parent update
|
||||
ALabel::update();
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ auto SystemdFailedUnits::update() -> void {
|
||||
|
||||
last_status_ = overall_state_;
|
||||
|
||||
label_.set_markup(fmt::format(
|
||||
setLabelMarkup(fmt::format(
|
||||
fmt::runtime(nr_failed_ == 0 ? format_ok_ : format_), fmt::arg("nr_failed", nr_failed_),
|
||||
fmt::arg("nr_failed_system", nr_failed_system_), fmt::arg("nr_failed_user", nr_failed_user_),
|
||||
fmt::arg("system_state", system_state_), fmt::arg("user_state", user_state_),
|
||||
@@ -290,14 +290,14 @@ auto SystemdFailedUnits::update() -> void {
|
||||
std::string failed_list = BuildTooltipFailedList();
|
||||
auto tooltip_template = overall_state_ == "ok" ? tooltip_format_ok_ : tooltip_format_;
|
||||
if (!tooltip_template.empty()) {
|
||||
label_.set_tooltip_markup(fmt::format(
|
||||
setTooltipMarkup(fmt::format(
|
||||
fmt::runtime(tooltip_template), fmt::arg("nr_failed", nr_failed_),
|
||||
fmt::arg("nr_failed_system", nr_failed_system_),
|
||||
fmt::arg("nr_failed_user", nr_failed_user_), fmt::arg("system_state", system_state_),
|
||||
fmt::arg("user_state", user_state_), fmt::arg("overall_state", overall_state_),
|
||||
fmt::arg("failed_units_list", failed_list)));
|
||||
} else {
|
||||
label_.set_tooltip_markup("");
|
||||
setTooltipMarkup("");
|
||||
}
|
||||
}
|
||||
ALabel::update();
|
||||
|
||||
@@ -223,7 +223,7 @@ auto UPower::update() -> void {
|
||||
return;
|
||||
}
|
||||
|
||||
label_.set_markup(getText(upDevice_, format_));
|
||||
setLabelMarkup(getText(upDevice_, format_));
|
||||
// Set icon
|
||||
if (upDevice_.icon_name == NULL || !gtkTheme_->has_icon(upDevice_.icon_name))
|
||||
upDevice_.icon_name = (char*)NO_BATTERY.c_str();
|
||||
|
||||
Reference in New Issue
Block a user