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

MacOS: Raw mouse motion and cursor grab #404

Merged
merged 2 commits into from
Aug 8, 2023

Conversation

Deseteral
Copy link
Contributor

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 and CGWarpMouseCursorPosition to move it inside window frame (more on this later). When the cursor is grabbed and mouseMoved is emitted we're calling raw_mouse_motion with deltaX and deltaY 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 the set_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:

NOTE that this code doesn't warp the mouse cursor to the window center as everybody else does it. This lead to a spike in the second mouse-moved event after the warp happened. The mouse centering doesn't seem to be required (mouse-moved events are reported correctly even when the cursor is at an edge of the screen).

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.

@not-fl3
Copy link
Owner

not-fl3 commented Aug 8, 2023

Thanks, great PR!

Let me know what you want to do about it - we can leave it as it is, or I will remove moving the cursor.

The behaviour you described sounds very reasonable to me, but to be honest, I do not have an opinion here.

@not-fl3 not-fl3 merged commit 63a0837 into not-fl3:master Aug 8, 2023
10 checks passed
@Deseteral
Copy link
Contributor Author

Thank you for that incredibly fast review 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants