Fixed bug 2931 - Large relative mouse motion jumps when using touch input
authorSam Lantinga <slouken@libsdl.org>
Sat, 12 Aug 2017 20:25:49 -0700
changeset 112589fc2e83124ba
parent 11257 7561c9adebd4
child 11259 931e9d3a452e
Fixed bug 2931 - Large relative mouse motion jumps when using touch input
src/events/SDL_mouse.c
src/events/SDL_mouse_c.h
     1.1 --- a/src/events/SDL_mouse.c	Sat Aug 12 20:21:34 2017 -0700
     1.2 +++ b/src/events/SDL_mouse.c	Sat Aug 12 20:25:49 2017 -0700
     1.3 @@ -173,6 +173,7 @@
     1.4      }
     1.5  
     1.6      mouse->focus = window;
     1.7 +    mouse->has_position = SDL_FALSE;
     1.8  
     1.9      if (mouse->focus) {
    1.10          SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
    1.11 @@ -223,10 +224,10 @@
    1.12  
    1.13      if (window != mouse->focus) {
    1.14  #ifdef DEBUG_MOUSE
    1.15 -         printf("Mouse entered window, synthesizing focus gain & move event\n");
    1.16 +        printf("Mouse entered window, synthesizing focus gain & move event\n");
    1.17  #endif
    1.18 -         SDL_SetMouseFocus(window);
    1.19 -         SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
    1.20 +        SDL_SetMouseFocus(window);
    1.21 +        SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
    1.22      }
    1.23      return SDL_TRUE;
    1.24  }
    1.25 @@ -271,7 +272,7 @@
    1.26          return 0;
    1.27      }
    1.28  
    1.29 -    if (mouse->relative_mode_warp) {
    1.30 +    if (mouseID != SDL_TOUCH_MOUSEID && mouse->relative_mode_warp) {
    1.31          int center_x = 0, center_y = 0;
    1.32          SDL_GetWindowSize(window, &center_x, &center_y);
    1.33          center_x /= 2;
    1.34 @@ -309,6 +310,19 @@
    1.35          return 0;
    1.36      }
    1.37  
    1.38 +    /* Ignore relative motion when first positioning the mouse */
    1.39 +    if (!mouse->has_position) {
    1.40 +        xrel = 0;
    1.41 +        yrel = 0;
    1.42 +        mouse->has_position = SDL_TRUE;
    1.43 +    }
    1.44 +
    1.45 +    /* Ignore relative motion positioning the first touch */
    1.46 +    if (mouseID == SDL_TOUCH_MOUSEID && !mouse->buttonstate) {
    1.47 +        xrel = 0;
    1.48 +        yrel = 0;
    1.49 +    }
    1.50 +
    1.51      /* Update internal mouse coordinates */
    1.52      if (!mouse->relative_mode) {
    1.53          mouse->x = x;
     2.1 --- a/src/events/SDL_mouse_c.h	Sat Aug 12 20:21:34 2017 -0700
     2.2 +++ b/src/events/SDL_mouse_c.h	Sat Aug 12 20:25:49 2017 -0700
     2.3 @@ -81,6 +81,7 @@
     2.4      int ydelta;
     2.5      int last_x, last_y;         /* the last reported x and y coordinates */
     2.6      Uint32 buttonstate;
     2.7 +    SDL_bool has_position;
     2.8      SDL_bool relative_mode;
     2.9      SDL_bool relative_mode_warp;
    2.10      float normal_speed_scale;