macos: Integrate GCMouse for raw mouse input#14741
macos: Integrate GCMouse for raw mouse input#14741ej-sanmartin wants to merge 1 commit intolibsdl-org:mainfrom
Conversation
|
@ej-sanmartin, this has conflicts, can you squash your PR into a single commit and resolve the conflict? Thanks! |
Fix duplicate button/scroll events when GCMouse active Fix duplicate events and add thread-safe atomic for GCMouse Fix GCMouse relative mode sync when connected after mode enabled Respect SDL_HINT_MOUSE_RELATIVE_SYSTEM_SCALE in GCMouse handler Fix variable shadowing in GCMouse motion handler
0a9baf3 to
ad7c693
Compare
|
Done! |
|
I've been struggling to access SDL mouse or keyboard events in my Godot plugin. This patch finally allowed mouse events to flow. Thanks a lot! |
|
I was about to implement mechanics that use both mice, but then I found that I can't click and drag with both mice at the same time. I used a minimal Xcode app to test this PR and I find that Note: in my tests I am wrapping the main window pointer with Tested using 1 MacBook trackpad and 1 bluetooth mouse. while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_EVENT_MOUSE_BUTTON_DOWN:
SDL_Log("SDL_EVENT_MOUSE_BUTTON_DOWN %d", event.button.which);
break;
case SDL_EVENT_MOUSE_BUTTON_UP:
SDL_Log("SDL_EVENT_MOUSE_BUTTON_UP %d", event.button.which);
break;
case SDL_EVENT_MOUSE_ADDED:
SDL_Log("SDL_EVENT_MOUSE_ADDED %d", event.mdevice.which);
break;
}
}I'm also confused why it sees 3 mice including |
Happy New Years btw 🎆🍾
Description
macOS 11.0+ now use GCMouse while remaining backwards compatabile with
NSEventbased mouse handling in older versions of Mac. This gives us raw mouse input data instead of the acceleration-based data fromNSEvent.Existing Issue(s)
Closes #10146
Tested
Built SDL3 locally, on macOS
12.6.7, usingtest/testrelativewith some added tempSDL_LOG. Apologies but I don't have a Mac device I can locally test the fallback originalNSEventimplementation on macOS 11 or older.I tested in both my branch and main branch with these similar movements: slow horizontal swipe, then fast horizontal swipe left and right.
These logs are long, but they print out rows formatted roughly
<Apple Input Handler Framework>: <deltaX>, <deltaY>.tldr is that it shows
GCMousehas raw deltaXs that increase linearly based on speed, andNSEventoutput raw deltaXs that are multiplied by acceleration.FYI
GCMouselogged more events likely due to less OS-level event coalescing and our high-priority dispatch queue, though the primary benefit is raw (unaccelerated) deltas rather than guaranteed higher frequency.GCMouselogs:NSEventlogs:Last Note
Didn't implement
SDL_MOUSE_RELATIVE_MODE_CENTERsupport in this PR since GCMouse delivers raw deltas directly from the mouse hardware, so cursor confinement location doesn't affect the input values and from what I understand the hint only matters for fallback scenarios where SDL uses cursor position to calculate movement. Lmk if i'm wrong and this can always be implemented in a future PR.