MacOS: Raw mouse motion and cursor grab #404
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When not-fl3/macroquad#181 added support for raw mouse motion events in macroquad it didn't work on MacOS because of missing
set_cursor_grab
implementation for that plaform. This PR adds support for missing MacOS features.My work is based on current implementation of mouse locking in sokol_app.
It uses
CGAssociateMouseAndMouseCursorPosition
to lock the cursor andCGWarpMouseCursorPosition
to move it inside window frame (more on this later). When the cursor is grabbed andmouseMoved
is emitted we're callingraw_mouse_motion
withdeltaX
anddeltaY
values.One notable difference from sokol is that in my implementation when user calls
set_cursor_grab(true)
I'm moving the cursor inside window frame. Without this when the cursor is outside window frame when theset_cursor_grab
is called, a mouse click will unfocus the window.Moving the cursor inside window frame is what sokol_app used to do, but it does not anymore, which is explained in their code:
This is what that spike looks like in macroquad (using miniquad from this branch):
macroquad_mouse_twitch_e.mov
In my opinion we should follow what sokol does. Most games are probably fullscreen anyway and when they're not - users will click on the window to focus. On the other hand this is still going to be a problem when users alt-tab to the window.
Let me know what you want to do about it - we can leave it as it is, or I will remove moving the cursor.
I've tested this change with all miniquad examples, and most importantly with macroquads
first_person
example (as seen on video below).macroquad_example_e.mp4
If there is something specific you would like me to test - let me know.