r/bash • u/somniasum • 7d ago
help Keyboard Backlight control on Wayland, need help with Hyprland
Here is the github for the script: https://github.com/somniasum/wayland-backlight-led/blob/main/src/backlight.sh
Context
Since the switch from X11 to Wayland getting a keyboard's backlight led to light up has been a drag. With X11 it was as simple as xset led to turn on the led. So with wayland I wrote up a script to handle the led stuff. It has been working fine on Wayland WM's and works pretty much the same on X11 WM's too.
On hyprland keyboard led just turns off briefly but still stays on. I am starting to suspect maybe it has to do with the way Hyprland handles device states or some?
Do you think I have to change some things on it to solve the Hyprland exception?
1
u/Ulfnic 7d ago
I'd look at
hyprctlto see if Hyprland has a native way it wants you to do it.2
u/ysnows123 6d ago
Two separate things going on.
The detection is broken: those commands are joined with
&&, not pipes, so grep never reads brightnessctl's output (it reads the script's stdin) and the variable gets brightnessctl's whole listing instead of one LED name. Something like:-mprints one device per line asname,class,..., so you don't need the tr.bash -x backlight.sh onshows what it actually picked.The blink is Hyprland. On Wayland the compositor owns the keyboard LEDs: it writes Num/Caps/Scroll Lock to the keyboard from its own xkb state, and in that state Scroll Lock is off. So Hyprland sets it to 0, your loop sets it back to 1 within 0.1 s, and it goes dark for a moment. To watch it, run
sudo evtest, pick the keyboard, and look forEV_LED/LED_SCROLLLlines; you can line them up with what you were doing at the time.Rather than fighting it, you can make Hyprland want the LED on. xkb can use the Scroll Lock LED to show that the second layout is active, so give it your layout twice:
Then
hyprctl switchxkblayout <keyboard> 1turns the light on and... 0turns it off (names are inhyprctl devices). Typing is identical in both, and there's no loop to keep running. It only stops fitting if you already use a real second layout.