backlight: support tooltip

This commit is contained in:
yeheng282 2023-04-11 21:01:02 +08:00
parent a46b8a0109
commit 022c9abad4
1 changed files with 18 additions and 3 deletions

View File

@ -190,10 +190,25 @@ auto waybar::modules::Backlight::update() -> void {
event_box_.show(); event_box_.show();
const uint8_t percent = const uint8_t percent =
best->get_max() == 0 ? 100 : round(best->get_actual() * 100.0f / best->get_max()); 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("percent", std::to_string(percent)),
fmt::arg("icon", getIcon(percent)))); fmt::arg("icon", getIcon(percent)));
getState(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 { } else {
event_box_.hide(); event_box_.hide();
} }