The Chartreuse Kitsune
HomeBlogHomebrew ComputersProjectsComputersAbout

Linux on the Thinkpad x41 Tablet

The IBM/Lenovo Thinkpad x41 Tablet was released back in 2005 and while the 1.5GHz Pentium M is quite dated now, it still is a somewhat capable machine for lighter tasks. Just don't expect web browsing to be the fastest.

After aquiring mine I promptly replaced the OS installed by the previous owner (Bodhi Linux) with my perferred distro, Debian 10 (Buster).

Out of the box the system works just fine, even the serial based Wacom stylus was working just fine. However the buttons on the tablet screen, along with rotation when in tablet mode were not as is to be expected.

Tablet Screen Buttons

Out of the box the buttons on the tablet screen do not work, and infact are not even recongized by Xorg when using xev. However by checking the raw scancodes using evtest I was able to determine that they were being recognised by Linux just not assigned a keycode for the scancode.

The raw scancodes (in hex) of the buttons on the tablet screen

Through evtest I was able to determine the scancodes for the buttons which just left me to map them to keycodes such that they could be bound to functions within Xorg.

Binding screen buttons

Binding these scancodes to keycodes can be done using udev. Inside /usr/lib/udev/hwdb.d/60-keyboard.hwdb we can add our custom mappings as such. Add the following to the file, either at the end or before the other custom bindings in there.

evdev:atkbd:dmi:bvn*:bvr*:bd*:svnIBM:pn18666GU:pvr*
 KEYBOARD_KEY_67=sleep          # Small button 
 KEYBOARD_KEY_6c=rotate_display # Rotate
 KEYBOARD_KEY_68=prog1          # App Shortcut
 KEYBOARD_KEY_6b=esc            # Escape key
 KEYBOARD_KEY_69=enter          # Enter key
 KEYBOARD_KEY_6e=pagedown       # Down arrow
 KEYBOARD_KEY_6d=pageup         # Up arrow

Keycodes 6e and 6d could also be assigned to up and down arrow keys, and the small unlablled button could be assigned to ctrl-alt-delete instead as appears to be originally intended.

Next the udev database needs to be updated and reloaded:

# systemd-hwdb update
# udevadm trigger

With the scancodes set, these now can be bound within XOrg, so that we can set up screen rotation.

Screen Rotation

For simple screen rotation I made use of the script by user hongcj92 of the Thinkpads.com forum. The post describes setting up both automatic screen rotation using Magick Rotation as well as manual rotation using a script. For manual rotation a bash script reads the current orientation using xrandr, sets the rotation to a counter clockwise rotation of it, and updates the wacom tablet and mouse pointer orientations to match.

I modified the script provided per the instructions, and installed it in /usr/local/bin with execute permissions. My modified script is as follows:

#!/bin/sh

# Find the line in "xrandr -q --verbose" output that contains current
# screen orientation and "strip" out current orientation.

rotation="$(xrandr -q --verbose | grep 'connected' | \
egrep -o  '\) (normal|left|inverted|right) \(' |\
egrep -o '(normal|left|inverted|right)')"

# Using current screen orientation proceed to rotate screen and input
# devices.

case "$rotation" in
    normal)
    # rotate to the left
    xrandr -o left
    xsetwacom set "Wacom Serial Penabled Pen stylus" rotate ccw
    xsetwacom set "Wacom Serial Penabled Pen eraser" rotate ccw
    xsetwacom set "TPPS/2 IBM TrackPoint" rotate ccw
    ;;
    left)
    # rotate to inverted
    xrandr -o inverted
    xsetwacom set "Wacom Serial Penabled Pen stylus" rotate half
    xsetwacom set "Wacom Serial Penabled Pen eraser" rotate half
    xsetwacom set "TPPS/2 IBM TrackPoint" rotate half
    ;;
    inverted)
    # rotate to the right
    xrandr -o right
    xsetwacom set "Wacom Serial Penabled Pen stylus" rotate cw
    xsetwacom set "Wacom Serial Penabled Pen eraser" rotate cw
    xsetwacom set "TPPS/2 IBM TrackPoint" rotate cw
    ;;
    right)
    # rotate to normal
    xrandr -o normal
    xsetwacom set "Wacom Serial Penabled Pen stylus" rotate none
    xsetwacom set "Wacom Serial Penabled Pen eraser" rotate none
    xsetwacom set "TPPS/2 IBM TrackPoint" rotate none
    ;;
esac
Copyright ©2017-2022 Chartreuse