src/video/cocoa/SDL_cocoawindow.m
changeset 2059 4685ccd33d0e
parent 1973 81255f93dfcd
child 2152 003c1b5b07da
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Sat Oct 28 16:41:08 2006 +0000
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sat Oct 28 16:41:54 2006 +0000
     1.3 @@ -129,6 +129,7 @@
     1.4  {
     1.5      int index;
     1.6  
     1.7 +    /* We're going to get keyboard events, since we're key. */
     1.8      index = _data->videodata->keyboard;
     1.9      SDL_SetKeyboardFocus(index, _data->windowID);
    1.10  }
    1.11 @@ -136,7 +137,16 @@
    1.12  - (void)windowDidResignKey:(NSNotification *)aNotification
    1.13  {
    1.14      int index;
    1.15 +    SDL_Mouse *mouse;
    1.16  
    1.17 +    /* Some other window will get mouse events, since we're not key. */
    1.18 +    index = _data->videodata->mouse;
    1.19 +    mouse = SDL_GetMouse(index);
    1.20 +    if (mouse->focus == _data->windowID) {
    1.21 +        SDL_SetMouseFocus(index, 0);
    1.22 +    }
    1.23 +
    1.24 +    /* Some other window will get keyboard events, since we're not key. */
    1.25      index = _data->videodata->keyboard;
    1.26      SDL_SetKeyboardFocus(index, 0);
    1.27  }
    1.28 @@ -227,14 +237,21 @@
    1.29  
    1.30      index = _data->videodata->mouse;
    1.31      mouse = SDL_GetMouse(index);
    1.32 -    if (mouse->focus != _data->windowID) {
    1.33 -        SDL_SetMouseFocus(index, _data->windowID);
    1.34 -    }
    1.35  
    1.36      point = [NSEvent mouseLocation];
    1.37      point.x = point.x - rect.origin.x;
    1.38      point.y = rect.size.height - (point.y - rect.origin.y);
    1.39 -    SDL_SendMouseMotion(index, 0, (int)point.x, (int)point.y);
    1.40 +    if ( point.x < 0 || point.x >= rect.size.width ||
    1.41 +         point.y < 0 || point.y >= rect.size.height ) {
    1.42 +        if (mouse->focus != 0) {
    1.43 +            SDL_SetMouseFocus(index, 0);
    1.44 +        }
    1.45 +    } else {
    1.46 +        if (mouse->focus != _data->windowID) {
    1.47 +            SDL_SetMouseFocus(index, _data->windowID);
    1.48 +        }
    1.49 +        SDL_SendMouseMotion(index, 0, (int)point.x, (int)point.y);
    1.50 +    }
    1.51  }
    1.52  
    1.53  - (void)mouseDragged:(NSEvent *)theEvent