21

How do I programmatically change the monitor brightness on Linux?

I'm using SLES 11.

Alexander Stolz
  • 7,454
  • 12
  • 57
  • 64
  • possible duplicate of [Possible to change screen brightness with c?](http://stackoverflow.com/questions/5811279/possible-to-change-screen-brightness-with-c) – Alexander Stolz Nov 03 '11 at 08:38

11 Answers11

31

You can always use

xrandr --output LVDS1 --brightness 0.9
JDB
  • 25,172
  • 5
  • 72
  • 123
christof
  • 319
  • 3
  • 3
  • 3
    "LVDS1" is the name of the display you want to change. Run `xrandr` and check the name of the display you have. The line will look something like "LVDS1 connected 1920x1080+0+0". – spiffytech Jan 02 '14 at 16:20
  • 9
    Quote from `man xrandr` regarding `--brightness`: "this is a software only modification, if your hardware has support to actually change the brightness, you will probably prefer to use `xbacklight`" – Amr Mostafa Mar 29 '14 at 18:47
  • 1
    change LVDS1 to eDP if you have a laptop, if you have a DP monitor and have it connected with DP, use DP instad, same with DVI1,DVI2 etc – nwgat Apr 05 '14 at 08:27
  • 1
    Amr is right. This can turn all white to black, or all black to white; but not make the white brigher – BeniBela Apr 11 '14 at 17:45
  • As this answer do not really changes the brightness of the monitor you better try the possibilities from this answer: https://askubuntu.com/a/1181157/1046889 – Coden Jan 09 '21 at 21:06
14

You can try using xbacklight.

xbacklight -set 100

foxhead128
  • 149
  • 1
  • 2
4

For me it works perfectly with xbacklight. If you for example wish to set up a key binding, you can use

bindsym $SUPER+Shift+plus   exec  xbacklight -inc 10
bindsym $SUPER+Shift+minus  exec  xbacklight -dec 10

in your window managers config (I use i3) to regulate your screen's brightness level.

I wouldn't recommend xrandr for this since it doesn't stop at 100% brightness automatically.

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
artemis_clyde
  • 373
  • 2
  • 20
4

On my machine I run the following as root:

echo -n 10 > /sys/devices/virtual/backlight/acpi_video0/brightness
whoplisp
  • 2,508
  • 16
  • 19
  • This is what I use, but typing this command each time is a pain, so you might want to add a shell function to your .bashrc file, something like `function brightness() {` `echo $1 > /sys/class/backlight/acpi_video0/brightness` `}` – Max Wallace Sep 07 '13 at 20:46
  • I got `echo: write error: Invalid argument` when I tried this. You may need to check `/sys/class/backlight/acpi_video0/max_brightness` first. I turned out that for me max_brightness was 7. – dr_agon Dec 15 '14 at 17:26
  • It works, but brightness 0 only results in a darker screen, not in blank dark screen (like turn off) !!! Any idea why ? – ransh Nov 25 '16 at 17:12
2

The ddcutil application can change an external monitor's actual backlight brightness via the VESA DDC/MCCS standard (xrandr can only move the X11 output within a monitor's currently set limits, it can't change the actual backlight brightness). This should work for any monitors that support that capability via Display Data Channel (DDC has been around for some time, it is be widely supported, but for external monitors only). I use ddcutil to automatically adjust my monitor based on the ambient light level sampled from a webcam. Ddcutil uses the i2c-dev kernel module (modprobe i2c-dev or set it to load at boot).

ddcutil detect                    # Get list of DDC displays
ddcutil --display 2 capabilities  # List VCP feature key numbers
ddcutil --display 2 getvcp 10     # Get brightness by key number
ddcutil --display 2 setvcp 10 50  # Set brightness to 50                                                                            
  • Subsequent to answering this question, I have written my own desktop tray GUI front end to ddcutil specifically for quick access to backlight adjustments. If you need such a tool, see vdu_controls at https://github.com/digitaltrails/vdu_controls or the brief write up at https://forums.opensuse.org/showthread.php/559401-Desktop-control-of-external-monitor-settings-with-ddcutil-and-vdu_controls – Michael Hamilton Sep 08 '21 at 20:55
0

edit /etc/default/grub file and add

“pcie_aspm=force acpi_backlight=vendor” after

GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”

after the changes, the whole line will look like this

GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash pcie_aspm=force acpi_backlight=vendor”

Chirag Singh

Mir Rahed Uddin
  • 1,208
  • 2
  • 12
  • 25
0

If you have multiple displays and php installed, put this in

/usr/bin/brightness

#!/usr/bin/php
<?
$br=(double)$argv[1];
if(!$br||$br>1) die("enter brightness lvl 0.1 - 1");
preg_match_all('!^(\S+)!m',`xrandr --current | grep ' connected'`,$m);
foreach($m[1] as $display){
        echo `xrandr --output $display --brightness $br`."\n";
}

than call brightness .7

13DaGGeR
  • 147
  • 1
  • 10
0

Here is the simple step to control brightness in Linux based system

First, you have to know the monitoring screen connected you.

To know this run this command

xrandr -q

It will give useful information about the screen

screen_info

( Here my screen connected to eDP, It might be different for your system )

After knowing that run the below command

xrandr --output eDP --brightness [0-10]

Replace eDP by your connected screen from the above output.

you can choose normal brightness values from 0.1 to 1.0

Mir Rahed Uddin
  • 1,208
  • 2
  • 12
  • 25
KrisH Jodu
  • 104
  • 9
0

command for this:

xgamma -gamma 0.7

anonim
  • 1
0

You might look into using xgamma. Although it's not pure code, at least it's just a command line utility.

rockerest
  • 10,412
  • 3
  • 37
  • 67
  • xgamma is not a monitor brightness, it is image filtering before output it into VGA card. – osgx Jul 08 '11 at 14:53
0

Works only for intel, but you can use xbacklight. Create a /etc/X11/xorg.conf.d/20-intel.conf and then add

Section "Device"
    Identifier  "Intel Graphics"
    Driver      "intel"
    Option      "Backlight"  "intel_backlight"
EndSection

Reboot, and then you can use xbacklight -set somevalue