0

I've acquired myself XP-Pen Deco mini 7 graphics tablet. Pointer and pressure work out of the box, but I want to rotate it to left-hand mode and change actions on pad and stylus buttons.

I'm using Sway wayland compositor on archlinux.

1 Answer 1

0

Preface

There is official linux "driver" on XP-Pen website (also aur package). From what I was able to discern it is a user-space app (linked with X11-only Qt5), which is supposed to autostart with DE and somehow interact with tablet over USB. It comes with udev rule to make XP-Pen USB device writeable for normal user.

strace showed that it tried every USB device (/dev/bus/usb/*/*) but in the end wasn't able to find my tablet. Maybe you'll have better luck with it

Tablet events handling overview

                                         +————————————————+
                                         |                |
                                         |  Wayland       |
                                         |  compositor    |
                                         |                |
+——————————+  event  +—————————+  event  +——————————————+ |  event  +———————+
|  Tablet  |————————>|  Linux  |————————>|   libinput   | |————————>|  app  |
+——————————+         +—————————+         |              | |         +———————+
                                         | +——————————+ | |
                                         | | libwacom | | |
                                         +—+——————————+—+—+

Wayland compositor (Sway, Mutter, KWin through Qt) uses libinput to handle input devices and their event. It in turn uses libwacom for hardware information about tablet (number of buttons, their codes, if stylus has "rubber" tip, etc.)

libinput can be used with X11 through xf86-input-libinput so following steps aren't limited to Wayland.

Left-hand mode

If libwacom reports that tablet is "reversible", libinput can be configured to translate pointer events from it to left-hand mode.

Basically libwacom is a database of known graphics tablets, each described in .tablet file (see whole list in repo).

You can check if libwacom knows your tablet:

$ libwacom-list-local-devices
/dev/input/event19 is a tablet but not supported by libwacom
Failed to find any devices known to libwacom.

If not, you'll have to create .tablet yourself. For XP-Pen Deco mini 7 I've made following file at /usr/share/libwacom/xp-pen-deco-mini-7.tablet:

# XP-Pen
# Deco mini7
#

[Device]
Name=XP-Pen Deco mini7
ModelName=
DeviceMatch=usb:28bd:0928
Class=Bamboo
Width=7
Height=4.37
Styli=0xffffd;

[Features]
Stylus=true
Reversible=true
Touch=false
Buttons=0

Most important are two options:

  • DeviceMatch specifies how to identify tablet and has format BUS:VENDOR_ID:MODEL_ID. You can find this values with udevadm:
$ udevadm info /dev/input/event19
...
E: ID_VENDOR_ID=28bd
...
E: ID_MODEL_ID=0928
...
E: ID_BUS=usb
  • Reversible indicates that tablet can be used in left-hand mode.

(more details and description for other options can be found in example in repo)

Verify that libwacom now recognizes the tablet:

$ libwacom-list-local-devices
devices:
- name: 'XP-Pen Deco mini7'
  bus: 'usb'
  vid: '0x28bd'
  pid: '0x0928'
  nodes:
  - /dev/input/event19

Now you can configure libinput through your compositor. For Sway add to your config

input type:tablet_tool left_handed enabled

For Gnome and KDE you can use system settings GUI.

NOTE you may need to replug tablet to apply configuration.

Pad and stylus buttons mapping

XP-Pen sends pad button events as separate keyboard device. You can see them with evtest (here buttons are already mapped):

$ sudo evtest /dev/input/event18
Input driver version is 1.0.1
Input device ID: bus 0x3 vendor 0x28bd product 0x928 version 0x100
Input device name: "UGTABLET 6 inch PenTablet Keyboard"
Supported events:
...
Testing ... (interrupt to exit)
Event: time 1648039909.676558, type 4 (EV_MSC), code 4 (MSC_SCAN), value 700e0
Event: time 1648039909.676558, type 1 (EV_KEY), code 29 (KEY_LEFTCTRL), value 1
Event: time 1648039909.676558, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70056
Event: time 1648039909.676558, type 1 (EV_KEY), code 44 (KEY_Z), value 1
Event: time 1648039909.676558, -------------- SYN_REPORT ------------
^Z
[1]+  Stopped                 sudo evtest /dev/input/event18
$ fg
sudo evtest /dev/input/event18
Event: time 1648039909.764562, type 4 (EV_MSC), code 4 (MSC_SCAN), value 700e0
Event: time 1648039909.764562, type 1 (EV_KEY), code 29 (KEY_LEFTCTRL), value 0
Event: time 1648039909.764562, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70056
Event: time 1648039909.764562, type 1 (EV_KEY), code 44 (KEY_Z), value 0
Event: time 1648039909.764562, -------------- SYN_REPORT ------------
Event: time 1648039944.475630, type 4 (EV_MSC), code 4 (MSC_SCAN), value 700e0
Event: time 1648039944.475630, type 1 (EV_KEY), code 29 (KEY_LEFTCTRL), value 1
Event: time 1648039944.475630, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70057
Event: time 1648039944.475630, type 1 (EV_KEY), code 183 (KEY_F13), value 1
Event: time 1648039944.475630, -------------- SYN_REPORT ------------
Event: time 1648039944.551696, type 4 (EV_MSC), code 4 (MSC_SCAN), value 700e0
Event: time 1648039944.551696, type 1 (EV_KEY), code 29 (KEY_LEFTCTRL), value 0
Event: time 1648039944.551696, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70057
Event: time 1648039944.551696, type 1 (EV_KEY), code 183 (KEY_F13), value 0
Event: time 1648039944.551696, -------------- SYN_REPORT ------------

(this is result of pressing first two buttons. Since one of them was mapped to Ctrl+Z, bash suspended evtest)

They can be mapped with hwdb(7). Create file /etc/udev/hwdb.d/62-xp-pen-deco-mini-7.hwdb with contents:

evdev:input:b0003v28BDp0928*
 KEYBOARD_KEY_70005=kp0
 KEYBOARD_KEY_70008=kp1
 KEYBOARD_KEY_700e2=kp2
 KEYBOARD_KEY_7002c=f16
 KEYBOARD_KEY_70016=f15
 KEYBOARD_KEY_7001d=f14
 KEYBOARD_KEY_70057=f13
 KEYBOARD_KEY_70056=z

First line matches device similar to .tablet file and has format b{BUS_ID}v{VENDOR_ID}p{MODEL_ID}. For USB {BUS_ID} is 0003.

Then you write scancode to key mappings in format KEYBOARD_KEY_{scancode}={key}. Scancodes are obtained from evtest output (MSC_SCAN lines), key names can be found in /usr/include/linux/input-event-codes.h and must be in lowercase. In example above I map all but last buttons to generic keys, so then I can bind specific actions to them on per application basis.

For XP-Pen Deco mini 7 default mapping is:

  • 70005 — b

  • 70008 — e

  • 700e2 — leftalt

  • 7002c — space

  • 700e2, 70016 — leftctrl, s

  • 700e2, 7001d — leftctrl, z

  • 700e2, 70057 — leftctrl, kpplus

  • 700e2, 70056 — leftctrl, kpminus

but these are different for every tablet model.

NOTE Since I don't map scancode 700e2, last four keys will be emitted with Ctrl

Stylus buttons events are generated on tablet input itself:

$ sudo evtest /dev/input/event19
Input driver version is 1.0.1
Input device ID: bus 0x3 vendor 0x28bd product 0x928 version 0x100
Input device name: "UGTABLET 6 inch PenTablet"
...
Event: time 1648041701.178269, -------------- SYN_REPORT ------------
Event: time 1648041701.686282, type 4 (EV_MSC), code 4 (MSC_SCAN), value d0044
Event: time 1648041701.686282, type 1 (EV_KEY), code 331 (BTN_STYLUS), value 1
Event: time 1648041701.786243, -------------- SYN_REPORT ------------
Event: time 1648041701.790243, type 4 (EV_MSC), code 4 (MSC_SCAN), value d0044
Event: time 1648041701.790243, type 1 (EV_KEY), code 331 (BTN_STYLUS), value 0
Event: time 1648041704.130289, -------------- SYN_REPORT ------------
Event: time 1648041704.134281, type 4 (EV_MSC), code 4 (MSC_SCAN), value d0045
Event: time 1648041704.134281, type 1 (EV_KEY), code 277 (BTN_FORWARD), value 1
Event: time 1648041704.262281, -------------- SYN_REPORT ------------
Event: time 1648041704.266286, type 4 (EV_MSC), code 4 (MSC_SCAN), value d0045
Event: time 1648041704.266286, type 1 (EV_KEY), code 277 (BTN_FORWARD), value 0

By default lower button (scancode d0044) resulted in "Middle mouse button press" event, which was pretty convenient, but upper had no visible effect. There are two possible ways to utilize it:

  • map to arbitrary mouse button and bind action to this button in application
KEYBOARD_KEY_d0045=btn_forward
  • map to BTN_TOOL_RUBBER to emulate "rubber" pen tip
KEYBOARD_KEY_d0045=btn_tool_rubber

Add preferred variant to /etc/udev/hwdb.d/62-xp-pen-deco-mini-7.hwdb, then compile binary hwdb

$ sudo systemd-hwdb update

and apply mappings to devices:

$ sudo udevadm trigger

NOTE you may need to replug you tablet and/or restart DE applications to use this mappings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.