Browse Source

A better fix for love.mouse.setPosition not updating the return values of love.window.getPosition until the next love.event.pump call on Windows and Linux.

Alex Szpakowski 10 years ago
parent
commit
8989e39b1e
1 changed files with 8 additions and 11 deletions
  1. 8 11
      src/modules/mouse/sdl/Mouse.cpp

+ 8 - 11
src/modules/mouse/sdl/Mouse.cpp

@@ -112,18 +112,10 @@ 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;
-	GetSDLMouseState(&x, nullptr);
+	SDL_GetMouseState(&x, nullptr);
 	windowToPixelCoords(&x, nullptr);
 
 	return x;
@@ -132,7 +124,7 @@ int Mouse::getX() const
 int Mouse::getY() const
 {
 	int y;
-	GetSDLMouseState(nullptr, &y);
+	SDL_GetMouseState(nullptr, &y);
 	windowToPixelCoords(nullptr, &y);
 
 	return y;
@@ -141,7 +133,7 @@ int Mouse::getY() const
 void Mouse::getPosition(int &x, int &y) const
 {
 	int mx, my;
-	GetSDLMouseState(&mx, &my);
+	SDL_GetMouseState(&mx, &my);
 	windowToPixelCoords(&mx, &my);
 
 	x = mx;
@@ -158,6 +150,11 @@ void Mouse::setPosition(int x, int y)
 
 	pixelToWindowCoords(&x, &y);
 	SDL_WarpMouseInWindow(handle, x, y);
+
+	// SDL_WarpMouse doesn't directly update SDL's internal mouse state in Linux
+	// and Windows, so we call SDL_PumpEvents now to make sure the next
+	// getPosition call always returns the updated state.
+	SDL_PumpEvents();
 }
 
 void Mouse::setX(int x)