From 7409ff69765bd358133e6a1b2a19b51b1e6384d3 Mon Sep 17 00:00:00 2001 From: gitmpr <89863774+gitmpr@users.noreply.github.com> Date: Sat, 18 Jul 2026 20:41:40 +0200 Subject: [PATCH] backlight: clamp scroll step to min-brightness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/modules/backlight.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/modules/backlight.cpp b/src/modules/backlight.cpp index 24e08d54..8f7ff760 100644 --- a/src/modules/backlight.cpp +++ b/src/modules/backlight.cpp @@ -120,9 +120,15 @@ bool waybar::modules::Backlight::handleScroll(GdkEventScroll* e) { if (config_["min-brightness"].isDouble()) { min_brightness = config_["min-brightness"].asDouble(); } - if (backend.get_scaled_brightness(preferred_device_) <= min_brightness && - ct == util::ChangeType::Decrease) { - return true; + if (ct == util::ChangeType::Decrease) { + const double current = backend.get_scaled_brightness(preferred_device_); + if (current <= min_brightness) { + return true; + } + if (current - step < min_brightness) { + backend.set_scaled_brightness(preferred_device_, static_cast(std::round(min_brightness))); + return true; + } } backend.set_brightness(preferred_device_, ct, step);