Tuesday, 23 February 2016

Ubuntu linux: how to restrict a graphic tablet to only one monitor (in a dual monitor setup ;)

I have 2 monitors that are placed on top of each other, like this:

My graphical tablet (Genius EasyPen i405X) is covering by default the entire (summed-up) area, which means that only about half of the tablet is usable for a MyPaint drawing that is opened only on the Benq monitor.

What I want to do is to restrict the tablet movement only to Benq, ie: tablet's physical margins should correspond to Benq ones.

Let's get the needed parameters. The monitors resolution and offset can be seen by launching xrandr in command line:

optimus:~$ xrandr
Screen 0: minimum 320 x 200, current ...
LVDS connected (normal left inverted right x axis y axis)
   1366x768      60.02 +
   1280x720      59.86 

480 x 1142, maximum 16384 x 16384HDMI-0 connected primary 1920x1080+338+1080 (normal left inverted right x axis y axis) 598mm x 336mm
   1920x1080     60.00*+  50.00    59.94 
   1920x1080i    60.00    50.00    59.94 
   1680x1050     59.88 
VGA-0 connected 2560x1080+0+0 (normal left inverted right x axis y axis) 673mm x 284mm
   2560x1080     59.98*+
   1920x1080     60.00 
   1680x1050     59.95 
The first screen is laptop's one that is inactive. Then, each monitor can be found based on the cable/socket it's on. In my case Benq is on HDMI and AOC is on VGA.

Xrandr displays all possible resolutions for each monitor but we need only the one that is active, marked with * (btw, the "+" means it is the recommended resolution). I have trimmed many of those for brevity and in fact we need only the first line of each, the long one where we have the resolution and also the offset.
As you can see (see also the picture) AOC (on VGA) has a resolution of 2560x1080 and it has offset 0 and 0 (it's top left corner is in the zero of the axis system).
More interesting for me, BenQ has resolution of 1920x1080 and horizontal offset 338, while the vertical one is 1080, i.e. Benq is lower that the 0 axis point with exactly the height of AOC.
(There are some distances in reality between monitor margins, but obviously these are not taken into account.)

So, let's write all down:

TotalHsize: 2560 (i.e. the Horizontal resolution of AOC, that "includes" BenQ)
TotalVsize: 2160 (i.e. the summed up Vertical resolution of both, as they are stacked: 1080+1080)
BenqHsize: 1920
BenqVsize: 1080
BenqHoffset: 338
BenqVoffset: 1080

These are all the input data we need. Now, let's calculate the proportions (or relative values):

BenqRelHsize = BenqHsize / TotalHsize = 1920 / 2560 = 0.75
BenqRelVsize = BenqVsize / TotalVsize = 1080 / 2160 = 0.5
BenqRelHoffset = BenqHoffset / TotalHsize = 338 / 2560 = 0.13203125
BenqRelVoffset = BenqVoffset / TotalVsize = 1080 / 2160 = 0.5

So, finally, the command we should launch looks like this:

xinput set-prop "Tablet name as detected by xinput --list" --type=float "Coordinate Transformation Matrix" RelHsize 0 RelHoffset 0 RelVsize RelVoffset 0 0 1

which in my case, for Benq, is:

xinput set-prop "Genius EasyPen i405X" --type=float "Coordinate Transformation Matrix" 0.75 0 0.13203125 0 0.5 0.5 0 0 1

Launch it and it's working!

This will not survive a reboot so you should do something about it if you care. Personally, I have just added the above line in a script that I run each time I use the tablet (which is quite rare in my case).

For more info see the sources I used:



No comments:

Post a Comment