Skip to content

fix(backlight): clamp scroll step to min-brightness#5210

Open
gitmpr wants to merge 1 commit into
Alexays:masterfrom
gitmpr:fix/backlight-min-brightness-step-clamp
Open

fix(backlight): clamp scroll step to min-brightness#5210
gitmpr wants to merge 1 commit into
Alexays:masterfrom
gitmpr:fix/backlight-min-brightness-step-clamp

Conversation

@gitmpr

@gitmpr gitmpr commented Jul 18, 2026

Copy link
Copy Markdown

What does this PR do?

When min-brightness is set, a scroll step that would cross it wasn't being clamped. Only scrolling while already at or below the minimum was blocked. With scroll-step: 5 and min-brightness: 1, scrolling from 5% passes the guard (5 > 1) and sets brightness to 0%.

The check in handleScroll in src/modules/backlight.cpp was:

if (backend.get_scaled_brightness(preferred_device_) <= min_brightness &&
    ct == util::ChangeType::Decrease) {
  return true;
}
backend.set_brightness(preferred_device_, ct, step);

This blocks further decrease once you're already at the minimum, but doesn't prevent a step from landing below it.

The fix computes whether the post-step value would fall below min-brightness and, if so, sets exactly min-brightness instead of applying the full step.

Why does this matter?

On intel_backlight (type raw, no kernel-enforced minimum), the kernel and logind both accept brightness 0, which on most laptop panels is a completely black screen. This makes the issue a real usability problem rather than just a cosmetic one. Users setting min-brightness: 1 to prevent this are silently unprotected when scrolling in steps larger than 1.

Tested on intel_backlight, max_brightness 7500. Confirmed bug on unpatched master, confirmed fix on this branch.

Relates to #5209 (which adds min-brightness to the default config, which is complementary, but without this fix the protection has gaps whenever scroll-step > 1).

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant