ThinkPad X61 Tablet Automatic Screen Rotation Under Linux
One advantage of a tablet laptop is that you can position and rotate it any way you want. For example, while I ride on the bus I like to hold my ThinkPad x61 in the portrait orientation to maximize the display height of Google Reader that I am looking over. Since X.Org allows you to rotate your display orientation through the xrandr extension, this isn’t much of a problem. However things could be improved, because there is no way to rotate your screen automatically based on the physical orientation of your laptop. I have created a script that will do this by reading information from the X61 hard drive accelerometer and rotate the screen, fix the mouse pointer orientation and change the direction of the arrow buttons on the display. It is based on twalson’s x61 rotate script that alternates between tablet and laptop modes, so quite a lot of the credit goes to him. Note that I have made quite a lot of changes, so the script should not be considered as stable. If you run into any trouble, just leave a comment or contact me directly. In the rest of the post I will document how to install the script on Ubuntu Hardy Heron, but the script should work on any other Linux distribution too.
- Automatic screen rotation based on orientation when in tablet mode
- Rotation is fixed and disabled when in laptop mode
- Fixes orientation of the mouse buttons and wacom stylus
- Minimum treshhold for change of rotation so small deviations won’t change the screen
- Make sure you have a working accelerometer that is reading the proper orientation as tested using the hdaps-gl utility.
- Add the python-xrandr PPA repositry (works on Hardy Heron too) by appending the following line to the end of the /etc/apt/sources.list file:
deb http://ppa.launchpad.net/displayconfig-gtk/ubuntu gutsy main
- Update apt-get’s package list to include python-xrandr:
sudo apt-get update
- Install the necessary packages for the script to work:
sudo apt-get install wacom-tools python-xrandr
- Download the autorotate.py script and place it in the /usr/local/bin directory. Make sure it has execute permissions by running the following command:
sudo chmod +x /usr/local/bin/autorotate.py
- Create a file to hold the information about the current screen mode (laptop vs tablet):
sudo touch /etc/tabletmode
- Create a file /etc/acpi/events/swivel-up with the following content:
# called when tablet screen swivels up (into laptop mode)
event=ibm/hotkey HKEY 00000080 0000500a
action=echo laptop > /etc/tabletmode
- Create a file /etc/acpi/events/swivel-down with the following content:
# called when tablet screen swivels down (into tablet mode)
event=ibm/hotkey HKEY 00000080 00005009
action=echo tablet > /etc/tabletmode
- Restart ACPI to register the events:
sudo /etc/init.d/acpid restart
- Have autorotate.py autostart on GDM. This way it will be available to all users, even during login! This is done by adding the following line to the end of the /etc/gdm/Init/Default file before the exit 0 command:
- Restart GDM to start the script:
sudo /etc/init.d/gdm restart
- Swivel down your screen into the tablet mode, and tilt it at around 45 degrees to test if the script works!
It is possible that you run into some problems, especially if you are missing some dependencies or have other problems. You can get error messages by running the script manually using the following command. Note that you do need to run it with sudo, because the wacom tool needs root privilages.