From 9ca918375fea8c34c5d21d9f9adf340db16d15c1 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 20 Feb 2011 20:49:31 -0800 Subject: [PATCH] Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation) --- src/video/cocoa/SDL_cocoawindow.m | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index bac23cb84..de90b7e03 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -135,8 +135,20 @@ - (void)windowDidDeminiaturize:(NSNotification *)aNotification - (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);