Ubuntu – Control external monitor brightness via software

brightnessexternal-monitor

Hello Ubuntu community,

I can control the brightness of my DELL U2713HM connected with DisplayPort via the command:

ddccontrol -p -r 0x10 -w 53

where in this example the number 53 represents the brightness level (range 0 to 100). But I don't know how to link the command to my brightness keys on my keyboard.

I searched already, but just found answers to integrated laptop screens. In /sys/class/backlight is the folder acpi_video0 with some subfolders and files. The file actual_brightness contains a number from 0 to 20, which is changing when I press the brightness keys.

How do I get my external monitor listed as a device in /sys/class/backlight ?

PS: I am running a fresh Ubuntu 12.10 install with integrated graphics Intel HD4000.

Best Answer

I don't think your desired solution of getting your external monitor in /sys/class/backlight will work, but the good news is that you can have the nice brightness animation!

Try

notify-send " " -i notification-display-brightness-low -h int:value:50 -h string:x-canonical-private-synchronous:brightness &

Now we can make a script that simulates Ubuntu's brightness changer:

#!/bin/bash
#get current brightness
presbright=$(ddccontrol -p | grep -A1 0x10 | tr -d '\n\t' | sed 's/.*value=\([^a-zA-Z]*\),.*/\1/')
#stepsize for the brightness change
stepsize=10

case "$1" in
        up)
          newbright=$(( ${presbright}+${stepsize} ))
          newbright=$(echo $newbright | awk '{if($1 < 100){if($1 > 0) print $1; else print 0;} else print 100;}')

          notify-send " " -i notification-display-brightness-low -h int:value:$newbright -h string:x-canonical-private-synchronous:brightness &
          ddccontrol -p -r 0x10 -w $newbright
        ;;
        down)
          newbright=$(( ${presbright}-${stepsize} ))
          newbright=$(echo $newbright | awk '{if($1 < 100){if($1 > 0) print $1; else print 0;} else print 100;}')

          notify-send " " -i notification-display-brightness-low -h int:value:$newbright -h string:x-canonical-private-synchronous:brightness &
          ddccontrol -p -r 0x10 -w $newbright            
        ;;
        status)
          echo $presbright
        ;;
        *)
          echo "Accepted arguments are: up, down, status."
        ;;
esac

exit 0

As you can see it clamps the values between 0 and 100. Now you can bind the up and down calls to the script to some keyboard shortcuts of your choice with System Settings > Keyboard > Shortcuts, like fotomonster suggested.


Notes:
I don't know how much time ddccontrol -p takes, if it is too long you can also add a sync option to the script which saves the brightness value of the monitor to a file. Then instead of getting the current brightness from ddccontrol you can simply get it from your file, which should be much faster. Of course you would need to update the up and down calls to write the new brightness to the file...


script inspired by this post on archlinux.