Ubuntu – Scale volume and/or screen brightness with a logarithmic scale

brightnesssoundunityvolume-control

I own an Acer Aspire E5-773G notebook running Ubuntu 16.04 with Unity Desktop.

When I change the volume or screen brightness level (no matter whether using Fn+Arrows or through e.g. the Volume Indicator), the scaling does not seem natural.

There is nearly no notable difference between the steps in the upper third of the brightness scale and in the upper fourth of the volume scale.

On the other hand, the steps between slider positions in the lower third of the brightness scale and in the lower fourth of the volume scale seem huge. Especially the lowest brightness setting is extremely darker than the second lowest setting (but not off).

To me these scales seem technically linear, but as the human senses all operate logarithmically, they seem weird. Is there any method how I can change the scaling of mainly brightness and ideally also volume to a more logarithmic one so that the steps seem more equal?


Update:

The xbacklight tool does not work on my machine for whatever reason. However, I found two alternatives:

  • Dbus: You can use the two commands below to get/set the brightness value as percentage, i.e. integer number in the range 0-100:

    qdbus org.gnome.SettingsDaemon.Power /org/gnome/SettingsDaemon/Power org.gnome.SettingsDaemon.Power.Screen.GetPercentage
    qdbus org.gnome.SettingsDaemon.Power /org/gnome/SettingsDaemon/Power org.gnome.SettingsDaemon.Power.Screen.SetPercentage 42
    

    The advantage of this is that every user can run it without special privileges. It is less fine-grained though.

  • Direct access to /sys/...: You can use these commands to get/set the brightness level as raw integer number in the range of 0-x. The actual maximum value x can be found using the third command:

    cat /sys/class/backlight/intel_backlight/brightness
    echo 42 | sudo tee /sys/class/backlight/intel_backlight/brightness
    cat /sys/class/backlight/intel_backlight/max_brightness
    

    The advantage of this is that it provides direct access to the hardware capabilities, so this is the most fine-grained control we can get. Unfortunately, changing the brightness value requires root rights (note the sudo in the set-command).

Best Answer

That bothered me as well, at least for the brightness adjustment, so I wrote the following script (edit: alternative backlight control commands added in comments):

#!/bin/bash

current=`xbacklight -get`
# alternatively, if xbacklight does not work:
# current=`qdbus org.gnome.SettingsDaemon.Power /org/gnome/SettingsDaemon/Power org.gnome.SettingsDaemon.Power.Screen.GetPercentage`

scale="1 2 5 10 20 50 100"

case $1 in
    "down")
        # translate space to newline so tac will reverse order of lines (values)
        for val in $(tr ' ' '\n' <<< $scale | tac) ; do
            # scale = 3 to preserve some decimal values
            if (( $(bc <<< "scale=3 ; $val < $current/1.1") )) ; then
                newval=$val
                break
            fi
        done
        ;;
    "up")
        for val in $scale ; do
            # scale = 3 to preserve some decimal values
            if (( $(bc <<< "scale=3 ; $val > $current*1.1") )) ; then
                newval=$val
                break
            fi
        done
        ;;
    *)
        echo "Usage: $0 [up, down]"
        exit 1
esac

if [ "x$newval" == "x" ] ; then
    echo "Already at min/max."
else
    echo "Setting backlight to $newval."

    # thanks: https://bbs.archlinux.org/viewtopic.php?pid=981217#p981217
    notify-send " " -i notification-display-brightness-low -h int:value:$newval -h string:x-canonical-private-synchronous:brightness &

    xbacklight -set $newval -steps 1 -time 0
    # alternatively, if xbacklight does not work:
    # qdbus org.gnome.SettingsDaemon.Power /org/gnome/SettingsDaemon/Power org.gnome.SettingsDaemon.Power.Screen.SetPercentage $newval
fi

exit 0

It depends on having xbacklight installed.

Name it brightness.sh, and running brightness.sh up or brightness.sh down will step up or down through the scale specified at the top of the script. The call to notify-send triggers the on-screen brightness notification (at least in Unity). (I'm sure the script could be improved some, but it seems to work well enough.)

I then setup keyboard shortcuts (for my tablet's volume rocker buttons, in my case) to trigger /path/to/brightness.sh up and /path/to/brightness.sh down.

To do something similar for volume, you'd need to replace the calls to xbacklight with a command that lets you read/set the volume and change the notification to be a volume notification.

Related Question