Use OS-provided click counts on macOS and iOS for mouse press and release events.
authorAlex Szpakowski <slime73@gmail.com>
Sat, 24 Sep 2016 18:46:34 -0300
changeset 10366e1b52e69578b
parent 10365 7f3be5258f80
child 10367 e88a4e5539e5
Use OS-provided click counts on macOS and iOS for mouse press and release events.
src/events/SDL_mouse.c
src/events/SDL_mouse_c.h
src/video/cocoa/SDL_cocoawindow.m
src/video/uikit/SDL_uikitview.m
     1.1 --- a/src/events/SDL_mouse.c	Sat Sep 24 13:28:40 2016 -0300
     1.2 +++ b/src/events/SDL_mouse.c	Sat Sep 24 18:46:34 2016 -0300
     1.3 @@ -322,15 +322,13 @@
     1.4      return &mouse->clickstate[button];
     1.5  }
     1.6  
     1.7 -int
     1.8 -SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
     1.9 +static int
    1.10 +SDL_PrivateSendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
    1.11  {
    1.12      SDL_Mouse *mouse = SDL_GetMouse();
    1.13      int posted;
    1.14      Uint32 type;
    1.15      Uint32 buttonstate = mouse->buttonstate;
    1.16 -    SDL_MouseClickState *clickstate = GetMouseClickState(mouse, button);
    1.17 -    Uint8 click_count;
    1.18  
    1.19      /* Figure out which event to perform */
    1.20      switch (state) {
    1.21 @@ -358,7 +356,8 @@
    1.22      }
    1.23      mouse->buttonstate = buttonstate;
    1.24  
    1.25 -    if (clickstate) {
    1.26 +    if (clicks < 0) {
    1.27 +        SDL_MouseClickState *clickstate = GetMouseClickState(mouse, button);
    1.28          if (state == SDL_PRESSED) {
    1.29              Uint32 now = SDL_GetTicks();
    1.30  
    1.31 @@ -374,9 +373,7 @@
    1.32                  ++clickstate->click_count;
    1.33              }
    1.34          }
    1.35 -        click_count = clickstate->click_count;
    1.36 -    } else {
    1.37 -        click_count = 1;
    1.38 +        clicks = clickstate->click_count;
    1.39      }
    1.40  
    1.41      /* Post the event, if desired */
    1.42 @@ -388,7 +385,7 @@
    1.43          event.button.which = mouseID;
    1.44          event.button.state = state;
    1.45          event.button.button = button;
    1.46 -        event.button.clicks = click_count;
    1.47 +        event.button.clicks = (Uint8) SDL_min(clicks, 255);
    1.48          event.button.x = mouse->x;
    1.49          event.button.y = mouse->y;
    1.50          posted = (SDL_PushEvent(&event) > 0);
    1.51 @@ -398,8 +395,21 @@
    1.52      if (window && state == SDL_RELEASED) {
    1.53          SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
    1.54      }
    1.55 +    
    1.56 +    return posted;
    1.57 +}
    1.58  
    1.59 -    return posted;
    1.60 +int
    1.61 +SDL_SendMouseButtonClicks(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks)
    1.62 +{
    1.63 +    clicks = SDL_max(clicks, 0);
    1.64 +    return SDL_PrivateSendMouseButton(window, mouseID, state, button, clicks);
    1.65 +}
    1.66 +
    1.67 +int
    1.68 +SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
    1.69 +{
    1.70 +    return SDL_PrivateSendMouseButton(window, mouseID, state, button, -1);
    1.71  }
    1.72  
    1.73  int
     2.1 --- a/src/events/SDL_mouse_c.h	Sat Sep 24 13:28:40 2016 -0300
     2.2 +++ b/src/events/SDL_mouse_c.h	Sat Sep 24 18:46:34 2016 -0300
     2.3 @@ -119,6 +119,9 @@
     2.4  /* Send a mouse button event */
     2.5  extern int SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button);
     2.6  
     2.7 +/* Send a mouse button event with a click count */
     2.8 +extern int SDL_SendMouseButtonClicks(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks);
     2.9 +
    2.10  /* Send a mouse wheel event */
    2.11  extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction);
    2.12  
     3.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Sat Sep 24 13:28:40 2016 -0300
     3.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sat Sep 24 18:46:34 2016 -0300
     3.3 @@ -823,6 +823,7 @@
     3.4  - (void)mouseDown:(NSEvent *)theEvent
     3.5  {
     3.6      int button;
     3.7 +    int clicks;
     3.8  
     3.9      /* Ignore events that aren't inside the client area (i.e. title bar.) */
    3.10      if ([theEvent window]) {
    3.11 @@ -858,7 +859,9 @@
    3.12          button = (int) [theEvent buttonNumber] + 1;
    3.13          break;
    3.14      }
    3.15 -    SDL_SendMouseButton(_data->window, 0, SDL_PRESSED, button);
    3.16 +
    3.17 +    clicks = (int) [theEvent clickCount];
    3.18 +    SDL_SendMouseButtonClicks(_data->window, 0, SDL_PRESSED, button, clicks);
    3.19  }
    3.20  
    3.21  - (void)rightMouseDown:(NSEvent *)theEvent
    3.22 @@ -874,6 +877,7 @@
    3.23  - (void)mouseUp:(NSEvent *)theEvent
    3.24  {
    3.25      int button;
    3.26 +    int clicks;
    3.27  
    3.28      if ([self processHitTest:theEvent]) {
    3.29          SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIT_TEST, 0, 0);
    3.30 @@ -899,7 +903,9 @@
    3.31          button = (int) [theEvent buttonNumber] + 1;
    3.32          break;
    3.33      }
    3.34 -    SDL_SendMouseButton(_data->window, 0, SDL_RELEASED, button);
    3.35 +
    3.36 +    clicks = (int) [theEvent clickCount];
    3.37 +    SDL_SendMouseButtonClicks(_data->window, 0, SDL_RELEASED, button, clicks);
    3.38  }
    3.39  
    3.40  - (void)rightMouseUp:(NSEvent *)theEvent
    3.41 @@ -1264,7 +1270,7 @@
    3.42          }
    3.43      }
    3.44  
    3.45 -    [nswindow setContentView: contentView];
    3.46 +    [nswindow setContentView:contentView];
    3.47      [contentView release];
    3.48  
    3.49      /* Allow files and folders to be dragged onto the window by users */
     4.1 --- a/src/video/uikit/SDL_uikitview.m	Sat Sep 24 13:28:40 2016 -0300
     4.2 +++ b/src/video/uikit/SDL_uikitview.m	Sat Sep 24 18:46:34 2016 -0300
     4.3 @@ -143,12 +143,13 @@
     4.4  
     4.5          if (!firstFingerDown) {
     4.6              CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
     4.7 +            int clicks = (int) touch.tapCount;
     4.8  
     4.9              /* send mouse moved event */
    4.10              SDL_SendMouseMotion(sdlwindow, SDL_TOUCH_MOUSEID, 0, locationInView.x, locationInView.y);
    4.11  
    4.12              /* send mouse down event */
    4.13 -            SDL_SendMouseButton(sdlwindow, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
    4.14 +            SDL_SendMouseButtonClicks(sdlwindow, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT, clicks);
    4.15  
    4.16              firstFingerDown = touch;
    4.17          }
    4.18 @@ -166,7 +167,8 @@
    4.19  
    4.20          if (touch == firstFingerDown) {
    4.21              /* send mouse up */
    4.22 -            SDL_SendMouseButton(sdlwindow, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
    4.23 +            int clicks = (int) touch.tapCount;
    4.24 +            SDL_SendMouseButtonClicks(sdlwindow, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT, clicks);
    4.25              firstFingerDown = nil;
    4.26          }
    4.27