11diff --git a/Sources/SwiftSDL3/src/video/cocoa/SDL_cocoawindow.m b/Sources/SwiftSDL3/src/video/cocoa/SDL_cocoawindow.m
2- index 3425737..df6c350 100644
2+ index 3425737..eb0a807 100644
33--- a/Sources/SwiftSDL3/src/video/cocoa/SDL_cocoawindow.m
44+++ b/Sources/SwiftSDL3/src/video/cocoa/SDL_cocoawindow.m
5- @@ -1703,12 +1703,65 @@ - (BOOL)processHitTest:(NSEvent *)theEvent
5+ @@ -1703,12 +1703,68 @@ - (BOOL)processHitTest:(NSEvent *)theEvent
66 return NO; // not a special area, carry on.
77 }
88
9- + static void Cocoa_SyncMouseButtonState(SDL_Mouse *mouse, SDL_MouseID mouseID)
9+ + static void Cocoa_SyncMouseButtonState(SDL_Mouse *mouse, SDL_MouseID mouseID, Uint8 excludeButton )
1010+ {
1111+ const NSUInteger actualButtons = [NSEvent pressedMouseButtons];
1212+ SDL_MouseInputSource *source = NULL;
@@ -43,8 +43,13 @@ index 3425737..df6c350 100644
4343+ actualButtonState |= SDL_BUTTON_X2MASK;
4444+ }
4545+
46- + // Sync any buttons that are out of sync
46+ + // Sync any buttons that are out of sync (except the one being processed)
4747+ for (Uint8 button = SDL_BUTTON_LEFT; button <= SDL_BUTTON_X2; ++button) {
48+ + // Skip the button being processed to avoid duplicate events
49+ + if (excludeButton != 0 && button == excludeButton) {
50+ + continue;
51+ + }
52+ +
4853+ Uint32 buttonMask = SDL_BUTTON_MASK(button);
4954+ bool sdlPressed = (sdlButtonState & buttonMask) != 0;
5055+ bool actuallyPressed = (actualButtonState & buttonMask) != 0;
@@ -62,10 +67,9 @@ index 3425737..df6c350 100644
6267 //const int clicks = (int)[theEvent clickCount];
6368 SDL_Window *focus = SDL_GetKeyboardFocus();
6469
65- + // Sync button state with hardware before processing event
66- + Cocoa_SyncMouseButtonState(mouse, mouseID);
70+ + // Sync button state with hardware before processing event (exclude the button being processed to avoid duplicate events)
71+ + Cocoa_SyncMouseButtonState(mouse, mouseID, button );
6772+
6873 // macOS will send non-left clicks to background windows without raising them, so we need to
6974 // temporarily adjust the mouse position when this happens, as `mouse` will be tracking
7075 // the position in the currently-focused window. We don't (currently) send a mousemove
71-
0 commit comments