Mapping tablet input to your monitor in Linux

March 4, 2020

To find out what your device is called compare the output of xinput --list before and after you plug the tablet in. For my tablet it looks something like this:

⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ ...
⎜   ↳ HID 256c:006e Pad                         id=16   [slave  pointer  (2)]
⎜   ↳ HID 256c:006e Pen Pen (0)                 id=17   [slave  pointer  (2)]
⎜   ↳ ...
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ ...
    ↳ HID 256c:006e Pen                         id=15   [slave  keyboard (3)]
    ↳ ...

Most devices have a human-readable name like “Huion H1060P Pen”, but my tablet calls itself “HID 256c:006e”. The X input devices associated with it are “HID 256c:006e Pad”, “HID 256c:006e Pen”, and “HID 256c:006e Pen Pen (0)”.


To find the name of the monitors connected to your computer, run xrandr --listmonitors. The name of the output is the last word on the line.

Monitors: 2
 0: +*DisplayPort-0 1920/509x1080/286+1920+0  DisplayPort-0
 1: +HDMI-A-0 1920/509x1080/286+0+0  HDMI-A-0

In this example the outputs are “DisplayPort-0” and “HDMI-A-0”.


Run xsetwacom --set "<tablet>" MapToOutput "<output>" and move your pen around to test it. If your tablet is associated with more than one device try each of them until you find the one that works.

Normally you’d put that xsetwacom command in your .xinit or .xprofile, but that only works if the X input device already exists when you log in. If you want your tablet to be mapped when you plug it in you need a configuration file in /etc/X11/xorg.conf.d/.

Once you’ve got the tablet mapped the way you want, use xinput list-props "<tablet>" to get the transformation matrix.

Device 'HID 256c:006e Pen Pen (0)':
        Device Enabled (149):   1
        Coordinate Transformation Matrix (151): 0.500000, 0.000000, 0.500000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
        Device Node (274):      "/dev/input/event3"
        Device Product ID (275):        9580, 110
        libinput Tablet Tool Pressurecurve (426):       0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 1.000000, 1.000000, 1.000000

The numbers after “Coordinate Transformation Matrix (151):” are what we want.

        Coordinate Transformation Matrix (151): 0.500000, 0.000000, 0.500000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000

Add the following to /etc/X11/xorg.conf.d/72-wacom-options.conf:

Section "InputClass"
        Identifier      "<identifier>"
        MatchProduct    "<tablet>"
        Option          "TransformationMatrix" "<matrix>"
EndSection

Replace <identifier> with any string, <tablet> with your tablet name, and <matrix> with the numbers after “Coordinate Transform Matrix (151):” from xinput list-props <tablet>.

Restart your computer. If it didn’t work, try changing <tablet> to one of the other X input devices you found in the first step. This time the correct one might be under “Virtual core keyboard” instead of “Virtual core pointer”.

In my case, only “HID 256c:006e Pen Pen (0)” works for xsetwacom, but “HID 256c:006e Pen” is required in the xorg configuration file.1

My configuration looks like this:

section "InputClass"
        Identifier      "H1060P transformation matrix"
        MatchProduct    "HID 256c:006e Pen"
        Option          "TransformationMatrix" "0.5 0.0 0.5 0.0 1.0 0.0 0.0 0.0 1.0"
EndSection

  1. Probably because “HID 256c:006e Pen Pen (0)” is a virtual subdevice of “HID 256c:006e Pen”

    I learned this by searching .local/share/xorg/Xorg.0.log for “HID 256c:006e Pen Pen (0)” while I was troubleshooting. Your logfile might be /var/log/Xorg.0.log. See man xorg for more details. ↩︎

Permanent link to this article

Preventing Neovim from using XTerm scroll margins

February 12, 2020

XTerm has the ability to set left and right scroll margins to speed up scrolling. The scroll margin capability isn’t described by terminfo1 and some terminals that set $TERM to “xterm” don’t support it so Neovim has a few heuristics to detect when it is actually running in XTerm.

Unfortunately not all of XTerm’s emulation levels support scroll margins. For example, when using the VT3402 emulation level Neovim correctly detects XTerm and tries to use scroll margins with poor results.

One of the heuristics Neovim uses is whether the environment variable $XTERM_VERISON is set. Therefore we can disable scroll margins by using XTERM_VERSION= nvim to launch Neovim.3 To avoid typing so much I added the following command to my .bashrc:

# Set XTERM_VERSION to the empty string and launch nvim
# Note the space between 'XTERM_VERSION=' and 'nvim'
alias nvim='XTERM_VERSION= nvim'

If you don’t want to use an alias you can use unset XTERM_VERSION instead. Note that this option will apply to all commands, not just nvim.


  1. :help xterm-scroll-region↩︎

  2. I use XTerm’s VT340 emulation for its SIXEL graphics support. ↩︎

  3. I intentionally avoided modifying $TERM because the correct value isn’t supposed to support colored text even though xterm allows it. ↩︎

Permanent link to this article