Restricting Drawing Tablets to A Bounded Area on Linux and Pop!_OS
Introduction
I recently bought a drawing tablet to use as a sort of “digital whiteboard” on video calls. I think in large blocks of architecture, so having a whiteboard makes it a lot easier for me to communicate what I’m thinking to others. Using a whiteboard in real-time helps me sketch out and explore new ideas more concretely. Unfortunately, COVID has preempted in-person meetings for now, so I’ve had to find a way to do this digitally. Until recently, I’d been trying to do this with Lucidchart, which always ended in disaster.
I decided to try a drawing tablet, and settled on the Huion H640P, which I snagged for a mere $34.99. I planned to use this tablet to draw and use Krita (an open source painting program developed by KDE) as my “digital whiteboard surface”. Once the tablet arrived and I got everything set up (which worked very smoothly, thanks to Pop!_OS/Ubuntu), I ran into one big problem — I had a multi-monitor setup, and the drawing pad’s stylus was tracking across all of them. I had assumed that Krita would be able to capture the tablet’s input, and redirect that to the drawing surface, but my stylus was moving my mouse around both screens.
There are a few ways to “fix” this issue, although none of them involve Krita capturing the tablet’s input directly. I’ll show you two different methods that have worked for me.
Method 1: “xinput map-to-output”
This method is the quickest and easiest, but all it will do is map your input device (your drawing tablet) to an output device (the monitor you’re running your drawing pad software on).
- Make sure you have
xinput
andxrandr
installed:
sudo apt install xinput x11-xserver-utils
- Now, plug in your drawing tablet.
- Once your drawing tablet is plugged in, run these commands:
xinput
xrandr
These commands should give you a result that looks like this (I have omitted a few entries to focus on the important parts):
sebmellen@pop-os:~$ xinput
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ CORSAIR Corsair Mouse id=11 [slave pointer (2)]
⎜ ↳ HUION Huion Tablet_H640P Pen id=20 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Power Button id=7 [slave keyboard (3)]
↳ HUION Huion Tablet_H640P Keyboard id=9 [slave keyboard (3)]
↳ HUION Huion Tablet_H640P Pen id=10 [slave keyboard (3)]
sebmellen@pop-os:~$ xrandr
DVI-D-0 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 476mm x 268mm
1920x1080 60.00*+
HDMI-0 connected primary 1920x1080+1920+0 (normal left inverted right x axis y axis) 598mm x 336mm
1920x1080 60.00*+ 74.97 59.94 50.00
-
Identify the devices you want to target. In this case, we’re looking for:
- A “Virtual core pointer” slave input returned from the
xinput
command. I’ll use the one withid=20
, the “HUION Huion Tablet_H640P Pen”. - A display returned from the
xrandr
command. My main monitor is connected via HDMI, so I know to use theHDMI-0
display.
- A “Virtual core pointer” slave input returned from the
-
Use
xinput map-to-output
and place in your input id and display identifier in this format:
xinput map-to-output <XINPUT_CORE_POINTER_ID> <XRANDR_DISPLAY_ID>
So I’ll run the following:
xinput map-to-output 20 HDMI-0
Done!
Method 2: “xrestrict”
xrestrict is a “utility to modify the ‘Coordinate Transformation Matrix’ of an XInput2 device.” I recommend this article from its creator if you’d like to know more about xrestrict: https://ademan.wordpress.com/2014/11/29/inexpensive-monoprice-tablet/.