From 8a9a73151d50d76dc53fbbee80e7014f4127c8b6 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 3 Jan 2015 23:02:10 -0400 Subject: [PATCH] Pump events when calling love.mouse.getPosition/getX/getY/setX/setY, since some of SDL's backends don't update the internal mouse state until the next PumpEvents, if SDL_WarpMouseInWindow was called previously. Resolves issue #968. --- src/modules/mouse/sdl/Mouse.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/modules/mouse/sdl/Mouse.cpp b/src/modules/mouse/sdl/Mouse.cpp index b39e6580d..566baf06e 100644 --- a/src/modules/mouse/sdl/Mouse.cpp +++ b/src/modules/mouse/sdl/Mouse.cpp @@ -112,10 +112,18 @@ love::mouse::Cursor *Mouse::getCursor() const return curCursor.get(); } +static Uint32 GetSDLMouseState(int *x, int *y) +{ + // SDL's Linux and Windows video backends don't update the internal mouse + // state until the next PumpEvents, if SDL_WarpMouse was called previously. + SDL_PumpEvents(); + return SDL_GetMouseState(x, y); +} + int Mouse::getX() const { int x; - SDL_GetMouseState(&x, nullptr); + GetSDLMouseState(&x, nullptr); windowToPixelCoords(&x, nullptr); return x; @@ -124,7 +132,7 @@ int Mouse::getX() const int Mouse::getY() const { int y; - SDL_GetMouseState(nullptr, &y); + GetSDLMouseState(nullptr, &y); windowToPixelCoords(nullptr, &y); return y; @@ -133,7 +141,7 @@ int Mouse::getY() const void Mouse::getPosition(int &x, int &y) const { int mx, my; - SDL_GetMouseState(&mx, &my); + GetSDLMouseState(&mx, &my); windowToPixelCoords(&mx, &my); x = mx;