feat(backlight): added percentexp as format option

Humans don't perceive light linearly and so an exponential curve is more
appropriate to gauge the perceived brightness of the screen.
This commit is contained in:
Narice
2022-12-06 18:40:38 +01:00
parent c5babb4c44
commit 0fdc4c11f3
+8
View File
@@ -179,9 +179,17 @@ auto waybar::modules::Backlight::update() -> void {
if (best->get_powered()) { if (best->get_powered()) {
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());
const uint8_t percent_exp =
best->get_max() == 0
? 100
: roundf(powf((float)best->get_actual() / best->get_max(), 1.0f / 2.718f) * 100);
label_.set_markup(fmt::format(format_, fmt::arg("percent", std::to_string(percent)), label_.set_markup(fmt::format(format_, fmt::arg("percent", std::to_string(percent)),
fmt::arg("percentexp", std::to_string(percent_exp)),
fmt::arg("icon", getIcon(percent)))); fmt::arg("icon", getIcon(percent))));
getState(percent); getState(percent);
} else { } else {