libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
10k stars 1.85k forks source link

MacOS raw mouse input #10146

Open expikr opened 4 months ago

expikr commented 4 months ago

I’m completely unfamiliar with MacOS and SDL’s support goals for it, but more recent versions of MacOS has GCMouseInput that provides raw deltas instead of accelerated motion. Does SDL use this? From what I could see it still handles regular cocoa events, no?

I think by default MacOS should use the GCMouseInput API, and only handle accelerated delta if SDL_MOUSE_RELATIVE_SYSTEM_SCALE is enabled.

And tangentially MacOS implementations should also be aware of the SDL_MOUSE_RELATIVE_MODE_CENTER hint.

slouken commented 4 months ago

Yes, this all makes sense. CGMouse has been hooked up for iOS and could be hooked up similarly for macOS. It probably needs refactoring and support for the hints as you mentioned.

dsvensson commented 3 months ago

This would be very valuable for all FPS type games that currently have to resort to nasty hacks like discussed in this thread,

https://discourse.libsdl.org/t/osx-raw-input-still-gives-acceleration-proposed-solution/20359

Would be nice if this was backported to SDL 2.x as well given how wide spread the use of SDL2, rather than the current assigned target of 3.2.0.

icculus commented 3 months ago

This has been asked for since #67, believe it or not. :)

dsvensson commented 3 months ago

Question is what it takes to make it work when sandboxed. Trying to make it work with ezQuake atm. Works great without sandboxing, but with sandboxing I wonder if it somehow blocks communication with gamecontrollerd or something.

icculus commented 3 months ago

I think CGMouseInput works in the sandbox; the ancient solution was trying to read from HID devices directly, which is a giant no-no for security.

dsvensson commented 3 months ago

Yes, it's supposed to be the golden way forward. I'm building with a cmake generated Xcode project so I must be missing something. Whatever it is, the solution will be valuable for this issue as well, as others will try to sandbox the future SDL implementation. A simple Xcode generated project in Swift that implements a simple handler gets the events when sandboxed so it should work.