Xfce keybindings: Difference between revisions

From OLPC
Jump to navigation Jump to search
(case)
 
(13 intermediate revisions by 11 users not shown)
Line 1: Line 1:
[[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.
[[Xfce]] is a user front end installed on many OLPC laptops to function alongside or replace the default [[Sugar]] user interface. When it is installed on an OLPC laptop the screen brightness and rotation buttons as well as the volume buttons no longer function as expected. The following instructions 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 ==
== Xbindkeys ==
Line 7: Line 7:
# yum install xbindkeys
# yum install xbindkeys


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


MAKE SURE YOU DO *NOT* DO THE FOLLOWING LINE AS root USER --> YOU NEED TO BE USER olpc
# xbindkeys –defaults > /home/olpc/.xbindkeysrc

$ 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
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
Line 83: Line 85:


=== Startup script ===
=== Startup script ===

((( This section needs updating. In build 711 it is no longer possible to remove / install sudo and thus have access to visudo. Also, there appears to be no sudoers file ))


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.
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.
Line 98: Line 102:
# chmod +x /home/olpc/.xfce4_startup
# 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:
In order for this to run every time Xfce starts up 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
# chgrp olpc /sys/class/backlight/dcon-bl/brightness
Line 109: Line 113:
In build 703 sudo is already installed but visudo, used below, is conspicuously absent. The simplest way to get around this would be to remove sudo before reinstalling it:
In build 703 sudo is already installed but visudo, used below, is conspicuously absent. The simplest way to get around this would be to remove sudo before reinstalling it:


# rm /usr/bin/sudo
# yum remove sudo
# yum install sudo
# yum install sudo

(This can't be done in build 711 - sudo is part of package olpc-utils-0.74-2.olpc2 and cannot be installed or removed in its own right. Visudo is not included, and there is no sudoers file. A workaround is required! (maybe just create a sudoers file???) (Yes, I copied my sudoers file from an earlier version over and it worked. Here is the file http://www.filedropper.com/sudoers -- link is dead. can you provide a new link to the sudoers file? and where do we copy it to?)


Now you just need to open visudo:
Now you just need to open visudo:
Line 154: Line 160:
shift + c:76
shift + c:76
## rotate the freakin' screen
## rotate the screen
"rotate"
"rotate"
c:235
c:235
Line 175: Line 181:
2=
2=
<pre style="margin: 5px; border: none; padding: 0; background: none;">
<pre style="margin: 5px; border: none; padding: 0; background: none;">
current=`xrandr | grep connected | awk '{print $4}'`
current=`xrandr | grep " connected" | awk '{print $4}'`
if [ $current == "(normal" ]; then val=3
if [ $current == "(normal" ]; then val=3
elif [ $current == "left" ]; then val=0
elif [ $current == "left" ]; then val=0
Line 197: Line 203:


=== So many possibilities ===
=== So many possibilities ===
Despite its small size , the keyboard included in G1G1 versions of the XO has alot of handy extra keys. The "grab" , "journal", "neighborhood", "peers", "home", and "activity" buttons in addition to the four black circle buttons and the two boxes button have yet to be mapped and used. That's not to mention all the combinations with alt, shift, fn, and control keys. If you have any ideas for them please add them to this section.
Despite its small size , the keyboard included in G1G1 versions of the XO has a lot of handy extra keys. The "grab" , "journal", "neighborhood", "peers", "home", and "activity" buttons in addition to the four black circle buttons and the two boxes button have yet to be mapped and used. That's not to mention all the combinations with alt, shift, fn, and control keys. If you have any ideas for them please add them to this section.


== Reference ==
== Reference ==
* Most of the information on this page is gleaned from the [http://olpcnews.com/forum/index.php the OLPC news forums]
* Most of the information on this page is gleaned from the [http://olpcnews.com/forum/index.php the OLPC news forums]

[[Category:Linux distributions]]
[[Category:Linux software]]

Latest revision as of 01:56, 2 November 2011

Xfce is a user front end installed on many OLPC laptops to function alongside or replace the default Sugar user interface. When it is installed on an OLPC laptop the screen brightness and rotation buttons as well as the volume buttons no longer function as expected. The following instructions 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 throughout the rest of this tutorial:

MAKE SURE YOU DO *NOT* DO THE FOLLOWING LINE AS root USER --> YOU NEED TO BE USER olpc

 $ 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 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

((( This section needs updating. In build 711 it is no longer possible to remove / install sudo and thus have access to visudo. Also, there appears to be no sudoers file ))

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 starts up 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

In build 703 sudo is already installed but visudo, used below, is conspicuously absent. The simplest way to get around this would be to remove sudo before reinstalling it:

 # yum remove sudo
 # yum install sudo

(This can't be done in build 711 - sudo is part of package olpc-utils-0.74-2.olpc2 and cannot be installed or removed in its own right. Visudo is not included, and there is no sudoers file. A workaround is required! (maybe just create a sudoers file???) (Yes, I copied my sudoers file from an earlier version over and it worked. Here is the file http://www.filedropper.com/sudoers -- link is dead. can you provide a new link to the sudoers file? and where do we copy it to?)

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 screen
"rotate"
c:235

Other options

Frame button, F11

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"

Rotating the screen counter-clockwise

You can use some of the stuff you've learned in the rest of this tutorial to make the screen rotate counter-clockwise when the rotate button is pressed with the shift key is down. You'll need to write a simple script first:


 File: /usr/bin/xrandr_reverse.sh
current=`xrandr | grep " connected" | awk '{print $4}'`
if [ $current == "(normal" ]; then val=3
  elif [ $current == "left" ]; then val=0
  elif [ $current == "inverted" ]; then val=1
  elif [ $current == "right" ]; then val=2
fi

xrandr -o $val

You'll have to make it executable before adding it to the .xbindkeysrc file:

 # chmod 755 /usr/bin/xrandr_reverse.sh

And now you can add the keybinding:

 ## rotate the screen counter-clockwise
 "xrandr_reverse.sh"
 shift + c:235

So many possibilities

Despite its small size , the keyboard included in G1G1 versions of the XO has a lot of handy extra keys. The "grab" , "journal", "neighborhood", "peers", "home", and "activity" buttons in addition to the four black circle buttons and the two boxes button have yet to be mapped and used. That's not to mention all the combinations with alt, shift, fn, and control keys. If you have any ideas for them please add them to this section.

Reference