Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
authorSam Lantinga <slouken@libsdl.org>
Sun, 20 Feb 2011 20:49:31 -0800
changeset 5367 71fe70373e58
parent 5366 d032ec40e7c1
child 5368 f0ee2c086931
Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
src/video/cocoa/SDL_cocoawindow.m
--- a/src/video/cocoa/SDL_cocoawindow.m	Sun Feb 20 19:15:00 2011 -0800
+++ b/src/video/cocoa/SDL_cocoawindow.m	Sun Feb 20 20:49:31 2011 -0800
@@ -135,8 +135,20 @@
 
 - (void)windowDidBecomeKey:(NSNotification *)aNotification
 {
+    SDL_Window *window = _data->window;
+
     /* We're going to get keyboard events, since we're key. */
-    SDL_SetKeyboardFocus(_data->window);
+    SDL_SetKeyboardFocus(window);
+
+    /* If we just gained focus we need the updated mouse position */
+    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+        NSPoint point;
+        point = [NSEvent mouseLocation];
+        point = [_data->nswindow convertScreenToBase:point];
+        point = [[_data->nswindow contentView] convertPoint:point fromView:nil];
+        point.y = window->h - point.y;
+        SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
+    }
 
     /* Check to see if someone updated the clipboard */
     Cocoa_CheckClipboardUpdate(_data->videodata);