-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
I have observed on both macOS and Windows that when multiple fingers are touched down and raised it is possible for the app to receive either one or multiple SDL_EVENT_FINGER_{DOWN,UP} events. For SDL_EVENT_FINGER_DOWN
this is not a problem as SDL_GetTouchFingers
called on the last event gives the total number of fingers down.
Handling this dichotomy for SDL_EVENT_FINGER_UP
is impossible. On the first event received, regardless if it will be the only one or is the first of several, SDL_GetTouchFingers
reports the total number of fingers that were down before the event and the returned SDL_TouchFingers
list includes all the fingers. Therefore it is impossible to know how many fingers may still be down. The SDL_TouchFingers
returned in the list do not provide any help. I thought maybe pressure
might be zero for the up fingers but all pressures are 1. It is possible that the fingerID
in the SDL_EVENT_FINGER_UP
may be the finger that was raised - there is no documentation to that effect - but that is helpful only if just 1 finger was raised.
If you are only interested in the number of fingers then you can fudge it by recording the number in SDL_EVENT_FINGER_DOWN
handling then decrementing that number on each SDL_EVENT_FINGER_UP
by the number of fingers reported by SDL_GetTouchFingers
clamping it to a minimum of 0.
But if, as part of gesture processing such as in SDL_gesture.h, you want to calculate the centroid of the remaining down fingers, there is no way to do that reliably especially if you are using more than 2 fingers in your gestures.
On macOS you can reproduce a single SDL_EVENT_FINGER_UP
by pressing 2 fingers on the trackpad to emulate a right mouse button. On release, regardless of any delay between raising the fingers, a single event will be received when the press is released. You can reproduce multiple events by touching the trackpad with 2 fingers, then raising one followed by the other.
The list returned by SDL_GetTouchFingers
should be either the fingers remaining down or the fingers that have been raised. The former contradicts with the semantic of "finger up" but is probably more useful than the latter which will require keeping the list of fingers between events and removing from it the fingers that have been raised.
This is with SDL3 but the symptoms which I tracked to this problem were present with SDL2 as well.