03 May 2009

Ubuntu 9.04 Jaunty on a Thinkpad X41 Tablet

Introduction and Other Easy Things

I recently bought a Thinkpad X41 tablet cheap off eBay. And, because it's the kind of thing I do, I promptly set to work installing the latest release of Ubuntu (9.04, Jaunty Jackalope) on it. Since the X41t doesn't have an optical drive, I installed via LiveUSB. The USB can easily be created from an existing Ubuntu install or LiveCD using the included USB Startup Disk Creator (System -> Administration -> USB Startup Disk Creator), or from Windows via instructions like these or these.

I won't trouble you with installation instructions, because the installer is well set up, the Ubuntu Installation Guide is very good, and I didn't have to do anything special to get it working. Installation took about 15 minutes (seriously: very fast), and afterwards it took about 30 seconds to go from GRUB to the login screen.

I'm happy to say that basically everything worked out of the box - including the wireless card and basic tablet functionality. For handwriting recognition, I used Synaptic to install the equivalent of Windows XP's Tablet Input Panel, Cellwriter. And, because it's useful, I installed a Windows Journal equivalent, Xournal.

Two things did not work right away: the tablet hardware buttons (including special PageUp and PageDown keys, a screen rotation button, and a few others), and (since there was no button for it) any kind of screen rotation that didn't involve going through the control panels. The volume keys work, but apparently control the hardware volume level (as distinct from the software volume level set in the Sound control panel), and therefore have no on-screen display.

My key resources for getting these things working were LIKEN Apuntes's Installing Linux, Ubuntu 8.04 Hardy, on a IBM X41 Tablet and Thinkwiki.org, which is a staggeringly good resource for getting Linux to work on Thinkpads.

Tablet Keys

Tablet keys were not actually difficult to make work, but took me a long time because Thinkwiki was down. My understanding of the problem is this: every keypress generates a hexadecimal key scancode in the kernel, which is then passed to X and assigned a separate keycode from 0 to 255. Keycodes from 0-119 are used for standard keyboard keys, and keycodes 120 and above are mostly unused. Once you find the keycodes the kernel uses, it's a trivial matter to find set a keycode in X and assign shortcuts to it. Unfortunately, in 9.04, the kernel's keyboard mask is set to disregard those buttons entirely, making it very difficult to find those keycodes.

Fortunately, though, Thinkwiki has an article on Tablet Hardware Buttons. Armed with these keycodes, I needed only edit my /etc/rc.local (sudo gedit /etc/rc.local) to assign those keys codes in X at startup. The keycodes for the tablet PageUp, PageDown, Enter, and Escape buttons aren't arbitrary: they're the same ones used by the normal PageUp, PageDown, Enter, and Escape keys. For those, add these lines to /etc/rc.local:

# PageDown, PageUp, Enter, Escape
setkeycodes 6e 109

setkeycodes 6d 104
setkeycodes 69 28

setkeycodes 6b 1

...where 6e, 6d, 69, and 6b are the kernel scancodes in the Thinkwiki article I linked, minus the '0x', and 109, 104, 28, and 1 are the keycodes X uses for PageDown, PageUp, Enter, Escape. If you're interested, you can find out what keycode X uses for what key by entering "sudo dumpkeys" (or, since the output is very long, "sudo dumpkeys | less") into the terminal. Sorry if that's a little over-deliberate.

For the other three keys, you can assign keycodes fairly arbitrarily. All the unused keycodes will be at the end of the dumpkeys output; I used 130, 131, and 132 for the Tablet Menu, Rotate, and Ctrl-Alt-Del keys:

# Tablet Menu Key
setkeycodes 68 130
# Tablet Rotate

setkeycodes 6c 131

# Tablet Ctrl-Alt-Del Key

setkeycodes 67 132

These keys are a little trickier, though, because they don't do anything by themselves. I wanted to assign my Tablet Menu key to open up Cellwriter, so I went to System -> Settings -> Keyboard Shortcuts, hit the "Add" button at the bottom, created a "Cellwriter" shortcut which called on the cellwriter command. Then, I clicked the shortcut box and pressed the Tablet Menu key, and the name X uses for that keycode showed up in the box. Unfortunately, when I was done with that, my Tablet Menu key still didn't do anything.

As a workaround, I went to the configuration editor (gconf-editor in terminal) and from there to apps -> metacity -> keybinding_commands. I arbitrarily assigned command_11 to cellwriter, then went to apps -> metacity -> global_keybindings and assigned run_command_11 to the name the Keyboard Shortcuts control panel gave when I pressed the Tablet Menu key. This is incredibly clumsy, but it worked for me.

I left the Ctrl-Alt-Del key alone, because I couldn't think of anything I wanted to do with it. The Tablet Rotate key requires some extra work.

Tablet Rotation

LIKEN Apuntes has a script and very good directions for setting up your tablet screen to rotate. You can even make the screen rotate automatically when it swivels. If you follow those directions, your tablet will screen will rotate automatically, and you can use gconf-editor to assign, say, command_12 to /usr/local/bin/rotatetablet, and run_command_12 to whatever name Keyboard Shortcuts gives you for your Tablet Rotate key.

There is a problem with this. Your screen will rotate, but the tablet input will not, making pen use awkward at best. This is because of a change in the way Ubuntu Jaunty interprets tablet input. Never fear; there is a fix. I've taken it directly from post 104 of this thread on the Ubuntu forums. Without further ado, run:

sudo gedit /etc/init.d/wacomtohal

and paste in these lines:

#! /bin/sh
## find any wacom devices
for udi in `hal-find-by-property --key input.x11_driver --string wacom`
type=`hal-get-property --udi $udi --key input.x11_options.Type`
## rewrite the names that the Xserver will use
hal-set-property --udi $udi --key info.product --string $type

Save it, close it, and run these two commands in terminal:

sudo chmod +x /etc/init.d/wacomtohal
sudo update-rc.d wacomtohal defaults 27

After you've done that, restart and everything should work just fine.


Tablet PC support in Linux obviously isn't great, but with a little work the tablet can be made to do everything you'd expect from Windows XP Tablet Edition. Cellwriter and Xournal aren't as good as the Tablet Input Panel and Windows Journal (Cellwriter's handwriting recognition is fairly rudimentary, and Xournal doesn't have it at all), but Ubuntu is snappy on the X41t, and even snappier if you switch (as I did) from the default Gnome desktop environment to Xfce - a simple matter of installing xfce-4 in Synaptic, going to Options -> Select Session and selecting Xfce. It'll even ask you if you want to make it default.

Overall, I'm very happy with the tablet functionality - handwriting recognition isn't something I care much about, since any serious input I do will be through the keyboard anyway. Inking in Xournal is perfectly satisfactory for notetaking, and the ability to annotate PDFs is a nice feature. My only complaint is that Flash videos (from YouTube and Hulu, mostly) are choppy in fullscreen or HD under Ubuntu. This is not the machine's fault, though, or even Ubuntu's - Flash videos run fine in Windows, and higher-definition video formats run fine in Ubuntu using VLC or MPlayer. The fault lies entirely at the door of Adobe's poor Flash implementation in Linux.

That's it - it works.


Phillip said...

Thank you IMMENSELY for this post! I've just installed Jaunty on my old X41t and your little write up and directions to other helpful information helped INCREDIBLY!

I'm a beginning Linux user and your walkthrough was a great intro to the different commands and workarounds that the linux system has. And of course the joy when hours and hours of tinkering finally results in the intended output (rotation, tablet working correctly) is fantastic to.

Thanks you!!!

Phil C.

zoot said...

Thanks for the post! It is appreciated!

However, I'm still having issues with some of the hardware buttons and the hdaps auto-rotation. The hdaps module wasn't loading for me so I had to add a line in my /etc/modules file with the word hdaps to get it to load the module on boot, or else the hdaps-gl command refuses to work.
The wacomtohal script, however, works perfectly.
Since my autorotation isn't quite up to snuff, I've added a link to the rotatetablet command to the panel. It does the job for now.

Tim said...

Things were working fine in Ubuntu 8.04, but Jaunty broke most of it.

I was able to make everything work again based on what you've written.

Thanks for the article!

schmiddo said...

Hey, thanks a lot for this tutorial.

I ure XBINDKEYS for the rotate-button.
Give it a try, works perfect!

Sean said...

Thanks for the great info. If you have a few bucks to spare... there is an "official" ssd from Lenovo for the X41... It's SLC and greatly improves the performance over the pokey HDD the machines came with. Do an ebay search on "Lenovo X41 SSD" to find them.

David Landes said...

Now if someone would come up with a way to package all those changes, tweaks and scripts into a small package called something like "ThinkPad X41t Compatibility Pack" that I can simply install under synaptic... then Ubunutu would win me over.

Tom said...

This post helped me out a lot. Thank you very much for taking the time to write it.

Barkus said...

Wow... great write-up. We have a few X41 devices laying around here and were wondering what to do with them. I thought "I wonder how Ubuntu would run on it" and POOF... there's your post in the first google search result. Good show man... good show!

Glenn Jackson said...

I published some updated information on Thinkpad X41 working with Ubuntu Lucid, with lots of help from your blog, Words Are All Lies. Thank you very much! You can find them on ubuntuworks.blogger.com
Thanks again! Glenn

Glenn Jackson said...

Sorry, I meant ubuntuworks.blogspot.com


Nicolas said...

This is the best source of information I have found for setting up the x41 tablet. All of these things work excellently! Don't be scared to try these out!