backlight: clamp scroll step to min-brightness

When min-brightness is set, a scroll step that would cross it was not
clamped — only scrolling while already at or below min was blocked.
With scroll-step: 5 and min-brightness: 1, scrolling from 5% would
pass the guard (5 > 1) and set brightness to 0%.

Fix by computing the post-step value before applying it: if it would
fall below min-brightness, set exactly to min-brightness instead.
This commit is contained in:
gitmpr
2026-07-18 20:41:40 +02:00
parent 7f732f0553
commit 7409ff6976
+8 -2
View File
@@ -120,10 +120,16 @@ bool waybar::modules::Backlight::handleScroll(GdkEventScroll* e) {
if (config_["min-brightness"].isDouble()) { if (config_["min-brightness"].isDouble()) {
min_brightness = config_["min-brightness"].asDouble(); min_brightness = config_["min-brightness"].asDouble();
} }
if (backend.get_scaled_brightness(preferred_device_) <= min_brightness && if (ct == util::ChangeType::Decrease) {
ct == util::ChangeType::Decrease) { const double current = backend.get_scaled_brightness(preferred_device_);
if (current <= min_brightness) {
return true; return true;
} }
if (current - step < min_brightness) {
backend.set_scaled_brightness(preferred_device_, static_cast<int>(std::round(min_brightness)));
return true;
}
}
backend.set_brightness(preferred_device_, ct, step); backend.set_brightness(preferred_device_, ct, step);
return true; return true;