|
| 1 | +diff --git a/Sources/SwiftSDL3/src/video/cocoa/SDL_cocoawindow.m b/Sources/SwiftSDL3/src/video/cocoa/SDL_cocoawindow.m |
| 2 | +index 3425737..859b9f3 100644 |
| 3 | +--- a/Sources/SwiftSDL3/src/video/cocoa/SDL_cocoawindow.m |
| 4 | ++++ b/Sources/SwiftSDL3/src/video/cocoa/SDL_cocoawindow.m |
| 5 | +@@ -1703,6 +1703,56 @@ - (BOOL)processHitTest:(NSEvent *)theEvent |
| 6 | + return NO; // not a special area, carry on. |
| 7 | + } |
| 8 | + |
| 9 | ++static void Cocoa_SyncMouseButtonState(SDL_Mouse *mouse, SDL_MouseID mouseID) |
| 10 | ++{ |
| 11 | ++ const NSUInteger actualButtons = [NSEvent pressedMouseButtons]; |
| 12 | ++ Uint32 actualButtonState = 0; |
| 13 | ++ Uint32 sdlButtonState = 0; |
| 14 | ++ |
| 15 | ++ // Convert NSEvent button mask to SDL button mask |
| 16 | ++ if (actualButtons & (1 << 0)) { |
| 17 | ++ actualButtonState |= SDL_BUTTON_LMASK; |
| 18 | ++ } |
| 19 | ++ if (actualButtons & (1 << 1)) { |
| 20 | ++ actualButtonState |= SDL_BUTTON_RMASK; |
| 21 | ++ } |
| 22 | ++ if (actualButtons & (1 << 2)) { |
| 23 | ++ actualButtonState |= SDL_BUTTON_MMASK; |
| 24 | ++ } |
| 25 | ++ if (actualButtons & (1 << 3)) { |
| 26 | ++ actualButtonState |= SDL_BUTTON_X1MASK; |
| 27 | ++ } |
| 28 | ++ if (actualButtons & (1 << 4)) { |
| 29 | ++ actualButtonState |= SDL_BUTTON_X2MASK; |
| 30 | ++ } |
| 31 | ++ |
| 32 | ++ // Get SDL's tracked button state |
| 33 | ++ for (int i = 0; i < mouse->num_sources; ++i) { |
| 34 | ++ if (mouseID == SDL_GLOBAL_MOUSE_ID || mouseID == SDL_TOUCH_MOUSEID) { |
| 35 | ++ if (mouse->sources[i].mouseID != SDL_TOUCH_MOUSEID) { |
| 36 | ++ sdlButtonState |= mouse->sources[i].buttonstate; |
| 37 | ++ } |
| 38 | ++ } else { |
| 39 | ++ if (mouseID == mouse->sources[i].mouseID) { |
| 40 | ++ sdlButtonState = mouse->sources[i].buttonstate; |
| 41 | ++ break; |
| 42 | ++ } |
| 43 | ++ } |
| 44 | ++ } |
| 45 | ++ |
| 46 | ++ // Sync any buttons that are out of sync |
| 47 | ++ for (Uint8 btn = SDL_BUTTON_LEFT; btn <= SDL_BUTTON_X2; ++btn) { |
| 48 | ++ Uint32 buttonMask = SDL_BUTTON_MASK(btn); |
| 49 | ++ bool sdlPressed = (sdlButtonState & buttonMask) != 0; |
| 50 | ++ bool actuallyPressed = (actualButtonState & buttonMask) != 0; |
| 51 | ++ |
| 52 | ++ if (sdlPressed != actuallyPressed) { |
| 53 | ++ // Send synthetic event to sync state |
| 54 | ++ SDL_SendMouseButton(0, mouse->focus, mouseID, btn, actuallyPressed); |
| 55 | ++ } |
| 56 | ++ } |
| 57 | ++} |
| 58 | ++ |
| 59 | + static void Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_Window *window, Uint8 button, bool down) |
| 60 | + { |
| 61 | + SDL_MouseID mouseID = SDL_DEFAULT_MOUSE_ID; |
| 62 | +@@ -1919,6 +1969,9 @@ - (void)mouseMoved:(NSEvent *)theEvent |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | ++ // Sync button state with hardware before sending motion event |
| 67 | ++ Cocoa_SyncMouseButtonState(mouse, mouseID); |
| 68 | ++ |
| 69 | + SDL_SendMouseMotion(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, false, x, y); |
| 70 | + } |
| 71 | + |
0 commit comments