Backlight
Introduction
This page documents methods for enabling backlight (aka screen brightness) control via hotkeys.
xbacklight
xbacklight
uses X to change the light settings. This can be inconvenient in some situations, e.g. for use with the services.actkbd
service, which doesn't know about the X session. It, though, has an history of being more compatible with different hardware, especially newer hardware[citation needed]
To enable xbacklight via configuration.nix add:
environment.systemPackages = with pkgs; [ xorg.xbacklight ];
light
light
does not use X to change the light settings. This can be used in situations where the X service isn't available.
To enable light via configuration.nix add:
programs.light.enable = true;
A reboot may be required.
To test:
light -U 30
- the screen should become darker
light -A 30
- the screen should become brighter
Be careful using light -U
, as you might turn your backlight completely off, and not see what you're typing any more.
Key mapping
Once the backend functionality of controlling the backlight is verified, you can assign that to an actual key. Different laptops and keyboards may map the hotkeys to different key codes.
Key mapping - obtain key codes via xev
While logged into an X session:
nix-shell -p xorg.xev
xev
Xev reports key codes, but they did not seem to be the right codes for use with actkbd.
Key mapping - obtain key codes via actkbd
First enable the actkbd service (see below).
To read key codes via actkbd, you need to select the right input event provider from /dev/input/. Each input device generating input events has it's own entry there, enumerated with an number. To find out which one generates the events from the hotkeys, it is viable (if tedious) to run the below command with each available entry, and see which one generates event notifications when pressing the brightness hotkeys:
actkbd -v9 -n -s -d /dev/input/event<number>
Once you discover the right one, it will report key presses like so:
Event: <number>:key
Event: <number>:rel
Those represent the key-press and key-release actions. The number is the key code to use for mapping.
Key mapping - map via actkbd service
To map keys using actkbd service and the light
program, add the following to your configuration.nix file:
services.actkbd = {
enable = true;
bindings = [
{keys = [ <brightnessDown> ]; events = [ "key" ]; command = "run/wrappers/bin/light -U 10";}
{keys = [ <brightnessUp> ]; events = [ "key" ]; command = "run/wrappers/bin/light -A 10";}
];
};
Where <brightnessUp> and <brightnessDown> are the key codes obtained before.
Working configuration on Lenovo T440
To enable backlight control on a Lenovo T440, add to configuration.nix:
programs.light.enable = true;
services.actkbd = {
enable = true;
bindings = [
{ keys = [ 224 ]; events = [ "key" ]; command = "/run/wrappers/bin/light -A 10"; }
{ keys = [ 225 ]; events = [ "key" ]; command = "/run/wrappers/bin/light -U 10"; }
];
};
Enabling actkbd service
Using /proc/
...