Skip to content

Commit

Permalink
issue/feat #3363: tooltip for systemd-failed-units
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertMueller2 committed Jul 20, 2024
1 parent 7c06524 commit b5b3172
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/modules/systemd_failed_units.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SystemdFailedUnits : public ALabel {
private:
bool hide_on_ok;
std::string format_ok;
std::string tooltip_format_;

bool update_pending;
uint32_t nr_failed_system, nr_failed_user;
Expand Down
10 changes: 10 additions & 0 deletions man/waybar-systemd-failed-units.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ Addressed by *systemd-failed-units*
typeof: array ++
The actions corresponding to the buttons of the menu.

*tooltip*: ++
typeof: bool ++
default: true ++
Whether to display a tooltip.

*tooltip-format* ++
typeof: string ++
default: content of *format* ++
The format for the tooltip.

# FORMAT REPLACEMENTS

*{nr_failed_system}*: Number of failed units from systemwide (PID=1) systemd.
Expand Down
15 changes: 15 additions & 0 deletions src/modules/systemd_failed_units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ SystemdFailedUnits::SystemdFailedUnits(const std::string& id, const Json::Value&
user_proxy->signal_signal().connect(sigc::mem_fun(*this, &SystemdFailedUnits::notify_cb));
}

if (tooltipEnabled() && config["tooltip-format"].isString()) {
tooltip_format_ = config["tooltip-format"].asString();
} else if (tooltipEnabled()) {
tooltip_format_ = format_;
}

updateData();
/* Always update for the first time. */
dp.emit();
Expand Down Expand Up @@ -124,6 +130,15 @@ auto SystemdFailedUnits::update() -> void {
label_.set_markup(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)));

if (tooltipEnabled()) {
if (tooltipMarkupEnabled()) {
label_.set_tooltip_markup(fmt::format(fmt::runtime(tooltip_format_), fmt::arg("nr_failed", nr_failed), fmt::arg("nr_failed_system", nr_failed_system), fmt::arg("nr_failed_user", nr_failed_user)));
} else {
label_.set_tooltip_text(fmt::format(fmt::runtime(tooltip_format_), fmt::arg("nr_failed", nr_failed), fmt::arg("nr_failed_system", nr_failed_system), fmt::arg("nr_failed_user", nr_failed_user)));
}
}

ALabel::update();
}

Expand Down

0 comments on commit b5b3172

Please sign in to comment.