@@ -1703,76 +1703,12 @@ - (BOOL)processHitTest:(NSEvent *)theEvent
17031703 return NO ; // not a special area, carry on.
17041704}
17051705
1706- static void Cocoa_SyncMouseButtonState (SDL_Mouse *mouse, SDL_MouseID mouseID, Uint8 excludeButton, bool excludeButtonState)
1707- {
1708- const NSUInteger actualButtons = [NSEvent pressedMouseButtons ];
1709- SDL_MouseInputSource *source = NULL ;
1710-
1711- // Find the mouse input source
1712- for (int i = 0 ; i < mouse->num_sources ; ++i) {
1713- if (mouse->sources [i].mouseID == mouseID) {
1714- source = &mouse->sources [i];
1715- break ;
1716- }
1717- }
1718-
1719- if (!source) {
1720- return ; // No source yet, will be created by the actual event
1721- }
1722-
1723- Uint32 sdlButtonState = source->buttonstate ;
1724- Uint32 actualButtonState = 0 ;
1725-
1726- // Convert NSEvent button mask to SDL button mask
1727- if (actualButtons & (1 << 0 )) {
1728- actualButtonState |= SDL_BUTTON_LMASK;
1729- }
1730- if (actualButtons & (1 << 1 )) {
1731- actualButtonState |= SDL_BUTTON_RMASK;
1732- }
1733- if (actualButtons & (1 << 2 )) {
1734- actualButtonState |= SDL_BUTTON_MMASK;
1735- }
1736- if (actualButtons & (1 << 3 )) {
1737- actualButtonState |= SDL_BUTTON_X1MASK;
1738- }
1739- if (actualButtons & (1 << 4 )) {
1740- actualButtonState |= SDL_BUTTON_X2MASK;
1741- }
1742-
1743- // Sync any buttons that are out of sync
1744- for (Uint8 button = SDL_BUTTON_LEFT; button <= SDL_BUTTON_X2; ++button) {
1745- Uint32 buttonMask = SDL_BUTTON_MASK (button);
1746- bool sdlPressed = (sdlButtonState & buttonMask) != 0 ;
1747- bool actuallyPressed = (actualButtonState & buttonMask) != 0 ;
1748-
1749- if (excludeButton != 0 && button == excludeButton) {
1750- // For the button being processed, check if SDL state matches the upcoming event state
1751- // If not, we need to send the opposite event first to sync (e.g., if processing DOWN
1752- // but SDL thinks it's already DOWN, send UP first)
1753- if (sdlPressed != excludeButtonState) {
1754- // Send synthetic event to sync to opposite state before the actual event
1755- SDL_SendMouseButton (0 , mouse->focus , mouseID, button, !excludeButtonState);
1756- }
1757- continue ; // The actual event will be processed after this sync
1758- }
1759-
1760- if (sdlPressed != actuallyPressed) {
1761- // Send synthetic event to sync state
1762- SDL_SendMouseButton (0 , mouse->focus , mouseID, button, actuallyPressed);
1763- }
1764- }
1765- }
1766-
17671706static void Cocoa_SendMouseButtonClicks (SDL_Mouse *mouse, NSEvent *theEvent, SDL_Window *window, Uint8 button, bool down)
17681707{
17691708 SDL_MouseID mouseID = SDL_DEFAULT_MOUSE_ID;
17701709 // const int clicks = (int)[theEvent clickCount];
17711710 SDL_Window *focus = SDL_GetKeyboardFocus ();
17721711
1773- // Sync button state with hardware before processing event (exclude the button being processed to avoid duplicate events)
1774- Cocoa_SyncMouseButtonState (mouse, mouseID, button, down);
1775-
17761712 // macOS will send non-left clicks to background windows without raising them, so we need to
17771713 // temporarily adjust the mouse position when this happens, as `mouse` will be tracking
17781714 // the position in the currently-focused window. We don't (currently) send a mousemove
0 commit comments