Use brightness keys with LXDE (Ubuntu on Sony VAIO)

lxdeMy brightness keys were not working out of the box when I switched to LXDE from Unity. Though I keep the brightness constant, I still wanted to make it work in case I need to change the level anytime. I kept the range between 5 to 50 as those limits are fine for me. Here goes how I did it with simple scripts.

The following script (br+) increases the brightness:

#!/bin/bash

curval=`pkexec /usr/lib/gnome-settings-daemon/gsd-backlight-helper \
--get-brightness`

if [ $curval -ge 50 ]; then
echo already max
else
`pkexec /usr/lib/gnome-settings-daemon/gsd-backlight-helper \
--set-brightness $(expr $curval + 5)`
fi

The script (br-) to decrease the brightness:

#!/bin/bash

curval=`pkexec /usr/lib/gnome-settings-daemon/gsd-backlight-helper \
--get-brightness`

if [ $curval -le 5 ]; then
echo already min
else
`pkexec /usr/lib/gnome-settings-daemon/gsd-backlight-helper \
--set-brightness $(expr $curval - 5)`
fi

Made both the scripts executable and moved to /usr/bin as root. The next step was to find the key mappings for the brightness keys. The tool I used to find that out is xev. It revealed that the keys are XF86MonBrightnessUp and XF86MonBrightnessDown. So I added the following in ~/.config/openbox/lxde-rc.xml along with other keybind actions:

<keybind key="XF86MonBrightnessUp">
  <action name="Execute">
  <command>br+</command>
  </action>
</keybind>

<keybind key="XF86MonBrightnessDown">
  <action name="Execute">
  <command>br-</command>
  </action>
</keybind>

That’s it! Just relogged-in and had functional brightness keys! You can download the scripts from here. It’s tested it on a Sony VAIO SVS13112ENB running Ubuntu 13.04 (Raring).

2 thoughts on “Use brightness keys with LXDE (Ubuntu on Sony VAIO)”

Leave a Reply

Your email address will not be published. Required fields are marked *