Backlight: Difference between revisions

imported>Graham33
Add info on OLED screens (which don't technically have a backlight)
Klinger (talk | contribs)
m link to category instead of redirect page
 
(4 intermediate revisions by 3 users not shown)
Line 29: Line 29:
   programs.light.enable = true;
   programs.light.enable = true;
</syntaxhighlight>
</syntaxhighlight>


The following commands will allow you to test <code>light</code>:
The following commands will allow you to test <code>light</code>:
*<code>light -U 30</code> — the screen should become darker.
* <code>light -U 30</code> — the screen should become darker.
*<code>light -A 30</code> — the screen should become brighter.
* <code>light -A 30</code> — the screen should become brighter.


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.
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.


== <code>brightnessctl</code> ==
== <code>brightnessctl</code> ==
{{nixos:package|brightnessctl}} ([https://github.com/Hummer12007/brightnessctl homepage]) is another option, which, like <code>light</code>, would work even without X or on Wayland.
{{nixos:package|brightnessctl}} ([https://github.com/Hummer12007/brightnessctl homepage]) is another option, which, like <code>light</code>, would work even without X or on Wayland.


You can use it by simply installing the package. Since <code>brightnessctl</code> supports the systemd-logind API it should work out of the box (i.e. without installing any udev rules or using a setuid wrapper).
You can use it by simply installing the package. Since <code>brightnessctl</code> supports the systemd-logind API it should work out of the box (i.e. without installing any udev rules or using a setuid wrapper).
The following commands will allow you to test <code>brightnessctl</code>:
* <code> brightnessctl set 5%-</code> - the screen should become darker.
* <code> brightnessctl set 5%+</code> - the screen should become brighter.
If you get an error like <code>Failed to set brightness: Protocol error</code>, check that you are using the right device. You can get a list of the devices with running <code>brightnessctl -l</code> and then specify the device with <code>-d deviceName</code>.
Example: <code>brightnessctl set 5%- -d intel_backlight</code>
== <code>/sys/class/backlight/...</code> ==
The <code>/sys/class/backlight/*/brightness</code> files are a built-in way to set brightness. Use them e.g. with:
<syntaxhighlight lang=bash>
  sudo tee /sys/class/backlight/intel_backlight/brightness <<< 300
</syntaxhighlight>
to set the brightness to <code>300</code>, where the maximum is stored in <code>brightness_max</code>. You can set file permissions e.g. with a udev rule, if you don't want to use sudo. Here is an example udev rule, where you will likely have to replace intel_backlight, with the name in your /sys/class/backlight/:
<syntaxhighlight lang=nix>
  services.udev.extraRules = ''
    ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="intel_backlight", MODE="0666", RUN+="${pkgs.coreutils}/bin/chmod a+w /sys/class/backlight/%k/brightness"
  '';
</syntaxhighlight>


== Tips ==
== Tips ==
Line 49: Line 72:
While controlling the backlight via the command line is useful, it would be preferable to control it using key bindings. This is especially true considering most laptops have backlight control keys.
While controlling the backlight via the command line is useful, it would be preferable to control it using key bindings. This is especially true considering most laptops have backlight control keys.


There are two main choices to add key bindings, using a system-level service like [[actkbd]] or using an X session tool, either provided by your [[Desktop environment]], [[Window manager]] or a tool like [[xbindkeys]].
There are two main choices to add key bindings, using a system-level service like [[actkbd]] or using an X session tool, either provided by your [[:Category:Desktop environment|Desktop environment]], [[Window manager]] or a tool like [[xbindkeys]].


Depending on the tools that work for controlling the backlight you will be able to choose one of those options.
Depending on the tools that work for controlling the backlight you will be able to choose one of those options.


{| class="wikitable" border="1"
{| class="wikitable"
|-
|-
!  
!  
Line 75: Line 98:
* NixOS 19.09pre173166.373488e6f4c on a Lenovo X240
* NixOS 19.09pre173166.373488e6f4c on a Lenovo X240


it may work on other models, but is unconfirmed. See [[actkbd]] for details on finding out the proper key bindings. Also check if the path to the light binary is correct. }}
it may work on other models, but is unconfirmed. See [[actkbd]] for details on finding out the proper key bindings. Also check if the path to the light binary is correct.}}
 
 


<syntaxhighlight lang="nix">
<syntaxhighlight lang=nix>
   programs.light.enable = true;
   programs.light.enable = true;
   services.actkbd = {
   services.actkbd = {
Line 91: Line 112:


== OLED Screens ==
== OLED Screens ==
OLED screens do not have a backlight, but their perceived brightness can be changed via xrandr:
OLED screens do not have a backlight, but their perceived brightness can be changed via xrandr:


Line 99: Line 121:


* [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]
[[category:hardware]]