A workaround to activate Scroll Lock LED (the backlight in some keyboards) in wlroots based compositors.
According to this swaywm/sway#5342 (comment), the LEDs appear to be updated post-key-release regardless of the key, which causes the backlight to be disabled immediately after turning it on. LEDs now only update when a LED changes. A workaround is still needed though.
If you are using GNOME/Mutter you can use these workarounds in combination with the first workaround in this repo.
Related issues and links:
Issue on Gitlab | Backlight activated by the Scroll Lock LED can't be turn on
Merge request on Gitlab | types/wlr_keyboard.c : keyboard_led_update when leds is change (Merged)
libinput/issue #11 | scrolllock, the only key that can switch keyboard back light can't be activated
libinput/issue #102 | Scroll Lock doesn't work as expected
Reddit | I can't enable Scroll Lock to turn keyboard's LED lights [Devastador 2 Gaming Keyboard]
The python script workaround gives the same results as using xset led named "Scroll Lock"
in Xorg, but requires executing a python script and executing it as root. This script should also work on GNOME/Mutter (untested).
Since the second "workaround" got merged, there's not need to patch wlroots anymore. I still recommend using the python script to prevent the CapsLock and NumLock from turning off the LED
Download it here.
Requires to run the script with admin-level access. (It reads from /dev/input/event
and /sys/class/leds/
)
This script is based on libinput/examples/led-toggle.py
After installing the necessary packages and modules, and downloading the script. You can proceed to execute it.
python ledToggler.py <path> <keystr> <ledstr> <forceLed> <startLed>
If you just want to enable your scroll lock LED use and toggle it as you want, then use:
python ledToggler.py /dev/input/eventX scrolllock scrolllock 1 1
Replace X
with your keyboard's handle event number. You can check it using:
cat /proc/bus/input/devices
<path>
refers to the event path of your keyboard. dev/input/eventX
<keystr>
refers to the name of the toggle key. numlock, capslock, scrolllock
<ledstr>
refers to the name of the LED that you want to toggle. numlock, capslock, scrolllock
<forceLed>
when disabled it won't force the LED to stay on (susceptible to LEDs updates), when enabled it forces the LED to stay on unless the toggle key state is off. 0, 1
Important: <forceLed>
is useful to have it enabled because when CapsLock or NumLock are pressed, the ScrollLock LED turns off. When enabled, visually, the LED doesn't turn off.
<startLed>
when disabled upon execution the script won't turn on the LED, when enabled upon execution the script will turn on the LED. 0, 1
You can use these commands to toggle the LED without the python script:
brightnessctl --device='*::scrolllock' set 1 # ON
brightnessctl --device='*::scrolllock' set 0 # OFF
# Alternative
sudo sh -c 'echo 1 > /sys/class/leds/inputX::scrolllock/brightness' # ON
sudo sh -c 'echo 0 > /sys/class/leds/inputX::scrolllock/brightness' # OFF
You can also use these workarounds to activate the LEDs.
-
You can find the key event code/name of a key, using:
evtest
https://archlinux.org/packages/community/x86_64/evtest/ -
Another alternative to
evtest
is usinglibevdev device example
https://python-libevdev.readthedocs.io/en/latest/examples.html#id1 -
Replace X with the event handler number:
cat /proc/bus/input/devices