quickshell: snap kbd backlight keys to exact 5% steps

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-08-16 13:51:24 +01:00
parent 11f7c14df3
commit 66fb7536e8

View file

@ -1645,13 +1645,31 @@ in
brightProc.running = true; brightProc.running = true;
} }
// smc::kbd_backlight has a raw max of 255, so brightnessctl's
// own percentages don't round-trip: `10%+` adds 25 raw, which
// reads back as 9%. Snap to exact 5% steps in raw units and
// report the intended percent to the OSD instead of the
// truncated readback. Prints a fake -m line so the parser above
// is unchanged. $3 = current raw, $5 = max raw.
function setKbd(step) {
if (brightProc.running) return;
brightProc.osdIcon = "keyboard";
brightProc.command = ["sh", "-c",
'd=smc::kbd_backlight; set -- $(brightnessctl -m -d $d | tr , " "); '
+ 'n=$(( ($3 * 20 + $5 / 2) / $5 ' + step + ' )); '
+ '[ $n -lt 0 ] && n=0; [ $n -gt 20 ] && n=20; '
+ 'brightnessctl -q -d $d set $(( (n * $5 + 10) / 20 )); '
+ 'echo "$d,leds,0,$(( n * 5 ))%,$5"'];
brightProc.running = true;
}
IpcHandler { IpcHandler {
target: "osd" target: "osd"
// floor 1%: `set 0%` turns the panel fully off // floor 1%: `set 0%` turns the panel fully off
function brightnessUp(): void { root.setBrightness(["set", "5%+"], "brightness"); } function brightnessUp(): void { root.setBrightness(["set", "5%+"], "brightness"); }
function brightnessDown(): void { root.setBrightness(["-n", "1", "set", "5%-"], "brightness"); } function brightnessDown(): void { root.setBrightness(["-n", "1", "set", "5%-"], "brightness"); }
function kbdUp(): void { root.setBrightness(["-d", "smc::kbd_backlight", "set", "10%+"], "keyboard"); } function kbdUp(): void { root.setKbd("+ 1"); }
function kbdDown(): void { root.setBrightness(["-d", "smc::kbd_backlight", "set", "10%-"], "keyboard"); } function kbdDown(): void { root.setKbd("- 1"); }
} }
// Night light: quickshell owns the schedule, the hyprsunset // Night light: quickshell owns the schedule, the hyprsunset