7c0h

Genius MousePen i608 in Debian Linux

I'm the proud owner of a Genius MousePen i608 graphic tablet (also known as UC-LOGIC Tablet WP8060U). This tablet is quite old and cheap, which is more often than not a recipe for headaches.

One very specific problem that I have: my tablet has an aspect ratio of 4:3, like old computers did, but both my desktop and laptop's screens have an aspect ratio of 16:9. Why is this a problem? Because my computer believes that the tablet and screen have the same aspect ratio, and whenever I draw a circle on my tablet it comes up on screen as an oval.

There are two possible solutions to this issue. One is changing my screen's resolution to match the 4:3 aspect ratio, which is annoying: I have to change the screen settings, then fiddle with my actual, physical screen so it doesn't stretch the image, and then I have to undo both steps once I'm done. The second solution requires a bit more calculations, but it's the right way: we'll configure the tablet in such a way that Linux recognizes the difference in ratios.

To be more precise: We will define a rectangle with the same height as the screen and a proportional width (sticking to the 4:3 ratio between width and height), we will position that rectangle in the center of the screen, and all movements in our tablet will only apply to that section of the screen. All movements on the tablet will translate to this rectangle without distortion, and if we need to interact with the screen outside this area we can still use our mouse.

The following code will run all the numbers for us. In essence, it will calculate the required set of parameters, and then it will modify the property Coordinate Transformation Matrix of xinit accordingly:

# Get the current screen resolution
resolution=`xrandr | grep '*' | cut -f 4 -d ' '`
width=`echo ${resolution} | cut -f 1 -d 'x'`
height=`echo ${resolution} | cut -f 2 -d 'x'`

# Get the proper tablet width, according to the 4:3 proportion
tablet_width=`echo "${height} 3 / 4 * n" | dc`

# We need to calculate four parameters c0, c1, c2, c3. For that, we use the
# 'dc' utility, which uses postfix notation (i.e., you write "7/3" as "7 3 /").
#
# Note: if you want to move the usable section of the screen left or right,
# take a look at the 'x offset' value. Also note that, since we are using the
# entire height of the screen, the 'y offset' is simply 0.

# Touch area width / width
c0=0`echo "7 k ${tablet_width} ${width} / n" | dc`
# Touch area x offset / width
c1=0`echo "7 k ${width} ${tablet_width} - 2 / ${width} / n" | dc`
# Touch area height / height
c2=1.0
# Touch area y offset / height
c3=0.0

# Obtain the device ID for the graphics tablet. Note that UC-LOGIC is my device
# ID, but yours may be different
device=`xinput | grep UC-LOGIC | head -n 1 | cut -f 2 -d '=' | cut -f 1`
# Set the Coordinate Transformation Matrix
xinput set-prop ${device} --type=float "Coordinate Transformation Matrix" ${c0} 0 ${c1} 0 ${c2} ${c3} 0 0 1

And that's it! It happens to me often that the transformation doesn't work straight away, in which case unplugging and plugging the tablet again solves the problem. A second issue with every reinstall is that the X server sometimes refuses to recognize my tablet. I solved that problem by adding the following lines to the /etc/X11/xorg.conf file:

Section "InputClass"
    Identifier "evdev tablet catchall"
    MatchIsTablet "on"
    MatchDevicePath "/dev/input/event*"
    Driver "evdev"
EndSection