From f5a0ff784e033874405a49ce157e0d10f12f1fcf Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Sat, 4 Feb 2012 00:13:21 +1300 Subject: [PATCH] Make mouse relative mode save the original co-ordinates to restore them properly. --- src/events/SDL_mouse.c | 8 ++++++-- src/events/SDL_mouse_c.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index b847a879a..ff20a79ed 100755 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -323,9 +323,13 @@ SDL_SetRelativeMouseMode(SDL_bool enabled) /* Set the relative mode */ mouse->relative_mode = enabled; - if (!enabled && mouse->focus) { + if (enabled) { + /* Save the expected mouse position */ + mouse->original_x = mouse->x; + mouse->original_y = mouse->y; + } else if (mouse->focus) { /* Restore the expected mouse position */ - SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y); + SDL_WarpMouseInWindow(mouse->focus, mouse->original_x, mouse->original_y); } /* Flush pending mouse motion */ diff --git a/src/events/SDL_mouse_c.h b/src/events/SDL_mouse_c.h index 9562e0756..d571ddabd 100755 --- a/src/events/SDL_mouse_c.h +++ b/src/events/SDL_mouse_c.h @@ -60,6 +60,8 @@ typedef struct int last_x, last_y; /* the last reported x and y coordinates */ Uint8 buttonstate; SDL_bool relative_mode; + /* the x and y coordinates when relative mode was activated */ + int original_x, original_y; SDL_Cursor *cursors; SDL_Cursor *def_cursor;