Thursday, May 16, 2013

Remapping a graphic tablet in Linux (using xinput)

This is how I set up my second hand Wacom Intuos 1 graphic tablet (old but very satisfying hardware) under Ubuntu 12.04.


4:3 to 16:9 conversion

The Xinput command

In fact it worked all "plug'n'play", except for the fact that my screen is 16:9 and my old Wacom Intuos 1 tablet is 4:3. This meant that when I drew a circle on my tablet, it was an ellips on screen.

In Linux this can be remedied by the "xinput" command. Without going into too much detail, what you should do is the following. (I found the basic info I needed on the "Calibrating Touchscreen" page on the Archlinux wiki).

First, with your tablet connected (it has to be connected before boot), type in a terminal (no need to be root or use sudo):
xinput list
The output in my case is, concerning the tablet,
  • Wacom Intuos 9x12 stylus
  • Wacom Intuos 9x12 eraser
  • Wacom Intuos 9x12 cursor
These are the devices you should remap, all three (or more or less in your case) of them.


The command for remapping for instance the "stylus" device is the following:
xinput set-prop "Wacom Intuos 9x12 stylus" --type=float "Coordinate Transformation Matrix" 1 0 0 0 1.33333 0 0 0 1
where
  • "Wacom Intuos 9x12 stylus" is the device in question
  • 1.33333 is the factor by which the tablet is horizontally "diminished". Underlying math, for those interested:
    • 4:3 = 16:12 (multiply numerator and denominator by 4)
    • conversion 16:12 -> 16:9 : the x conversion factor is 12/9 = 1.33333
This "deactivates" a horizontal border at the bottom of your graphic tablet (near you); the remaining active field has the desired widescreen 16:9 ratio.


If you prefer, as I do, to rather deactivate the top border so that your active drawing field is as close as possible to you, you should use an offset factor. The command then becomes (note the -0.33333 value):
xinput set-prop "Wacom Intuos 9x12 stylus" --type=float "Coordinate Transformation Matrix" 1 0 0 0 1.33333 -0.33333 0 0 1
You have to execute this command not only for the "stylus", but for every of your tablet "sub-devices", in my case:
xinput set-prop "Wacom Intuos 9x12 stylus" --type=float "Coordinate Transformation Matrix" 1 0 0 0 1.33333 -0.33333 0 0 1
xinput set-prop "Wacom Intuos 9x12 eraser" --type=float "Coordinate Transformation Matrix" 1 0 0 0 1.33333 -0.33333 0 0 1
xinput set-prop "Wacom Intuos 9x12 cursor" --type=float "Coordinate Transformation Matrix" 1 0 0 0 1.33333 -0.33333 0 0 1

Making changes persistent throughout reboots

Now the problem is that these changes are not persistent throughout reboots, so you have to re-enter the commands every time you restart your computer. There is of course a simple solution for this: making a simple shell-script and getting your linux to run it at boot.

1. Making the script

For the shell script open a text-editor (i.e. GEdit or Mousepad or other), and type:
#!/bin/sh
xinput set-prop "Wacom Intuos 9x12 stylus" --type=float "Coordinate Transformation Matrix" 1 0 0 0 1.33333 -0.33333 0 0 1
xinput set-prop "Wacom Intuos 9x12 eraser" --type=float "Coordinate Transformation Matrix" 1 0 0 0 1.33333 -0.33333 0 0 1
xinput set-prop "Wacom Intuos 9x12 cursor" --type=float "Coordinate Transformation Matrix" 1 0 0 0 1.33333 -0.33333 0 0 1
Save it as (for instance) wacom.sh in your home-directory or any other place where you can find it afterwards.

2. Make the script executable

Now you need to make it executable. One way is to use Nautilus, the file browser, right click on the file, choose "Properties" (at the bottom) and in the "Permissions" tab, check the checkbox at the bottom that says "allow execution".
Or, in a terminal, navigate towards the directory where you saved wacom.sh and type:
chmod +x ./wacom.sh
At this stage your script is ready. You can test it out by typing in a terminal, while you're still in the right directory:
./wacom.sh
You should see the changes directly when you use your tablet.

3. Auto-execute the script on boot

Now the only thing left is to make linux run the script at every boot.

For this, launch the program "Startup Applications" (should be installed by default). Click on "Add" and fill in the form. The name and optional commentary you can choose freely, the most important is the command:
/path/wacom.sh
where "path" is of course your particular path, the directory where the script is saved, i.e.
/home/jeff/wacom.sh

That's it. Reboot and test... Good luck!


Making the active field smaller

I bought a big graphic tablet and found that actually a smaller one is more useful for my type of work. So instead of buying a smaller one, I used again the xinput command to "make" it smaller (that way, if I need it bigger, I just change the xinput values and I have a big one again). How to do this:

If we represent the Coordinate Transformation Matrix used in the above commands (i.e. 1 0 0 0 1.33333 -0.33333 0 0 1) as a1 a2 a3 b1 b2 b3 c1 c2 c3, and the conversion factor for widescreen correction as Cf then:
  • always b2=a1*Cf, this way the widescreen conversion is correct at all times. (If you don't need to do this conversion, then for you Cf = 1).
  • the bigger a1 is, the smaller your active field becomes on your tablet. 
    • If a1=1, then your active field is at it's biggest, full size
    • If a1=2, then it becomes half this size
    • If a1=3, then it becomes one third this size
    • and so on
  • a3 and b3 are resp. the horizontal and vertical offset.
    • If these values are 0, then your active field is placed at the top left of your tablet
    • to move your active field towards the bottom right, these values need to be negative. You should experiment a bit with values. To put a small active field in the bottom left corner of my tablet (taking into account the widescreen conversion, see above), I had to use the matrix: 2 0 0 0 2.666666667 -1.666667 0 0 1.
So finally I made two scripts, wacom_A4.sh and wacom_A5.sh. According to the desired configuration, I execute one or the other.


If you appreciated this article for some reason or another, please share it (see the buttons below), and, of course, don't forget to Flattr! (Why?)


2 comments:

  1. So I'm having issues with my remapping. I'm trying to do basically the opposite as your setup. I have a 4/3 monitor and a 16/9 wacom tablet. I know my device identifiers and have made many erroneous remapping changes, but can't seem to figure out how to chop off the side of my tablet instead of the bottom of my monitor.

    ReplyDelete
  2. Wow OK I fixed it myself... After a little fiddling I figured out that I was changing the wrong part of the matrix, mine needed to look like this "1.33 0 0 1 0 0 1". All is well now and I think my skull is a little more crowded so thanks for the excellent tutorial! Check out my digital sketches that should be getting better now that my tablet isn't squashed. http://sketchbank.wordpress.com/

    ReplyDelete