Monday, March 1, 2010

HP Compaq TC4400 and Ubuntu 9.10 Karmic Koala



A really big plus for Tablet PC users who want to try Linux is that, with the recent versions of Ubuntu based distros at least, the WACOM digitizer is a recognized input source on first boot. Moving the mouse about by hovering the pen just over the display, clicking objects by tapping the screen with the pen, moving objects by clicking, holding, and then dragging -- these are some of the things that can already be done without having to do some extra tinkering. I have tried both Jaunty Jackalape (Ubuntu 9.04) and Karmic Koala (Ubuntu 9.10) on my HP Compaq TC400 Tablet PC, and both versions offer the same kind of first-boot experience.

Unfortunately some other Tablet PC functions of the TC4400 are initially not available, just to enumerate a couple:
  • Screen Rotation of both display and digitizer (landscape to portrait to landscape)
  • Use of the extra buttons on the stylus
  • Use of the Tablet PC Shortcut Buttons on the bezel surrounding the display (the "Quick Launch Buttons", as HP refers to then)
Also, Ubuntu-based Distros tend to cater to the general user -- as such, Tablet PC-specific programs are usually absent from the applications available on first boot. In particular, I wanted the following kinds of applications:
  • a Journaling App that has support for inking (like Windows Journal, or OneNote)
  • an App that allows users to annotate PDFs (like Grahl's aptly named PDF Annotator)
  • an art/drawing App that is able to make use of pressure sensitivity
Linux being Linux, I had a feeling that, although not immediately available, the features that I wanted were nonetheless implementable -- so I did what any determined Linux user would and should do: I searched through community billboards for possible solutions. This post aims to summarize the process, in large part for my own future reference, but hopefully also to help other people (in particular other TC4400 users) who may also be looking for ways to make their Tablet PCs more functional in a Linux Disto. The subsequent steps are meant to be executed in a Karmic Koala installation; some of the steps may have to be modified if the installed Distro is Jaunty Jackalope.

PRELIMINARIES

First off all, it is necessary to install the main utilities to be used in this exercise.

Become a super user in order to have administrative privileges (and subsequently make modifications to the system)

sudo su

Install the utilities to be used to setup the important tablet functions

aptitude install wacom-tools xbindkeys
wacom-tools: "This package provides utilities to test and configure Wacom graphics tablets. You will need kernel and X.Org driver support for your tablet to use them."
    • wacomcpl: "wacomcpl is a simple graphic Wacom driver configuration tool. It changes the pressure sensitivity, click threshold, button functions, cursor mode, speed, mapping, etc. without having to manually modify XF86Config/xorg.conf file. For Cintiq and Tablet PC users, it is also a tool to calibrate the tablet."

xbindkeys: "xbindkeys is a program that associates keys or mouse buttons to shell commands under X. After a little configuration, it can start many commands with the keyboard (e.g. control+alt+x starts an xterm) or with the mouse buttons."

  INSTALL TABLET PC APPS

While not as polished as their Windows counterparts, there are a handful of Linux Apps for Tablet PCs/Handwritten Input that are surprisingly capable. Two of the best examples are CellWriter and Xournal. CellWriter facilitates handwriting-to-text (as the Tablet Input Panel Does on Windows), while Xournal can function as a Journaling App, a Sketching App, and a PDF Annotator.   
CellWriter: "CellWriter is a grid-entry natural handwriting input panel. As you write characters into the cells, your writing is instantly recognized at the character level. When you press Enter on the panel, the input you entered is sent to the currently focused application as if typed on the keyboard."
Xournal: "Xournal is an application for notetaking, sketching, keeping a journal using a stylus. It is free software (GNU GPL) and runs on Linux (recent distributions) and other GTK+/Gnome platforms."
To install both, open an instance of the Terminal app and run the following:

sudo aptitude install cellwriter xournal

CLEAR UP COMMUNICATION BETWEEN HAL AND LINUXWACOM

(Steps courtesy of Ubuntu Forums user Favux.)

Apparently, a major source of complication has been the assignment of names by the Hardware Abstraction Layer (HAL) -- to, say, the WACOM Stylus and Eraser -- that is different from what is expected by linuxwacom. One workaround is to revert the assigned names to what linuxwacom looks for.

Backup the "10-linuxwacom.fdi file" in Karmic to, for example, the User's Desktop (fill in your user account name to [user]):

sudo cp /usr/share/hal/fdi/policy/20thirdparty/10-linuxwacom.fdi /home/
[user]/Desktop/10-linuxwacom.fdi.bak
 
Download "Favux_new-generic_rc2_10-linuxwacom.fdi.txt" from this thread (the hyperlink is at the bottom part of the post); after downloading, open the text file with the Ubuntu text editor by opening the file from Nautilus (Ubuntu's built-in File Explorer).

Open "10-linuxwacom.fdi" for editing:

gksudo gedit /usr/share/hal/fdi/policy/20thirdparty/10-linuxwacom.fdi

After opening "10-linuxwacom.fdi", replace its contents with that of "Favux_new-generic_rc2_10-linuxwacom.fdi.txt". (In other words, copy-and-paste the content of the latter into the former.)

Save the modified "10-linuxwacom.fdi" and then reboot. After rebooting, run the Terminal app and execute the following lines, one after the other:

xinput --list
xsetwacom list

The names assigned to the stylus and the eraser in HAL should now be the same as in linuxwacom.

SETUP SCREEN ROTATION

(Ubuntu Forums user jelera provided a script that, when executed, changes the orientation of both the display and the digitizer from landscape to portrait, or from portrait to landscape; the subsequent script is based on what jelera shared.)

Without installing anything else it is already possible to rotate the display in Ubuntu through the use of the Display Preference utility. For Tablet PCs, this is however only one half of the orientation rotation equation: opting to rotate the display 90 degrees (clockwise), while allowing the visual shift in orientation to portrait from landscape does not similarly shift the Digitizer 90 degrees (clockwise) -- movements of the stylus would thus result in perpendicular movements of the pointer! (The pointer does not mirror the direction of the stylus.)

Open an instance of the Text Editor -- copy and paste the series of commands found below, and then save the resulting script as, say, "/home/
[user]/Tablet PC/rotatescript" (fill in your user account name to [user]):
#!/bin/sh
if [ $(xrandr --dryrun|awk '/LVDS1 connected/ {print $5}') = "normal" ]; then
xrandr -o right
xsetwacom set "stylus" Rotate CW
xsetwacom set "eraser" Rotate CW
else
xrandr -o normal
xsetwacom set "stylus" Rotate None
xsetwacom set "eraser" Rotate None
fi
Once the script has been saved, it may be a good idea to make it executable, and then to move it to "/usr/bin/":

sudo su
chmod +x "/home/[user]
/Tablet PC/rotatescript"
mv "/home//Tablet PC/rotatescript" "/usr/bin/rotatescript"


jelera's script works great! For convenience you may want to make a launcher shortcut on one of the Gnome Panel that runs "rotatescript" -- you could then tap on the shortcut with the tip of the stylus whenever you want to change the TC4400's orientation.

CONFIGURE THE WACOM STYLUS

"wacomcpl" gives users a GUI to tweak some configuration settings of the WACOM Digitizer, including changing what the buttons do as well as calibrating the digitizer on demand. To run simply open an instance of the Terminal app and run:

wacomcpl

As with "rotatescript", you may want to make a launcher shortcut on one of the Gnome Panels for "wacomcpl".

SET UP THE "QUICK LAUNCH" BUTTONS

"xbindkeys" allows custom key mapping: if the assignments for the Quick Launch Buttons are known, commands could then be mapped to these keys. Thankfully, this blog post was able to point out the assignments (technically for the TC1100, but the same are applicable for the TC4400 as well).
   
The first step would be to make xbindkeys start up automatically on login:
  • Open system > Preferences > Startup Applications.
  • Click add.
  • Enter xbindkeys in each box.
  • Click add.
The next step would be to configure "xbindkeys" and assign commands to the Quick Launch Buttons

sudo gedit .xbindkeysrc
       
Enter the following text into the file:
"cellwriter"
b:30
"rotatescript"
b:31
"wacomcpl"
b:32
Save and close the modified ".xbindkeysrc" and then run "xbindkeys":

xbindkeys

The Quick Launch Buttons should now be functional:
  • tapping the "Q" Button with the stylus should launch the WACOM Control Panel
  • tapping the Rotate Button should shift the orientation from Landscape to Portrait, or from Portrait to Landscape.
  • tapping the Input Panel Button should pop up Cell Writer, a decent handwriting-to-text utility.

BONUS: ENABLE PRESSURE SENSITIVITY IN GIMP

According to the initial Developers of the GNU Image Manipulation Program (GIMP), "GIMP is our answer to the current lack of free (or at least reasonably priced) image manipulation software for GNU/Linux and UNIX in general." It has been one of the mainstays of the most popular Linux Distros, including Ubuntu and its variants.

While GIMP is available on first boot, it is not -- as to be expected -- configured to take advantage of the WACOM Digitizer's pressure sensitivity. As MetalMusicAddict points out in an Ubuntu Forums thread, this is easy enough to correct:
  • File--- Preferences--- Input Devices--- "Configure Extended Input Devices".
  • under "Device" you will have 3 settings: Cursor, Eraser and Stylus. Set them from "Disabled" to "Screen".
After saving your preferences, you should now be able to take advantage of pressure sensitivity in GIMP.

REFERENCES
http://ubuntuforums.org/showpost.php?p=7234134&postcount=176
http://ubuntuforums.org/showthread.php?t=1294392   
http://ubuntuforums.org/showthread.php?t=1100119
http://ubuntuforums.org/showthread.php?t=25151
http://www.unifyingtheory.net/tabletubuntu9.10.html