diff --git a/include/modules/systemd_failed_units.hpp b/include/modules/systemd_failed_units.hpp index 9c3fbcee17..0f6d04b7da 100644 --- a/include/modules/systemd_failed_units.hpp +++ b/include/modules/systemd_failed_units.hpp @@ -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; diff --git a/man/waybar-systemd-failed-units.5.scd b/man/waybar-systemd-failed-units.5.scd index ada3ab8b5e..7a436f63ff 100644 --- a/man/waybar-systemd-failed-units.5.scd +++ b/man/waybar-systemd-failed-units.5.scd @@ -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. diff --git a/src/modules/systemd_failed_units.cpp b/src/modules/systemd_failed_units.cpp index 56e624cf29..1f1c600347 100644 --- a/src/modules/systemd_failed_units.cpp +++ b/src/modules/systemd_failed_units.cpp @@ -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(); @@ -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(); }