mouse: Save initial position yet even if xrel and yrel are 0.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 09 Oct 2019 13:42:13 -0400
changeset 1310611be7c38d220
parent 13105 db9d0d0b7ebc
child 13107 074c42dbf8c9
mouse: Save initial position yet even if xrel and yrel are 0.

The X11 target sets mouse->last_x and last_y in EnterNotify and then calls
SDL_SendMouseMotion(), which throws away the new position because it matches
the mouse->last_x and last_y we just set, meaning that if the pointer is
in the window when it created, SDL_GetMouseState() will report a position of
0,0 until a MotionNotify event (the pointer moves) arrives and corrects the
mouse state.

Mostly fixes Bugzilla #1612.
src/events/SDL_mouse.c
     1.1 --- a/src/events/SDL_mouse.c	Sat Oct 05 20:19:10 2019 -0400
     1.2 +++ b/src/events/SDL_mouse.c	Wed Oct 09 13:42:13 2019 -0400
     1.3 @@ -381,19 +381,16 @@
     1.4          yrel = y - mouse->last_y;
     1.5      }
     1.6  
     1.7 -    /* Drop events that don't change state */
     1.8 -    if (!xrel && !yrel) {
     1.9 -#ifdef DEBUG_MOUSE
    1.10 -        printf("Mouse event didn't change state - dropped!\n");
    1.11 -#endif
    1.12 -        return 0;
    1.13 -    }
    1.14 -
    1.15      /* Ignore relative motion when first positioning the mouse */
    1.16      if (!mouse->has_position) {
    1.17          xrel = 0;
    1.18          yrel = 0;
    1.19          mouse->has_position = SDL_TRUE;
    1.20 +    } else if (!xrel && !yrel) {  /* Drop events that don't change state */
    1.21 +#ifdef DEBUG_MOUSE
    1.22 +        printf("Mouse event didn't change state - dropped!\n");
    1.23 +#endif
    1.24 +        return 0;
    1.25      }
    1.26  
    1.27      /* Ignore relative motion positioning the first touch */