Firstly, to get your backlight controls working. Rather than have the Fn-F5 key toggle between on and off, I have made it step between 4 settings, 0 - 1/3 - 2/3 - 1. This enables you to pick different settings for outside lighting conditions, varying between different levels of power saving. Up/Down in small steps is accomplished on the Fn-Up/Down keys.
Note that this script works at system level, so you can be sure that the LED power is being reduced, I am concerned that some of the commands that work through X may just darken the contents of the screen.
Here is a script I wrote, it's called s-backlight and I have placed it in /usr/local/bin
#/bin/bash
#quick and dirty by davecs
#tail r to rotate between 0,85,170,255
#tail s n to set absolute n
#tail number to increment/decrement brightness
#get existing brightness
BRTNESS=$((0x0`setpci -s 00:02.1 F4.B`))
if [ "$1" = "r" ] ; then
#rotate between 0 > 85 > 170 > 255
if [ "$BRTNESS" = "255" ] ; then
BRTNESS2=0
else
Y=$(( $BRTNESS / 85 ))
Y=$(( $Y + 1 ))
Y=$(( $Y * 85 ))
BRTNESS2=$Y
fi
else
# just set to figure supplied
if [ "$1" = "s" ] ; then
BRTNESS2=$2
else
#set increment in tail of command, maybe 5 for up, -5 for down
BRTNESS2=$(($BRTNESS + $1))
#block overflows
if [ $BRTNESS2 -gt 255 ] ; then
BRTNESS2=255
fi
if [ $BRTNESS2 -lt 0 ] ; then
BRTNESS2=0
fi
fi
fi
setpci -s 00:02.1 F4.B=`printf '%x' $BRTNESS2`
Don't forget to right-click on it in Konqueror or Dolphin super user mode, and make it executable.
The problem here is that setpci is only able to change values if run as root. So we need to be able to run it, without a password, using sudo. The way to do this is to add this line at the end of the file /etc/sudoers
ALL localhost = NOPASSWD: /usr/local/bin/s-backlight
It is recommended that you use the command "visudo" in a terminal as root to make this change. visudo will refuse to save an invalid sudoers file.
In order to be able to bind commands to certain keys, you need to have xbindkeys running. When you run this, it has a file ~/.xbindkeysrc as its setup file, all key binding declarations have to be in that file.
Here is my .xbindkeysrc file: (you only need to copy the lines not starting with # )
# For the benefit of emacs users: -*- shell-script -*-
###########################
# xbindkeys configuration #
###########################
#
# Version: 1.8.3
#
# If you edit this file, do not forget to uncomment any lines
# that you change.
# The pound(#) symbol may be used anywhere for comments.
#
# To specify a key, you can use 'xbindkeys --key' or
# 'xbindkeys --multikey' and put one of the two lines in this file.
#
# The format of a command line is:
# "command to start"
# associated key
#
#
# A list of keys is in /usr/include/X11/keysym.h and in
# /usr/include/X11/keysymdef.h
# The XK_ is not needed.
#
# List of modifier:
# Release, Control, Shift, Mod1 (Alt), Mod2 (NumLock),
# Mod3 (CapsLock), Mod4, Mod5 (Scroll).
#
# The release modifier is not a standard X modifier, but you can
# use it if you want to catch release events instead of press events
# By defaults, xbindkeys does not pay attention with the modifiers
# NumLock, CapsLock and ScrollLock.
# Uncomment the lines above if you want to pay attention to them.
#keystate_numlock = enable
#keystate_capslock = enable
#keystate_scrolllock= enable
"sudo /usr/local/bin/s-backlight 10"
m:0x0 + c:212
"sudo /usr/local/bin/s-backlight -10"
m:0x0 + c:101
"sudo /usr/local/bin/s-backlight s 255"
m:0x4 + c:212
"sudo /usr/local/bin/s-backlight s 160"
m:0x4 + c:101
"sudo /usr/local/bin/s-backlight r"
m:0x0 + c:159
##################################
# End of xbindkeys configuration #
##################################
And to make xbindkeys run when you start your session, you need to amend the file (14_setkeys) you made earlier at ~/.kde4/Autostart to look like this:
#/bin/sh
xmodmap ~/.Xmodmap
xbindkeys
If you log out and in, you can check this is all working.