src/events/SDL_mouse.c
changeset 12943 49190e92b7d1
parent 12934 d03900e991a2
child 12979 bbbb30026158
     1.1 --- a/src/events/SDL_mouse.c	Sun Jul 14 16:59:39 2019 -0700
     1.2 +++ b/src/events/SDL_mouse.c	Mon Jul 15 09:36:53 2019 -0700
     1.3 @@ -156,6 +156,8 @@
     1.4      SDL_AddHintCallback(SDL_HINT_MOUSE_TOUCH_EVENTS,
     1.5                          SDL_MouseTouchEventsChanged, mouse);
     1.6  
     1.7 +    mouse->was_touch_mouse_events = SDL_FALSE; /* no touch to mouse movement event pending */
     1.8 +
     1.9      mouse->cursor_shown = SDL_TRUE;
    1.10  
    1.11      return (0);
    1.12 @@ -244,7 +246,7 @@
    1.13  
    1.14  /* Check to see if we need to synthesize focus events */
    1.15  static SDL_bool
    1.16 -SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate)
    1.17 +SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate, SDL_bool send_mouse_motion)
    1.18  {
    1.19      SDL_Mouse *mouse = SDL_GetMouse();
    1.20      SDL_bool inWindow = SDL_TRUE;
    1.21 @@ -275,7 +277,9 @@
    1.22  #ifdef DEBUG_MOUSE
    1.23              printf("Mouse left window, synthesizing move & focus lost event\n");
    1.24  #endif
    1.25 -            SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
    1.26 +            if (send_mouse_motion) {
    1.27 +                SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
    1.28 +            }
    1.29              SDL_SetMouseFocus(NULL);
    1.30          }
    1.31          return SDL_FALSE;
    1.32 @@ -286,7 +290,9 @@
    1.33          printf("Mouse entered window, synthesizing focus gain & move event\n");
    1.34  #endif
    1.35          SDL_SetMouseFocus(window);
    1.36 -        SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
    1.37 +        if (send_mouse_motion) {
    1.38 +            SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
    1.39 +        }
    1.40      }
    1.41      return SDL_TRUE;
    1.42  }
    1.43 @@ -296,7 +302,7 @@
    1.44  {
    1.45      if (window && !relative) {
    1.46          SDL_Mouse *mouse = SDL_GetMouse();
    1.47 -        if (!SDL_UpdateMouseFocus(window, x, y, mouse->buttonstate)) {
    1.48 +        if (!SDL_UpdateMouseFocus(window, x, y, mouse->buttonstate, (mouseID == SDL_TOUCH_MOUSEID) ? SDL_FALSE : SDL_TRUE)) {
    1.49              return 0;
    1.50          }
    1.51      }
    1.52 @@ -446,6 +452,8 @@
    1.53          event.motion.type = SDL_MOUSEMOTION;
    1.54          event.motion.windowID = mouse->focus ? mouse->focus->id : 0;
    1.55          event.motion.which = mouseID;
    1.56 +        /* Set us pending (or clear during a normal mouse movement event) as having triggered */
    1.57 +        mouse->was_touch_mouse_events = (mouseID == SDL_TOUCH_MOUSEID)? SDL_TRUE : SDL_FALSE;
    1.58          event.motion.state = mouse->buttonstate;
    1.59          event.motion.x = mouse->x;
    1.60          event.motion.y = mouse->y;
    1.61 @@ -530,7 +538,7 @@
    1.62  
    1.63      /* We do this after calculating buttonstate so button presses gain focus */
    1.64      if (window && state == SDL_PRESSED) {
    1.65 -        SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
    1.66 +        SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate, SDL_TRUE);
    1.67      }
    1.68  
    1.69      if (buttonstate == mouse->buttonstate) {
    1.70 @@ -580,7 +588,7 @@
    1.71  
    1.72      /* We do this after dispatching event so button releases can lose focus */
    1.73      if (window && state == SDL_RELEASED) {
    1.74 -        SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
    1.75 +        SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate, SDL_TRUE);
    1.76      }
    1.77  
    1.78      return posted;