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 536771fe70373e58
parent 5366 d032ec40e7c1
child 5368 f0ee2c086931
Fixed bug 1105 (SDL_GetMouseState returns wrong location upon window re-activation)
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Sun Feb 20 19:15:00 2011 -0800
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sun Feb 20 20:49:31 2011 -0800
     1.3 @@ -135,8 +135,20 @@
     1.4  
     1.5  - (void)windowDidBecomeKey:(NSNotification *)aNotification
     1.6  {
     1.7 +    SDL_Window *window = _data->window;
     1.8 +
     1.9      /* We're going to get keyboard events, since we're key. */
    1.10 -    SDL_SetKeyboardFocus(_data->window);
    1.11 +    SDL_SetKeyboardFocus(window);
    1.12 +
    1.13 +    /* If we just gained focus we need the updated mouse position */
    1.14 +    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    1.15 +        NSPoint point;
    1.16 +        point = [NSEvent mouseLocation];
    1.17 +        point = [_data->nswindow convertScreenToBase:point];
    1.18 +        point = [[_data->nswindow contentView] convertPoint:point fromView:nil];
    1.19 +        point.y = window->h - point.y;
    1.20 +        SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
    1.21 +    }
    1.22  
    1.23      /* Check to see if someone updated the clipboard */
    1.24      Cocoa_CheckClipboardUpdate(_data->videodata);