The Problem #
I recently reinstalled Arch Linux on my not so old Lenovo Thinkpad Yoga X370, on my previous full arch run i was manually modifying the /sys/class/backlight/intel_backlight/brightness
file. It was a real pain.
With this new installation I want to do things the right way, so here I am writing what I did as I didn’t find a ready to go solution for this problem.
PS. I might be bad at googling, if you find another solution lmk.
The Solution #
Install the acpid
(stands for ACPI deamon) so that we can capture keyboard events.
sudo pacman -S acpid
You might already see where we are going with this, when we press a key on the keyboard it will generate an event that acpid
will detect and execute an action on response.
Enable and start the service
sudo systemctl enable acpid
sudo systemctl start acpid
sudo systemctl status acpid
At this point we can run something like journalctl -f
or acpi_listen
to capture the keys events.
[user@notknown ~]$ acpi_listen
video/brightnessup BRTUP 00000086 00000000
video/brightnessdown BRTDN 00000087 00000000
As we can see we get the ‘class’, the key and its number.
Look at the official documentation here for more information on the outputs and to get some examples.
To make it short, on my current configuration, when a function key is pressed an event is captured it will always execute the /etc/acpi/handler.sh
script.
[user@notknown ~]$ cat /etc/acpi/events/anything
# Pass all events to our one handler script
event=.*
action=/etc/acpi/handler.sh %e
We will modify the handler.sh
script by adding the action that we want to execute when the keys are pressed, in this case it will get the current value present inside the brightness
file and -/+ 500 , effectively changing our brightness.
.....
video/brightnessup)
case "$2" in
BRTUP)
echo -n $(( $(cat /sys/class/backlight/intel_backlight/brightness) + 500 )) > /sys/class/backlight/intel_backlight/brightness
;;
*)
logger "ACPI action undefined: $2"
;;
esac
;;
video/brightnessdown)
case "$2" in
BRTDN)
echo -n $(( $(cat /sys/class/backlight/intel_backlight/brightness) - 500 )) > /sys/class/backlight/intel_backlight/brightness
;;
*)
logger "ACPI action undefined: $2"
;;
esac
.....
Now if we check the systemctl status acpid
we wont see the events for the unrecognized keys when we press those brightness keys and the brightness will increase/decrese.