Restricting Drawing Tablets to A Bounded Area on Linux and Pop!_OS

Published on 2021-02-04 on Sebastian Mellen's Blog

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.

An image of the Lucidchart diagramming software failing catastrophically when used with time constraints, leading to improper formatting

Creating flowcharts on a video call always leads to chaos.

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).

  1. Make sure you have xinput and xrandr installed:
sudo apt install xinput x11-xserver-utils
  1. Now, plug in your drawing tablet.
  2. 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
  1. 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 with id=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 the HDMI-0 display.
  2. 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/.