Skip to content

Instantly share code, notes, and snippets.

@rowantran
Created May 19, 2019 17:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rowantran/329000023ee4a64f908fb71fc044585f to your computer and use it in GitHub Desktop.
Save rowantran/329000023ee4a64f908fb71fc044585f to your computer and use it in GitHub Desktop.
Setting up XP-Pen tablet on Linux using new kernel drivers

Short guide detailing how to use the new drivers included in kernel (since 5.1) for an XP-Pen tablet.

As of 5.1, this method should work for at least the XP-Pen G540 and G640 (I am using a G540 but commands given should be identical across either tablet.)

Running xinput list should yield something similar to this:

$ xinput list
⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ Hoksi Technology DURGOD Taurus K320 Aurora Consumer Control       id=10   [slave  pointer  (2)]
⎜   ↳ Hoksi Technology DURGOD Taurus K320 Aurora Mouse  id=12   [slave  pointer  (2)]
⎜   ↳ UGTABLET TABLET G3 5x4 Mouse              id=13   [slave  pointer  (2)]
⎜   ↳ UGTABLET TABLET G3 5x4 Mouse              id=14   [slave  pointer  (2)]
⎜   ↳ Razer Razer DeathAdder Chroma             id=16   [slave  pointer  (2)]
⎜   ↳ Razer Razer DeathAdder Chroma Consumer Control    id=17   [slave  pointer  (2)]
⎜   ↳ UGTABLET TABLET G3 5x4 Pen Pen (0)        id=25   [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
(continues ...)

Look under the "Virtual core pointer" section and take note of the name of the device ending in "Pen" -- in this case that would be "UGTABLET TABLET G3 5x4 Pen Pen (0)" so that you can use it in the next command.

Running xinput list-props "[INSERT NAME OF DEVICE]" should give a short list of properties, something like this:

$ xinput list-props "UGTABLET TABLET G3 5x4 Pen Pen (0)"
Device 'UGTABLET TABLET G3 5x4 Pen Pen (0)':
        Device Enabled (155):   1
        Coordinate Transformation Matrix (157): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
        Device Node (277):      "/dev/input/event17"
        Device Product ID (278):        10429, 117
        libinput Tablet Tool Pressurecurve (509):       0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 1.000000, 1.000000, 1.000000

The "Coordinate Transformation Matrix" property takes the form of a b c d e f g h i, representing a 3x3 matrix applied to the input from the tablet. If you use full area, the default matrix of 1 0 0 0 1 0 0 0 1 will map the entire tablet area to the screen.

If you use a portion of the tablet, you will have to do a bit of simple math to calculate some values.

For examples, I will pretend that I am using a 3x1.69 area on a 5x4 tablet.

First, we will calculate the values that represent the area size.

Calculate the value a by dividing total width / width of your area. For example, 5 / 3 = 1.667.

Next, calculate the value e by dividing total height / height of you area. For example, 4 / 1.69 = 2.367.

Now we will calculate the values representing offset.

For horizontal offset, if you want the area to be aligned against the left edge of the tablet, the value of c is 0. If you want it to be aligned against the right edge of the tablet, the value of c equals 1 - a. This should be a negative number in all cases.

For vertical offset, if you want the area to be aligned against the top edge of the tablet, the value of f is 0. If you want it to be aligned against the bottom edge of the tablet, the value of f equals 1 - e. This should also be a negative number.

We should now have the values a, c, e, and f. Take those values and run the following command:

$ xinput set-prop "[INSERT NAME OF DEVICE]" "Coordinate Transformation Matrix" a 0 c 0 e f 0 0 1

Replace a, c, e, and f with the values calculated above. Your tablet should now use your desired area.

@rajhlinux
Copy link

I get the following:

Here is what xinput list shows:

⎡ Virtual core pointer                          id=2    [master pointer  (3)]

⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]

⎜   ↳ System mouse                              id=6    [slave  pointer  (2)]

⎜   ↳ Logitech Gaming Mouse G502                id=12   [slave  pointer  (2)]

⎜   ↳ UGTABLET 6 inch PenTablet                 id=13   [slave  pointer  (2)]

⎜   ↳ UGTABLET 6 inch PenTablet                 id=14   [slave  pointer  (2)]

⎜   ↳ BY Tech Usb Gaming Keyboard               id=15   [slave  pointer  (2)]

⎣ Virtual core keyboard                         id=3    [master keyboard (2)]

    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]

    ↳ System keyboard multiplexer               id=7    [slave  keyboard (3)]

    ↳ Power Button                              id=8    [slave  keyboard (3)]

    ↳ AT keyboard                               id=9    [slave  keyboard (3)]

    ↳ Logitech Gaming Mouse G502                id=10   [slave  keyboard (3)]

    ↳ BY Tech Usb Gaming Keyboard               id=11   [slave  keyboard (3)]

I do not get the "Pen Pen" list.

Thanks.

@rowantran
Copy link
Author

rowantran commented Jan 6, 2023

@rajhlinux I've been using OpenTabletDriver so I haven't used the kernel drivers in a while. But the name is probably just different due to different configuration, or some driver changes since the original post. I'm guessing one of the two "PenTablet" devices has the Coordinate Transformation Matrix property -- what do you get when you run xinput list-props [13/14]?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment