Don't change mouse capture based on touch events Fixes https://github.com/libsdl-org/SDL/issues/5652
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 68 69 70 71 72 73 74 75 76
diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c
index ba486ee..ae85a0c 100644
--- a/src/events/SDL_mouse.c
+++ b/src/events/SDL_mouse.c
@@ -230,13 +230,15 @@ SDL_GetMouse(void)
return &SDL_mouse;
}
-static Uint32 GetButtonState(SDL_Mouse *mouse)
+static Uint32 GetButtonState(SDL_Mouse *mouse, SDL_bool include_touch)
{
int i;
Uint32 buttonstate = 0;
for (i = 0; i < mouse->num_sources; ++i) {
- buttonstate |= mouse->sources[i].buttonstate;
+ if (include_touch || mouse->sources[i].mouseID != SDL_TOUCH_MOUSEID) {
+ buttonstate |= mouse->sources[i].buttonstate;
+ }
}
return buttonstate;
}
@@ -331,7 +333,7 @@ SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int
{
if (window && !relative) {
SDL_Mouse *mouse = SDL_GetMouse();
- if (!SDL_UpdateMouseFocus(window, x, y, GetButtonState(mouse), (mouseID == SDL_TOUCH_MOUSEID) ? SDL_FALSE : SDL_TRUE)) {
+ if (!SDL_UpdateMouseFocus(window, x, y, GetButtonState(mouse, SDL_TRUE), (mouseID == SDL_TOUCH_MOUSEID) ? SDL_FALSE : SDL_TRUE)) {
return 0;
}
}
@@ -432,7 +434,7 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
}
/* Ignore relative motion positioning the first touch */
- if (mouseID == SDL_TOUCH_MOUSEID && !GetButtonState(mouse)) {
+ if (mouseID == SDL_TOUCH_MOUSEID && !GetButtonState(mouse, SDL_TRUE)) {
xrel = 0;
yrel = 0;
}
@@ -506,7 +508,7 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
event.motion.which = mouseID;
/* Set us pending (or clear during a normal mouse movement event) as having triggered */
mouse->was_touch_mouse_events = (mouseID == SDL_TOUCH_MOUSEID)? SDL_TRUE : SDL_FALSE;
- event.motion.state = GetButtonState(mouse);
+ event.motion.state = GetButtonState(mouse, SDL_TRUE);
event.motion.x = mouse->x;
event.motion.y = mouse->y;
event.motion.xrel = xrel;
@@ -840,7 +842,7 @@ SDL_GetMouseState(int *x, int *y)
if (y) {
*y = mouse->y;
}
- return GetButtonState(mouse);
+ return GetButtonState(mouse, SDL_TRUE);
}
Uint32
@@ -856,7 +858,7 @@ SDL_GetRelativeMouseState(int *x, int *y)
}
mouse->xdelta = 0;
mouse->ydelta = 0;
- return GetButtonState(mouse);
+ return GetButtonState(mouse, SDL_TRUE);
}
Uint32
@@ -1041,7 +1043,7 @@ SDL_UpdateMouseCapture(SDL_bool force_release)
if (!force_release) {
if (SDL_GetMessageBoxCount() == 0 &&
- (mouse->capture_desired || (mouse->auto_capture && SDL_GetMouseState(NULL, NULL) != 0))) {
+ (mouse->capture_desired || (mouse->auto_capture && GetButtonState(mouse, SDL_FALSE) != 0))) {
if (!mouse->relative_mode) {
capture_window = SDL_GetKeyboardFocus();
}