Skip to content

Commit

Permalink
Don't change mouse capture based on touch events
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken authored and PJB3005 committed Oct 5, 2022
1 parent be450b2 commit b2e25b1
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/events/SDL_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -840,7 +842,7 @@ SDL_GetMouseState(int *x, int *y)
if (y) {
*y = mouse->y;
}
return GetButtonState(mouse);
return GetButtonState(mouse, SDL_TRUE);
}

Uint32
Expand All @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit b2e25b1

Please sign in to comment.