Fixed bug 2931 - Large relative mouse motion jumps when using touch input
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c
index 3b9d184..42d142a 100644
--- a/src/events/SDL_mouse.c
+++ b/src/events/SDL_mouse.c
@@ -173,6 +173,7 @@ SDL_SetMouseFocus(SDL_Window * window)
}
mouse->focus = window;
+ mouse->has_position = SDL_FALSE;
if (mouse->focus) {
SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
@@ -223,10 +224,10 @@ SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate)
if (window != mouse->focus) {
#ifdef DEBUG_MOUSE
- printf("Mouse entered window, synthesizing focus gain & move event\n");
+ printf("Mouse entered window, synthesizing focus gain & move event\n");
#endif
- SDL_SetMouseFocus(window);
- SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
+ SDL_SetMouseFocus(window);
+ SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
}
return SDL_TRUE;
}
@@ -271,7 +272,7 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
return 0;
}
- if (mouse->relative_mode_warp) {
+ if (mouseID != SDL_TOUCH_MOUSEID && mouse->relative_mode_warp) {
int center_x = 0, center_y = 0;
SDL_GetWindowSize(window, ¢er_x, ¢er_y);
center_x /= 2;
@@ -309,6 +310,19 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
return 0;
}
+ /* Ignore relative motion when first positioning the mouse */
+ if (!mouse->has_position) {
+ xrel = 0;
+ yrel = 0;
+ mouse->has_position = SDL_TRUE;
+ }
+
+ /* Ignore relative motion positioning the first touch */
+ if (mouseID == SDL_TOUCH_MOUSEID && !mouse->buttonstate) {
+ xrel = 0;
+ yrel = 0;
+ }
+
/* Update internal mouse coordinates */
if (!mouse->relative_mode) {
mouse->x = x;
diff --git a/src/events/SDL_mouse_c.h b/src/events/SDL_mouse_c.h
index 947fbec..c6ba729 100644
--- a/src/events/SDL_mouse_c.h
+++ b/src/events/SDL_mouse_c.h
@@ -81,6 +81,7 @@ typedef struct
int ydelta;
int last_x, last_y; /* the last reported x and y coordinates */
Uint32 buttonstate;
+ SDL_bool has_position;
SDL_bool relative_mode;
SDL_bool relative_mode_warp;
float normal_speed_scale;