love icon indicating copy to clipboard operation
love copied to clipboard

Multi-touch support for trackpads and touch displays

Open vaner-org opened this issue 4 years ago • 10 comments

Allowing the trackpad under macOS to trigger pre-exisiting love.touch functionality through SDL's native SDL_TouchFingerEvent (which already supports it) would make testing mobile applications on desktop a breeze, and allow gestures for interface navigation (which would be a godsend).

vaner-org avatar Oct 04 '20 20:10 vaner-org

Trackpads don't behave like touch screens at all, because there's no correlation between where the user presses the trackpad and a location on the screen.

I added this functionality to SDL relatively recently to account for that difference https://hg.libsdl.org/SDL/rev/eb60e952b13f - I wouldn't feel good about exposing trackpad touches in love without making sure the API made that touch type distinction very clear, so people don't write code that will break when a trackpad is used (especially since end users actually use their trackpad to move the mouse cursor).

slime73 avatar Oct 04 '20 20:10 slime73

I described the problem a bit more here https://bugzilla.libsdl.org/show_bug.cgi?id=3542#c1 (although I wrote that before the above APIs were added to SDL).

slime73 avatar Oct 04 '20 20:10 slime73

Thank you for the detailed explanation, I understand what you mean.

Trackpads don't behave like touch screens at all, because there's no correlation between where the user presses the trackpad and a location on the screen.

My hypothetical case of testing mobile apps in Love doesn't make a whole lot of sense, I realise now. Still, I think this is worth including just for the sake of location-agnostic gestures like pinch to zoom or drawing with multi touch. I personally know of a lot of people (myself included) whose programs could benefit from this weird hybrid place the trackpad sits in. Maybe only allowing ignoring the mouse data in favour of trackpad when the mouse has been captured and hidden by the window? Like how Preview accepts signatures.

Screenshot 2020-10-05 at 02 38 02

And in the other case keeping the two separate, that is, if the trackpad has multiple fingers on it, it no longer sending any love.mouse signals, only multitouch info, which can be manually sifted by the coder (I think this happens automatically at OS level though.)

I added this functionality to SDL relatively recently to account for that difference https://hg.libsdl.org/SDL/rev/eb60e952b13f - I wouldn't feel good about exposing trackpad touches in love without making sure the API made that touch type distinction very clear, so people don't write code that will break when a trackpad is used (especially since end users actually use their trackpad to move the mouse cursor).

Is API naming the biggest hurdle here? I'm guessing a love.trackpad class might be too much fragmentation for your liking, which I understand. If so, I would be glad to draft documentation that could fit it into love.touch or love.mouse.

vaner-org avatar Oct 04 '20 21:10 vaner-org

For the sake of cross-platform feature compatibility, how would this work on windows and linux?

zorggn avatar Oct 05 '20 05:10 zorggn

For the sake of cross-platform feature compatibility, how would this work on windows and linux?

I was unable to find documentation for a multitouch API in either for trackpads but... found someone talking about it here, about SDL_MultiGestureEvent.

Looks to me that Mac has trackpads triggering MultiGestureEvent natively, while Windows and Linux have touch panels doing the same. So it would benefit all three platforms. :)

vaner-org avatar Oct 05 '20 08:10 vaner-org

@slime73 Is the Touch FFI from love-snippets still expected to be functional? I can't get it to work with 11.3. Otherwise, would it be non-trivial to get it running with the new SDL functionality you added?

vaner-org avatar May 23 '21 20:05 vaner-org

I have the Touch FFI and therefore trackpad multitouch working when I build love2d with SDL_SetHint(SDL_HINT_MOUSE_TOUCH_EVENTS, "1") added to the int main() in love.cpp.

vaner-org avatar Oct 20 '22 02:10 vaner-org

AFAIK there's no equivalent API in Windows and Linux for this one, so having it working in all platforms that LOVE supports would be next to impossible.

Multitouch on touch displays has been supported since 0.10.0. However multitouch (and absolute coordinate) for trackpads are another story.

MikuAuahDark avatar Dec 06 '22 04:12 MikuAuahDark

But surely there isn't a downside to having the SDL hint enabled by default, since it needs FFI to be usable anyway?

vaner-org avatar Jan 17 '23 01:01 vaner-org

Not sure but after checking it, SDL_HINT_MOUSE_TOUCH_EVENTS is responsible whetever LOVE will also fire mousepressed/moved/released when the input comes from touchscreen and this is enabled by default.

MikuAuahDark avatar Jan 17 '23 02:01 MikuAuahDark