Backlight: Difference between revisions

imported>Samueldr
m Adds `see also`.
imported>BenSchaeffner
No edit summary
Line 1: Line 1:
{{expansion}}
{{expansion}}
== Introduction ==
This page documents methods for enabling backlight (aka screen brightness) control via hotkeys.


== <code>xbacklight</code> ==
== <code>xbacklight</code> ==


<code>xbacklight</code> uses X to change the light settings. This can be inconvenient in some situations, e.g. for use with the {{nixos:option|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<sup>[citation needed]</sup>
<code>xbacklight</code> uses X to change the light settings. This can be inconvenient in some situations, e.g. for use with the {{nixos:option|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<sup>[citation needed]</sup>
To enable xbacklight via configuration.nix add:<p>
<code>environment.systemPackages = with pkgs; [ xorg.xbacklight ];</code>


== <code>light</code> ==
== <code>light</code> ==


<code>light</code> does not use X to change the light settings. This can be used in situations where the X service isn't available.
<code>light</code> does not use X to change the light settings. This can be used in situations where the X service isn't available.</code>
 
To enable light via configuration.nix add:<p>
<code>programs.light.enable = true;</code>
 
A reboot may be required.
 
To test:<p>
<code> light -U 30</code> - the screen should become darker<p>
<code> light -A 30</code> - the screen should become brighter<p>
Be careful using <code>light -U</code>, 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:<p>
<code>nix-shell -p xorg.xev</code><p>
<code>xev</code><p>
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).<p>
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:<p>
<code>actkbd -v9 -n -s -d /dev/input/event<number></code><p>
Once you discover the right one, it will report key presses like so:<p>
<code>Event: <number>:key</code><p>
<code>Event: <number>:rel</code><p>
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 <code>light</code> program, add the following to your configuration.nix file:<p>
<code>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";}
  ];
};</code>
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:
 
<code>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"; }
  ];
};</code>
 
== Enabling actkbd service ==


== Using <tt>/proc/</tt> ==
== Using <tt>/proc/</tt> ==