DIGImend / digimend-kernel-drivers

DIGImend graphics tablet drivers for the Linux kernel
GNU General Public License v2.0
1.17k stars 173 forks source link

Huion 420 reports BTN_STYLUS2 events instead of BTN_TOOL_RUBBER on tip down #416

Open Xyene opened 4 years ago

Xyene commented 4 years ago

Hi,

I'm running the drivers in kernel 5.4.0 with a Huion 420 tablet whose pen has two buttons, one of which is a mode switch to eraser on tip down. However, it seems this device (and possibly also the H420, which AFAIK is the same pad but with 3 buttons on it?) has buggy firmware: it performs the virtual proximity out / in switch to eraser mode, but then sends BTN_STYLUS2 events instead of BTN_TOOL_RUBBER.

Here is a thread from libinput describing this which has a bit more background and event traces. The relevant bits are on button press while tip is down:

  - evdev:
    - [  1, 924005,   4,   4,      30] # EV_MSC / MSC_SCAN                 30 (obfuscated)
    - [  1, 924005,   1, 330,       0] # EV_KEY / BTN_TOUCH                 0
    - [  1, 924005,   3,  24,       0] # EV_ABS / ABS_PRESSURE              0 (-2047)
    - [  1, 924005,   0,   0,       0] # ------------ SYN_REPORT (0) ---------- +56ms
  - evdev:
    - [  1, 932004,   4,   4,      30] # EV_MSC / MSC_SCAN                 30 (obfuscated)
    - [  1, 932004,   1, 330,       1] # EV_KEY / BTN_TOUCH                 1
    - [  1, 932004,   4,   4,      30] # EV_MSC / MSC_SCAN                 30 (obfuscated)
    - [  1, 932004,   1, 332,       1] # EV_KEY / BTN_STYLUS2               1
    - [  1, 932004,   3,  24,     647] # EV_ABS / ABS_PRESSURE            647 (+647)
    - [  1, 932004,   0,   0,       0] # ------------ SYN_REPORT (0) ---------- +8ms

which I think look fine except for BTN_STYLUS2 instead of BTN_TOOL_RUBBER.

I'm happy to provide any other info that might be useful here.

spbnick commented 4 years ago

@Xyene, I assume that switching to eraser tool is how the windows drivers treat the top pen button of your tablet.

All tablet drivers I wrote, always report it as BTN_STYLUS2, which is translated to the right mouse button by userspace drivers, because that's how most tablets intend it to be used.

If you want it to switch the tool, there's a number of ways that could be accomplished, but a quick fix might be to try to remap it to a shortcut which switches to that tool in your drawing program. That could be done with xsetwacom.

Otherwise this needs work in either the kernel or the userspace drivers.

Xyene commented 4 years ago

Thanks for the quick reply! I'm afraid I was not very clear about what's going on, especially with regards to orientation... so here's an annotated Huion 420 pen :slightly_smiling_face:

image

When the pen is in proximity, but not touching the pad, pressing B reports BTN_STYLUS2, and pressing A reports BTN_STYLUS (I'm assuming B is what you mean by "top pen button"?). When the pen is touching the pad, pressing B again reports BTN_STYLUS2. I think this is still fine.

The problem is when pressing A while the pen is touching the pad. What happens is:

This sounds a lot like the behavior of the Surface 3 pens, except the transition is reported as BTN_STYLUS2 instead of BTN_TOOL_RUBBER.

Assuming a mapping of BTN_STYLUS2 → eraser, and BTN_STYLUS → something else, this ends up making using button A for anything very finicky: if you try to stop erasing while the pen is down, you can either:

It's actually a bit worse than that in practice, since I think there's also some pressure requirement (roughly > 0.2, it seems) before the tablet switches sending BTN_STYLUS2 instead of BTN_STYLUS... so you can be in contact with the tablet surface and using BTN_STYLUS's tool, but if you apply just a bit too much (> 0.2) pressure, it switches to BTN_STYLUS2 and you start erasing instead.