Hi!

Sometimes it’s painful to stare for few hours at a too bright monitor, especially at night.

Luckily this can be easily solved by setting the output brightness with XRandR, the problem is that it’s not so handy as the command to type is quite long, for example:

$ xrandr --output DVI-I-1 --brightness 0.9

In this case the DVI output connected to my monitor will be filtered resulting in a lower brightness of -0.10 from the default 1.00.

Notice that this is a software modification as man xrandr explains, if you’re using a laptop or a monitor that has hardware support to change the brightness you should check xbacklight.

You can try the command out, but first run xrandr and modify the line to fits your output:

$ xrandr

DisplayPort-0 disconnected primary (normal left inverted right x axis y axis)
HDMI-A-0 disconnected (normal left inverted right x axis y axis)
DVI-D-0 disconnected (normal left inverted right x axis y axis)
DVI-I-1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 531mm x 298mm

As you can see it works fine but as I said it’s quite a pain to execute and open a terminal every time you need to lower/raise the brightness would be extremely boring.

So I came up with a short script that can be used as a shortcut:

xrandr --output DVI-I-1 --brightness $(echo "$(xrandr --verbose |grep Brightness |grep -o '[0-9].*')+0.1" | bc)

This basically extract the current brightness value and then add/subtract a decimal value that results in a lower or higher brightness.

On i3 I use this with the KeyPad + and – keys, like this:

# BRIGHTNESS
bindsym $mod+Shift+KP_Add exec xrandr --output DVI-I-1 --brightness $(echo "$(xrandr --verbose |grep Brightness |grep -o '[0-9].*')+0.1" | bc) 
bindsym $mod+Shift+KP_Subtract exec xrandr --output DVI-I-1 --brightness $(echo "$(xrandr --verbose |grep Brightness |grep -o '[0-9].*')-0.1" | bc)
Advertisements