get tablet stylus pressure

Any useful information coming out of SDL_TouchFingerEvent::pressure for your hardware?

1 Like

Hi, yes I tried SDL_TouchFingerEvent::pressure
but it always return 1.

EDIT: in fact my touchscreen returns 1, but my wacom tablet only emit mouse events, no touch, and asking for SDL_TouchFingerEvent::pressure on the mouse event returns a bogus number.

many thanks for the info. I will have a look at EasyTab, but a cross-platform solution would be great (at least on Mac OS)

EasyTab requires the X11 window and display as parameters. How can I get these from the already open SDL window?

You may be interested in this pull request and the related issues:

1 Like

Hello-- any feedback on whether the #5481 API meets your needs would be really valuable. A quick summary below:

  • New pen motion and button events (NB: no hotplugging event, since I’m not sure if there is demand for it)
  • List of pen axes
  • New API functions for querying pens are right below that (discourse won’t let me add more links…)
  • For backend/driver writers: src/events/SDL_pen_c.h is what you want, but test/testautomation_pen.c (especially pen_initAndInfo, pen_buttonReporting, and pen_hotplugging) give examples for reporitng new pens, reporting button events, and handling hot-plugging, respectively.

(These URLs point to older versions than what is in the PR, but IIRC there have been no changes to the API since then.)

If you have suggestions for changes, please feel free to add them to the PR discussion!

I’m not planning to add OS X or Win32 support myself (haven’t even been able to find the OS X APIs, even) but would be happy to help if someone else wants to do so.

I have tested your test program testpen with the Wacom cintiq and it works great! So cool.

Since you asked, what would be great for me is to have a precise time stamp of when the event was emitted. Since you’re into X11, maybe that’s not too difficult. See [Patch] Event timestamp propagation for x11 - #2 by Sanette

On the other hand, the testpen program does not work with my cheap Huion: I don’t see the pointer in the window.
(stylus pressure is detected in Xournalpp, for instance).

Thank you very much! This is very valuable.

First, about timestamps: while I am all for more precise timestamps, this is an orthogonal problem and I don’t think I can make a good point for including such changes in the current patch (moreover, I am not 100% sure what the “right” solution would be). (One backward-compatible solution might be to have an alternative poll function that returns a microsecond-resolution timestamp along with a “normal” event.)

Second, about the Huion tablet: Xournalpp uses the GTK tablet facilities, which I have largely tried to emulate, so hopefully this won’t be too hard to fix (fingers crossed…). Could you do the following, please:

  • In testpen, move the Huion pen close to the upper left corner (doesn’t need to be terribly close) and press a key on your keyboard. This should dump information on all current pens that will help me understand better what is going on.
  • Please also send the output of xinput. As you probably know, xinput will list all attached input devices.
  • Let’s say that the xinput ID of your Huion pen is ${ID}. Then please also send me the output of xinput list ${ID} --long
  • …as well as the output of xinput list-props ${ID}

Thank you again!

in fact, as soon as I move the Huion stylus within the window region, the program seems to freeze. Cannot get anything from pressing any key. But it’s quite unstable. Sometimes it crashes with “core dumped”. Once I was able to get this message at startup, but only once:

$ ./testpen 
INFO: Found 1 pens
INFO: Pen 18: [6d006c25000000000000000000000000] attached=1, ? buttons [cap= 00014000:00004000 =status] 'HUION Huion Tablet Pen Pen (0)'
INFO:    pos=(0.00, 0.00)
INFO:    axis 0:  0.000
INFO:    axis 1:  unsupported (0.000)
INFO:    axis 2:  unsupported (0.000)
INFO:    axis 3:  unsupported (0.000)
INFO:    axis 4:  unsupported (0.000)
INFO:    axis 5:  unsupported (0.000)

Checking with my system monitor, as soon as the stylus enters the window, there is a huge memory leak (about 12Gb in a few seconds!), and CPU usage is at 100%

$ xinput
⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ ELAN Touchscreen                          id=10   [slave  pointer  (2)]
⎜   ↳ DLL0704:01 06CB:76AE Mouse                id=12   [slave  pointer  (2)]
⎜   ↳ DLL0704:01 06CB:76AE Touchpad             id=13   [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Power Button                              id=8    [slave  keyboard (3)]
    ↳ Sleep Button                              id=9    [slave  keyboard (3)]
    ↳ Integrated_Webcam_HD: Integrate           id=11   [slave  keyboard (3)]
    ↳ Intel HID events                          id=14   [slave  keyboard (3)]
    ↳ Dell WMI hotkeys                          id=15   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=16   [slave  keyboard (3)]
    ↳ HUION Huion Tablet Pen                    id=17   [slave  keyboard (3)]
 
$ xinput list 17 --long
HUION Huion Tablet Pen                          id=17   [slave  keyboard (3)]
        Reporting 0 classes:

xinput list-props

$  xinput list-props 17
Device 'HUION Huion Tablet Pen':
        Device Enabled (186):   1
        Coordinate Transformation Matrix (188): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
        libinput Calibration Matrix (326):      1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
        libinput Calibration Matrix Default (327):      1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
        libinput Send Events Modes Available (309):     1, 0
        libinput Send Events Mode Enabled (310):        0, 0
        libinput Send Events Mode Enabled Default (311):        0, 0
        Device Node (312):      "/dev/input/event8"
        Device Product ID (313):        9580, 109

Thank you again! The output from testpen looks sane to me (i.e., they unfortunately don’t help :wink:

The xinput outputs are a bit mysterious in that this device doesn’t meet the criteria for being recognised as a pen (moreover, the device ID 18 that testpen reported is different from the device ID 17 that you investigated, though that might be for other reasons).

Could you try to see if you get different values if you hold the pen close to the tablet (or even touch it) while you run these xinput queries, please?

I’ve been able to reproduce a crash with testpen trying to draw unreasonably large lines due to impossible tilt angles being reported… for pens that don’t report tilt support. I have pushed a patch for that now.

Does that fix the Huion issue?

I would still be very interested in hearing whether there is more information reported by xinput list-props and xinput list --long when the pen is close to the screen (my Wacom pens don’t report everything unless they are close to the surface either), since it is possible that the pen’s features aren’t all getting detected yet.

this is just because I had unplugged/plugged again the device

EDIT: no, sorry, my bad. 17 was the device reported as a keyboard, not as a pointer! Indeed I should haved used 18:

$ xinput list 18 --long
HUION Huion Tablet Pen Pen (0)                  id=18   [slave  pointer  (2)]
        Reporting 4 classes:
                Class originated from: 18. Type: XIButtonClass
                Buttons supported: 7
                Button labels: None None None None None None None
                Button state:
                Class originated from: 18. Type: XIValuatorClass
                Detail for Valuator 0:
                  Label: Abs X
                  Range: 0.000000 - 16777215.000000
                  Resolution: 0 units/m
                  Mode: absolute
                  Current value: 5116538.680947
                Class originated from: 18. Type: XIValuatorClass
                Detail for Valuator 1:
                  Label: Abs Y
                  Range: 0.000000 - 16777215.000000
                  Resolution: 0 units/m
                  Mode: absolute
                  Current value: 15399529.246693
                Class originated from: 18. Type: XIValuatorClass
                Detail for Valuator 2:
                  Label: Abs Pressure
                  Range: 0.000000 - 2047.000000
                  Resolution: 0 units/m
                  Mode: absolute
                  Current value: 0.000000

this is getting better! Now I can get some info by pressing a key:

INFO: Found 1 pens
INFO: Pen 18: [6d006c25000000000000000000000000] attached=1, ? buttons [cap= 00014000:00004000 =status] 'HUION Huion Tablet Pen Pen (0)'
INFO:    pos=(203.87, 171.35)
INFO:    axis 0:  0.000
INFO:    axis 1:  unsupported (0.000)
INFO:    axis 2:  unsupported (0.000)
INFO:    axis 3:  unsupported (0.000)
INFO:    axis 4:  unsupported (0.000)
INFO:    axis 5:  unsupported (0.000)
$ xinput list-props 18
Device 'HUION Huion Tablet Pen Pen (0)':
        Device Enabled (186):   1
        Coordinate Transformation Matrix (188): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
        libinput Send Events Modes Available (309):     1, 0
        libinput Send Events Mode Enabled (310):        0, 0
        libinput Send Events Mode Enabled Default (311):        0, 0
        Device Node (312):      "/dev/input/event21"
        Device Product ID (313):        9580, 109
        libinput Tablet Tool Pressurecurve (668):       0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 1.000000, 1.000000, 1.000000

Great, thank you! This looks all sane to me now. According to this, the X11 driver only offers pressure information, but not tilt-- does that match what you’re getting on Gnome?

peninfo doesn’t do much if there is no tilt available, so I’ll add something to visualise pressure for the case that reported tilt is close to zero.

I’ve pushed a change that should make it possible for you to see the pressure information. Does the Huion tablet work as intended now?

yes perfect. (Indeed the X11 driver cannot get the tilt for the Huion tablet, unfortunately)

I’ve just modified the sourcecode in a local build for iOS to report pen pressure , as follows:

SDL/Library Source/video/uikit/SDL_uikitview.m
in
-(void)touchesBegin(NSSet*) touches withEvent:(UIEvent*) event
{
        for (UITouch *touch in touches) {
        BOOL handled = NO;
        
        if (touch.type == UITouchTypePencil){
            g_pen_pressure = touch.type;
        }
        ....
}

float g_pen_pressure;
float SDL_GetPenPressure(){return g_pen_pressure;}

I might have some details to iron out , e.g. how it interacts with the other touch types.
seems like keeping a forked version of SDL2 I can get the support i’m after but I find it a bit daunting to go through the whole PR process and test it for all the platforms. but i’ll definitely share code if I get this working for anything else.

keeping a fork just for this seems easier than ditching SDL2 generally, I’ve enjoyed how well this works across so many platforms.