Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Add conf.lua option to enable touchpad touch events on macOS #2093

Open
turbo opened this issue Aug 16, 2024 · 2 comments
Open

[Request] Add conf.lua option to enable touchpad touch events on macOS #2093

turbo opened this issue Aug 16, 2024 · 2 comments
Labels
feature New feature or request
Milestone

Comments

@turbo
Copy link

turbo commented Aug 16, 2024

On Apple computers with Magic Trackpads (MacBooks, and the standalone Magic Trackpad product), the surface is actually a multi-touch pad. This is important for implementations of e.g. natural scrolling, which depends on access to touch events themselves. E.g. on any scrollable surface on macOS, you can initiate a scroll with inertia, lift off your fingers, and then stop it dead by simply touching again (just an example, there are a lot more gestures). I'd like to make use of some of the gestures in Love, but currently MTs don't register touch events - as far as I can tell, please correct me if I'm wrong!

SDL2 has solved this problem a while ago with this hint: https://github.com/love2d/love-apple-dependencies/blob/b3397c1464537d7ad418a1d60ffced71fc919cd4/macOS/Frameworks/SDL2.framework/Versions/A/Headers/SDL_hints.h#L2442-L2461

I'd like to propose adding a config option that allows settings this hint from a game's config.lua. SDL has indicated the same hint will apply to future touchpad support beyond macOS, but it is specific to Cocoa right now.

I tried to add this to the latest Love source, but I'm not sure where the right place is. The hint docs indicate it should be called before video init, so I added it to Window.cpp before the init call, but it didn't do anything. To test, I used the default touch example from the Wiki:

// in the Window constructor, before SDL_InitSubSystem

#ifdef LOVE_MACOS
 /**
  * The variable can be set to the following values:
  *
  * - "0": Trackpad will send mouse events. (default)
  * - "1": Trackpad will send touch events.
  *
  * This hint should be set before SDL is initialized.
  */
 SDL_SetHint(SDL_HINT_TRACKPAD_IS_TOUCH_ONLY, "1");
#endif
@turbo
Copy link
Author

turbo commented Aug 16, 2024

Hm, looking a bit more into the SDL source, I'm not sure if this is fully implemented after all. But that's a judgement beyond my understanding of SDL internals.

@turbo
Copy link
Author

turbo commented Aug 18, 2024

I gave up on my SDL investigation. For anyone stumbling upon this, I solved this for me by compiling this code which talks directly to MultitouchSupport (a system Framework) to a C library and then using it from Lua. This doesn't just give the position of touches, but also the velocity and even the rotation (which is very accurate!) for each finger.

@turbo turbo changed the title [Request] Add conf.lua option to respect SDL_HINT_TRACKPAD_IS_TOUCH_ONLY on macOS [Request] Add conf.lua option to enable touchpad touch events on macOS Aug 18, 2024
@slime73 slime73 added the feature New feature or request label Aug 27, 2024
@slime73 slime73 added this to the 12.0 milestone Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants