From 022c9abad4d5e505ac177541c092dd8a281f538d Mon Sep 17 00:00:00 2001 From: yeheng282 Date: Tue, 11 Apr 2023 21:01:02 +0800 Subject: [PATCH] backlight: support tooltip --- src/modules/backlight.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/modules/backlight.cpp b/src/modules/backlight.cpp index a46b2968..dc0ef92b 100644 --- a/src/modules/backlight.cpp +++ b/src/modules/backlight.cpp @@ -190,10 +190,25 @@ auto waybar::modules::Backlight::update() -> void { event_box_.show(); const uint8_t percent = best->get_max() == 0 ? 100 : round(best->get_actual() * 100.0f / best->get_max()); - label_.set_markup(fmt::format(fmt::runtime(format_), + std::string desc = fmt::format(fmt::runtime(format_), fmt::arg("percent", std::to_string(percent)), - fmt::arg("icon", getIcon(percent)))); - getState(percent); + fmt::arg("icon", getIcon(percent))); + label_.set_markup(desc); + getState(percent); + if (tooltipEnabled()) { + std::string tooltip_format; + if (config_["tooltip-format"].isString()) { + tooltip_format = config_["tooltip-format"].asString(); + } + if (!tooltip_format.empty()) { + label_.set_tooltip_text(fmt::format( + fmt::runtime(tooltip_format), + fmt::arg("percent", std::to_string(percent)), + fmt::arg("icon", getIcon(percent)))); + } else { + label_.set_tooltip_text(desc); + } + } } else { event_box_.hide(); }