src/video/cocoa/SDL_cocoawindow.m
changeset 12929 d6c5eb7a0afb
parent 12923 73091a9e72f7
child 12937 41528cbd80ab
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Sun Jul 07 09:10:56 2019 -0700
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Jul 08 13:41:01 2019 -0400
     1.3 @@ -918,20 +918,10 @@
     1.4          return;
     1.5      }
     1.6  
     1.7 -    SDL_MouseID mouseID = mouse->mouseID;
     1.8 +    const SDL_MouseID mouseID = mouse->mouseID;
     1.9      int button;
    1.10      int clicks;
    1.11  
    1.12 -    #if TRACKPAD_REPORTS_TOUCH_MOUSEID
    1.13 -    if ([theEvent subtype] == NSEventSubtypeTouch) {  /* this is a synthetic from the OS */
    1.14 -        if (mouse->touch_mouse_events) {
    1.15 -            mouseID = SDL_TOUCH_MOUSEID;   /* Hint is set */
    1.16 -        } else {
    1.17 -            return;  /* no hint set, drop this one. */
    1.18 -        }
    1.19 -    }
    1.20 -    #endif
    1.21 -
    1.22      /* Ignore events that aren't inside the client area (i.e. title bar.) */
    1.23      if ([theEvent window]) {
    1.24          NSRect windowRect = [[[theEvent window] contentView] frame];
    1.25 @@ -989,20 +979,10 @@
    1.26          return;
    1.27      }
    1.28  
    1.29 -    SDL_MouseID mouseID = mouse->mouseID;
    1.30 +    const SDL_MouseID mouseID = mouse->mouseID;
    1.31      int button;
    1.32      int clicks;
    1.33  
    1.34 -    #if TRACKPAD_REPORTS_TOUCH_MOUSEID
    1.35 -    if ([theEvent subtype] == NSEventSubtypeTouch) {  /* this is a synthetic from the OS */
    1.36 -        if (mouse->touch_mouse_events) {
    1.37 -            mouseID = SDL_TOUCH_MOUSEID;   /* Hint is set */
    1.38 -        } else {
    1.39 -            return;  /* no hint set, drop this one. */
    1.40 -        }
    1.41 -    }
    1.42 -    #endif
    1.43 -
    1.44      if ([self processHitTest:theEvent]) {
    1.45          SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
    1.46          return;  /* stopped dragging, drop event. */
    1.47 @@ -1050,21 +1030,11 @@
    1.48          return;
    1.49      }
    1.50  
    1.51 -    SDL_MouseID mouseID = mouse->mouseID;
    1.52 +    const SDL_MouseID mouseID = mouse->mouseID;
    1.53      SDL_Window *window = _data->window;
    1.54      NSPoint point;
    1.55      int x, y;
    1.56  
    1.57 -    #if TRACKPAD_REPORTS_TOUCH_MOUSEID
    1.58 -    if ([theEvent subtype] == NSEventSubtypeTouch) {  /* this is a synthetic from the OS */
    1.59 -        if (mouse->touch_mouse_events) {
    1.60 -            mouseID = SDL_TOUCH_MOUSEID;   /* Hint is set */
    1.61 -        } else {
    1.62 -            return;  /* no hint set, drop this one. */
    1.63 -        }
    1.64 -    }
    1.65 -    #endif
    1.66 -
    1.67      if ([self processHitTest:theEvent]) {
    1.68          SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
    1.69          return;  /* dragging, drop event. */
    1.70 @@ -1134,7 +1104,12 @@
    1.71  
    1.72  - (void)touchesBeganWithEvent:(NSEvent *) theEvent
    1.73  {
    1.74 +    /* probably a MacBook trackpad; make this look like a synthesized event.
    1.75 +       This is backwards from reality, but better matches user expectations. */
    1.76 +    const BOOL istrackpad = ([theEvent subtype] == NSEventSubtypeMouseEvent);
    1.77 +
    1.78      NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
    1.79 +    const SDL_TouchID touchID = istrackpad ? SDL_MOUSE_TOUCHID : (SDL_TouchID)(intptr_t)[[touches anyObject] device];
    1.80      int existingTouchCount = 0;
    1.81  
    1.82      for (NSTouch* touch in touches) {
    1.83 @@ -1143,7 +1118,6 @@
    1.84          }
    1.85      }
    1.86      if (existingTouchCount == 0) {
    1.87 -        const SDL_TouchID touchID = (SDL_TouchID)(intptr_t)[[touches anyObject] device];
    1.88          int numFingers = SDL_GetNumTouchFingers(touchID);
    1.89          DLog("Reset Lost Fingers: %d", numFingers);
    1.90          for (--numFingers; numFingers >= 0; --numFingers) {
    1.91 @@ -1175,8 +1149,12 @@
    1.92  {
    1.93      NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
    1.94  
    1.95 +    /* probably a MacBook trackpad; make this look like a synthesized event.
    1.96 +       This is backwards from reality, but better matches user expectations. */
    1.97 +    const BOOL istrackpad = ([theEvent subtype] == NSEventSubtypeMouseEvent);
    1.98 +
    1.99      for (NSTouch *touch in touches) {
   1.100 -        const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device];
   1.101 +        const SDL_TouchID touchId = istrackpad ? SDL_MOUSE_TOUCHID : (SDL_TouchID)(intptr_t)[touch device];
   1.102          SDL_TouchDeviceType devtype = SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE;
   1.103  
   1.104  #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101202 /* Added in the 10.12.2 SDK. */