Tuesday, November 25, 2008

Automatic rotation on its way

I got a new laptop in January 2008, an HP 2150p. It has a great feature: hard disk protection when the laptop falls. Well, by itself I don't think it's a great feature at all, I'd rather stay very careful and never let the laptop fall at all. However, what this meant is that it contains an accelerometer. Since I discovered this, I've wanted to have a great feature, the same one which is available on the expensive phones (like the iPhone) and in some photo cameras (like my Canon A530), the screen automatically rotates when you physically rotate the device. It's especially useful when reading articles or books: you open the file, rotate the computer and suddenly one page = one screen.

Before going further, let's recap why an accelerometer is useful for this. An accelerometer measures the acceleration, so shouldn't it detect something only when it moves, and not when it is standing rotated or not? Well, all the trick is that we can assume the user is on earth (or a planet more generally), and that the user keeps his fits on the ground. The beauty of the accelerometer is that it detect all the accelerations, including G, the gravity! So, assuming that you are on earth and that you are not taking off in a rocket plane, the main acceleration vector indicates the direction of the ground... so convenient!

Getting the functionality working in Linux was not so hard. Mainly because Yan Burman had already tackled the main problem of writing a driver for the accelerometer. However, the real fun is to have it as a default feature for anyone using Linux. Having the ad-hoc solution is fine, but the generic solution is worth thousand times more! For this, I ended up becoming the maintainer of the driver (now named lis3lv02d) and it got recently accepted in Linus' tree. It will be part of 2.6.28...

But that's merely half the journey. We need also a daemon which observes the data obtained by the accelerometer and rotates the screen accordingly. For now I have my own little script which does this. On the long term it would be good to have it integrated with the normal desktop. Let's say at least in Gnome, I would like to get this feature integrated with the new xrandr plugin.

Last but not least, after some usage I realised that there is an annoying problem when rotating the screen with the laptop: the touchpad stays not rotated. Moving the cursor requires some special mental training! So, the obvious question is how to do that. There is unfortunately no directly available solutions. However, I'm hopeful that with the Input Device Properties that Peter Hutterer added to Xorg, plus the work by Mildred Ki'Lya for changing the rotation of the synaptic touchpad driver. To be totally generic, it would be better if any input device could be rotated (the same way), especially the evdev driver should support this as well...

So the complete ad-hoc solution is nearly there, but not yet. And the generic and upstream solution still needs lots of integration at various levels... but it's on its way! Whoever is also interested is welcome to try to create patchs (for Gnome, for Xorg) and share them.

3 comments:

jmcnaught said...

Hi Éric,

Nice auto-rotate-display.py script. Is there a newer version?

Also is there a license for the script? I couldn't see one.


thanks,
Jeremy

Unknown said...

Hello,
Yes, I've updated it a bit, also including contributions from other people and starting to write the code handling the rotation of the input devices.

It's now hosted as a git project at
http://github.com/pieleric/AutoRotateDisplay

Eric

jmcnaught said...

Cool! Thanks!