Skip to content

fork Multi touch support

Oznogon edited this page Jun 15, 2026 · 1 revision

SDL_TouchFingerEvent (SDL_FINGER*)

On SDL_FINGERDOWN, SDL_FINGERMOTION, and SDL_FINGERUP, SDL emits an event.tfinger that reports each touch with a unique, incremental fingerId, coordinates, and positional movement deltas since the last event.

Capturing the events

SP already passes event.tfinger, including fingerId, to EE through the render chain, but EE doesn't do anything with fingerId.

dX and dY can be very sensitive depending on the touchscreen. Distances and angles between them probably need a configurable deadzone similar to a joystick.

vs. SDL_MULTIGESTURE

TouchFingerEvents don't provide deltas for angles or distances between SDL_Fingers, only distance deltas for each independent finger, nor does it provide centroids. We'd have to calculate what we need from FINGER* events each tick, including the number of active fingers. Since SDL is already calculating and emitting these in SDL_MULTIGESTURE events regardless of whether we use them, these calculations are also redundant.

With SDL_FINGER*, fingerId increments with every touch without a reset when no touch events are active, so we'd have to either collect the fingerIds into a set on FINGERDOWN and erase them on FINGERUP, or use SDL_GetNumTouchFingers() but lose the association of those events with their position deltas necessary to track things like pinch-to-zoom.

This would also all be redundant with what SDL is already doing in SDL_MULTIGESTURE, which already associates multiple concurrent fingers into a single event.

Because SDL_FINGER* are already handled, the only new code would be on the EE side and could be tailored to different uses, such as two-finger panning on the GM Screen. However, it's unclear which of these uses would be unique to what SDL_MULTIGESTURE already provides.

Trackpad gestures

Not by default. Trackpad events might be reported as touch events, but trackpad drivers or the OS typically intercept multiple-finger events, and the only multifinger trackpad support in SDL is through SDL_MULTIGESTURE exclusive to macOS.

SDL_MULTIGESTURE

SDL2 emits SDL_MULTIGESTURE events when it can recognize both a touch device, multiple active touch points ("fingers"), and movement in those touch points. These events report the number of fingers on the surface, and the relative deltas in their distance and angles (theta) between multigesture events.

This allows for rudimentary gesture support, particularly pinch in/spread out, swipe, and rotational gestures. SDL2 includes a test implementation in its tree, at test/testgesture.c.

While different in implementation, at least for pinch-to-zoom the implementation can probably mirror EE/SP's handling of mousewheel events.

Capturing the events

SDL_MULTIGESTURE provides numFingers, dDist (distance delta), dTheta (angle delta in rads), and the gesture's centerpoint coordinates as x y. They lack a windowID field and must get it via SDL_GetWindowID() like mousewheel events do.

dDist and dTheta can be very sensitive depending on the touchscreen and probably need a configurable deadzone similar to a joystick.

vs. FINGERDOWN/UP and FINGERMOTION

SDL2 continues tracking FINGERDOWN, FINGERUP, and FINGERMOTION events while a MULTIGESTURE is being employed. EE also uses these events for other purposes, and for pinch-to-zoom gestures that likely will conflict on screens like Relay that also uses FINGERDOWN and MOTION to pan.

Either EE (per screen) or SP (at engine?) will likely need to implement a 10-20 frame or 0.2-0.3 second cooldown to avoid collisions between events.

vs. DOLLARGESTURE

SDL_DOLLARGESTURE (templated and recordable single-stroke gestures) is unrelated but might be useful later.

Trackpad gestures

Not by default. Setting SDL_HINT_TRACKPAD_IS_TOUCH_ONLY=1 would allow only macOS trackpads to serve as equivalent touch devices, and doing so would probably be disruptive to other interactions (particularly scrollwheel) that depend on mouse-like devices acting like mice.

SDL3

As of October 2025, SDL3 supports OS-level gesture pinch events as SDL_Pinch. If SP and EE are ever ported to SDL3, these simpler events can replace this implementation.

Clone this wiki locally