From 2cb49721a4a21244f45ee89a1fef3cd8166e02f0 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 11 Mar 2011 18:16:39 -0800 Subject: [PATCH] Fixed bug 1165 (SDL_GetMouseState() returns wrong location after switch to/from fullscreen) I'm solving this by moving the mouse to the correct location after a fullscreen mode switch. --- src/video/SDL_video.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 58b937ae1..77de57372 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -1017,6 +1017,17 @@ SDL_GetWindowPixelFormat(SDL_Window * window) return display->current_mode.format; } +static void +SDL_RestoreMousePosition(SDL_Window *window) +{ + int x, y; + + if (window == SDL_GetMouseFocus()) { + SDL_GetMouseState(&x, &y); + SDL_WarpMouseInWindow(window, x, y); + } +} + static void SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen) { @@ -1070,6 +1081,8 @@ SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen) } else { SDL_OnWindowResized(other); } + + SDL_RestoreMousePosition(other); return; } } @@ -1085,6 +1098,9 @@ SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen) /* Generate a mode change event here */ SDL_OnWindowResized(window); + + /* Restore the cursor position */ + SDL_RestoreMousePosition(window); } #define CREATE_FLAGS \