From cf092eca909a263d892080baa67deaaaaef457d8 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 9 Oct 2019 13:42:13 -0400 Subject: [PATCH] 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 | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index 646649d9930c7..29c445fd8af55 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -381,19 +381,16 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ yrel = y - mouse->last_y; } - /* Drop events that don't change state */ - if (!xrel && !yrel) { -#ifdef DEBUG_MOUSE - printf("Mouse event didn't change state - dropped!\n"); -#endif - return 0; - } - /* Ignore relative motion when first positioning the mouse */ if (!mouse->has_position) { xrel = 0; yrel = 0; mouse->has_position = SDL_TRUE; + } else if (!xrel && !yrel) { /* Drop events that don't change state */ +#ifdef DEBUG_MOUSE + printf("Mouse event didn't change state - dropped!\n"); +#endif + return 0; } /* Ignore relative motion positioning the first touch */