Backlight: Difference between revisions

From NixOS Wiki
imported>BenSchaeffner
No edit summary
imported>Samueldr
m WIP, cleaning and re-working sections
Line 1: Line 1:
{{expansion}}
{{expansion}}
== Introduction ==
== Introduction ==
This page documents methods for enabling backlight (aka screen brightness) control via hotkeys.
This page documents methods for controlling backlight (aka screen brightness) and tips to control it via hotkeys.


== <code>xbacklight</code> ==
== <code>xbacklight</code> ==
Line 7: Line 7:
<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:<br />
To install <code>xbacklight</code> globally, add this to your <tt>configuration.nix</tt>.
<code>environment.systemPackages = with pkgs; [ xorg.xbacklight ];</code>
<syntaxhighlight lang=nix>
  environment.systemPackages = with pkgs; [ xorg.xbacklight ];
</syntaxhighlight>
 
Alternatively, use <code>nix-env -iA nixos.xorg.xbacklight</code> to install it to your user profile.


== <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>
<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. While it does not use X, it will need some privileges to work. This means that it needs to either be installed in a specific way (with a SUID wrapper) or used using <code>sudo</code>, or ran with superuser privileges.
 
To enable the use of <code>light</code> with SUID wrappers, add this to your <tt>configuration.nix</tt>.
 
<syntaxhighlight lang=nix>
  programs.light.enable = true;
</syntaxhighlight>


To enable light via configuration.nix add:<br />
The following commands will allow you to test <code>light</code>:
<code>programs.light.enable = true;</code>
*<code>light -U 30</code> — the screen should become darker.
*<code>light -A 30</code> — the screen should become brighter.


A reboot may be required.
Be careful using <code>light -U</code>, as you might turn your backlight completely off! You will not be able to see what you're typing anymore.


To test:<p>
== Tips ==
<code> light -U 30</code> - the screen should become darker<br />
<code> light -A 30</code> - the screen should become brighter<br />
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 ==
=== 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.
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.
Line 66: Line 74:
};</syntaxhighlight>
};</syntaxhighlight>
Tested with NixOS 18.03, and in combination with lightdm & i3.
Tested with NixOS 18.03, and in combination with lightdm & i3.
== Enabling actkbd service ==
== Using <tt>/proc/</tt> ==
<tt>...</tt>


== See also ==
== See also ==


* [https://wiki.archlinux.org/index.php/backlight Arch Linux wiki page about the backlight]
* [https://wiki.archlinux.org/index.php/backlight Arch Linux wiki page about the backlight]

Revision as of 17:08, 6 May 2018

Introduction

This page documents methods for controlling backlight (aka screen brightness) and tips to control it 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 install xbacklight globally, add this to your configuration.nix.

  environment.systemPackages = with pkgs; [ xorg.xbacklight ];

Alternatively, use nix-env -iA nixos.xorg.xbacklight to install it to your user profile.

light

light does not use X to change the light settings. This can be used in situations where the X service isn't available. While it does not use X, it will need some privileges to work. This means that it needs to either be installed in a specific way (with a SUID wrapper) or used using sudo, or ran with superuser privileges.

To enable the use of light with SUID wrappers, add this to your configuration.nix.

  programs.light.enable = true;

The following commands will allow you to test light:

  • 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! You will not be able to see what you're typing anymore.

Tips

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"; }
  ];
};

Tested with NixOS 18.03, and in combination with lightdm & i3.

See also