Xfce keybindings

From OLPC
Jump to navigation Jump to search

Xfce is a user frontend installed on many OLPC laptops to replace or function alongside the default Sugar user interface. When it is installed on an OLPC laptops the screen brightness and rotation buttons as well as the volume buttons no longer function as expected. While it may appear complicated the following instuctions should make these keys functional again. These instructions may seem complicated at first but anyone with a working knowledge of the terminal should be able to use them.

Xbindkeys

The first step to making the keys work the way you want them to is to install a small application called Xbindkeys. In the terminal use the following commands:

 $ su
 # yum install xbindkeys

Follow the simple install procedures and create a keybindings file which you will be editing thoughout the rest of this tutorial:

 # xbindkeys –defaults > /home/olpc/.xbindkeysrc

In order to map the keys to the appropriate action we must now first discover the index for each of the concerned keys. In the instructions that follow, the correct key indexes are included so you don't have to perform this step it is included here in case you want to map out other keys to additional actions. The command "xbindkeys -k" followed by pressing one key will give the keycode for that key. For the increase volume button for example the keycode is c:96

To edit the keybindings file that we have created use any text editor you please. Nano is easy to use so we'll use it:

 # nano /home/olpc/.xbindkeysrc

The format for adding a keybinding to this file is one line with a hash " # " followed by a comment describing what the keybinding will do, a second line with the command to be executed in quotes, and a third line with the keycode.

Adjust screen brightness buttons

Because of the restricted access to the backlight adjustment program this is the most complicated part of the keybinding tutorial. Start by creating a script to adjust screen brightness when called from xbindkeys:

 File: /usr/bin/adjust_brightness.sh
# The first argument is whether to increase the brightness (+) or
# decrease the brightness (-).
# The second argument is optional and indicates the step size when
# increasing or decreasing the brightness. The default is 1.
if [ $# -eq 0 ]; then exit 1; fi
bright_file="/sys/class/backlight/dcon-bl/brightness"
mbright_file="/sys/class/backlight/dcon-bl/max_brightness"
while read line; do
brightness=$line
done < <(cat "$bright_file")
while read line; do
max_brightness=$line
done < <(cat "$mbright_file")
step=1
if [ $# -gt 1 ]; then
step=$2
fi
declare -i brightness
if [ $1 = "-" ]; then
if [ $brightness -ne 0 ]; then
brightness=$brightness-$step;
echo $brightness > /sys/class/backlight/dcon-bl/brightness
fi
else
if [ $brightness -ne $max_brightness ]; then
brightness=$brightness+$step;
echo $brightness > $bright_file
fi
fi

Don't worry if you don't understand the above script. You can just copy and paste the contents into the file you create when using the following command:

 # nano /usr/bin/adjust_brightness.sh

Now you must make this file executable:

 # chmod a+x /usr/bin/adjust_brightness.sh

Open the keybindings file and add have the "dim" (c:75) and "bright" (c:76) keys execute the above script:

 # nano /home/olpc/.xbindkeysrc

and paste the following before "End of Xbindkeys configuration" :

 ## Reduce brightness
 "/usr/bin/adjust_brightness.sh -" 
 c:75
 
 ## Increase brightness
 "/usr/bin/adjust_brightness.sh +" 
 c:76

Note: shift is used here instead of control because control did not work for some reason. If you have any solutions for this please post here

Startup script

In order to make these and other keybindings work each session you'll need to make a startup script which will run xbindkeys as well as making the necessary permission changes in the case of brightness adjustment keys. Our script will start out very simply. We'll add to it later.

 File: /home/olpc/.xfce4_startup
#!/bin/bash
/usr/bin/xbindkeys

Now make the script executable:

 # chmod +x /home/olpc/.xfce4_startup

In order for this to run every time Xfce startsup you'll need to add it to Xfce Menu -> Settings -> Autostarted Applications using the full path for the script. The only commands left to make our keys adjust the brightness are those that change the permissions of the application to adjust the backlight:

 # chgrp olpc /sys/class/backlight/dcon-bl/brightness
 # chmod g+w /sys/class/backlight/dcon-bl/brightness

At this point your keys should work properly. Unfortunately, simply adding these commands to your startup script will not work. Not only will the permission be automatically reset but the startup script doesn't currently have the authority to go around changing permissions. To give it such authority we need sudo:

 # yum install sudo

If you get an error you may need to remove the old version of sudo first:

 # rm /usr/bin/sudo

Now you just need to open visudo:

# EDITOR=/usr/bin/nano /usr/sbin/visudo

Comment out the line that reads "Defaults requiretty” and add the following lines to the bottom somewhere:

 olpc ALL=(root) NOPASSWD: /bin/chgrp olpc /sys/class/backlight/dcon-bl/brightness
 olpc ALL=(root) NOPASSWD: /bin/chmod g+w /sys/class/backlight/dcon-bl/brightness

Now you can have your startup script edit the permissions of the appropriate file by adding to /home/olpc/.xfce4_startup the following lines:

 sudo chgrp olpc /sys/class/backlight/dcon-bl/brightness
 sudo chmod g+w /sys/class/backlight/dcon-bl/brightness

Adjusting volume, and rotating the screen

Most everything else involving keybindings is much simpler than getting the backlighting adjust to work. Simply add the following to you .xbindkeyrc file:

# Decrease volume (F11)
"amixer -c 0 set Master,0 2dB-"
c:95

# Increase volume (F12)
"amixer -c 0 set Master,0 2dB+"
c:96

# Toggle mute
"amixer -c 0 set Master,0 toggle"
shift + c:95

# Max volume
"amixer -c 0 set Master,0 31"
shift + c:96

# Turn off backlighting (ebook mode)
"brightness 0"
shift + c:75

# Maximum brightness
"brightness 15"
shift + c:76

# rotate the freakin' screen
"rotate"
c:235

Other options

Many applications use F11 to toggle fullscreen. You can map your frame button in the top-right corner of the keyboard for this with a simple command:

 # xmodmap -e 'keycode 147=F11'

you can use this method to link F-keys to the rest of the unused top-row of keys if you like. This will only last for the current session. To make the results last simply add the command to Autostarted Applications or preferably to the startup script you created above- "/home/olpc/.xfce4_startup"

Reference

  • Much of this page is gleaned from the "Xfce?" thread on the OLPC news forums
  • Most of the instructions are based on work by OLPC news forum user Frihet
  • Other tips for keybindings were taken from OLPC news forum posts by user pgf