Don't send mouse events when warping in relative mode
This fixes games which set relative mode and then did mouse warping at the same time Reference https://github.com/libsdl-org/SDL/issues/5609main
parent
ea15253220
commit
b44241ab2f
|
@ -866,8 +866,8 @@ SDL_GetGlobalMouseState(int *x, int *y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
|
SDL_PerformWarpMouseInWindow(SDL_Window *window, int x, int y, SDL_bool ignore_relative_mode)
|
||||||
{
|
{
|
||||||
SDL_Mouse *mouse = SDL_GetMouse();
|
SDL_Mouse *mouse = SDL_GetMouse();
|
||||||
|
|
||||||
|
@ -883,6 +883,20 @@ SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mouse->relative_mode && !ignore_relative_mode) {
|
||||||
|
/* 2.0.22 made warping in relative mode actually functional, which
|
||||||
|
* surprised many applications that weren't expecting the additional
|
||||||
|
* mouse motion.
|
||||||
|
*
|
||||||
|
* So for now, warping in relative mode adjusts the absolution position
|
||||||
|
* but doesn't generate motion events.
|
||||||
|
*/
|
||||||
|
mouse->x = x;
|
||||||
|
mouse->y = y;
|
||||||
|
mouse->has_position = SDL_TRUE;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Ignore the previous position when we warp */
|
/* Ignore the previous position when we warp */
|
||||||
mouse->has_position = SDL_FALSE;
|
mouse->has_position = SDL_FALSE;
|
||||||
|
|
||||||
|
@ -894,6 +908,12 @@ SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
|
||||||
|
{
|
||||||
|
SDL_PerformWarpMouseInWindow(window, x, y, SDL_FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
SDL_WarpMouseGlobal(int x, int y)
|
SDL_WarpMouseGlobal(int x, int y)
|
||||||
{
|
{
|
||||||
|
@ -953,8 +973,9 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
|
||||||
if (enabled && focusWindow) {
|
if (enabled && focusWindow) {
|
||||||
SDL_SetMouseFocus(focusWindow);
|
SDL_SetMouseFocus(focusWindow);
|
||||||
|
|
||||||
if (mouse->relative_mode_warp)
|
if (mouse->relative_mode_warp) {
|
||||||
SDL_WarpMouseInWindow(focusWindow, focusWindow->w/2, focusWindow->h/2);
|
SDL_PerformWarpMouseInWindow(focusWindow, focusWindow->w/2, focusWindow->h/2, SDL_TRUE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (focusWindow) {
|
if (focusWindow) {
|
||||||
|
@ -962,7 +983,7 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
|
||||||
|
|
||||||
/* Put the cursor back to where the application expects it */
|
/* Put the cursor back to where the application expects it */
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
SDL_WarpMouseInWindow(focusWindow, mouse->x, mouse->y);
|
SDL_PerformWarpMouseInWindow(focusWindow, mouse->x, mouse->y, SDL_TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_UpdateMouseCapture(SDL_FALSE);
|
SDL_UpdateMouseCapture(SDL_FALSE);
|
||||||
|
|
Loading…
Reference in New Issue