src/video/cocoa/SDL_cocoamouse.m
changeset 4484 9322f7db8603
parent 4465 3e69e077cb95
child 4498 3d91e31fcf71
--- a/src/video/cocoa/SDL_cocoamouse.m	Mon Jul 05 22:45:45 2010 -0700
+++ b/src/video/cocoa/SDL_cocoamouse.m	Mon Jul 05 22:48:13 2010 -0700
@@ -52,6 +52,7 @@
     int i;
     NSPoint point = { 0, 0 };
     SDL_Window *window;
+    SDL_Window *focus = SDL_GetMouseFocus();
 
     /* See if there are any fullscreen windows that might handle this event */
     window = NULL;
@@ -66,19 +67,18 @@
             point = [NSEvent mouseLocation];
             point.x = point.x - bounds.x;
             point.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - point.y - bounds.y;
-            if ((point.x >= 0 && point.x < candidate->w) ||
+            if ((point.x >= 0 && point.x < candidate->w) &&
                 (point.y >= 0 && point.y < candidate->h)) {
                 /* This is it! */
                 window = candidate;
                 break;
+            } else if (candidate == focus) {
+                SDL_SetMouseFocus(NULL);
             }
         }
     }
 
-    /* Set the focus appropriately */
-    SDL_SetMouseFocus(window);
-
-    if (window) {
+    if (!window) {
         return;
     }
 
@@ -86,18 +86,18 @@
     case NSLeftMouseDown:
     case NSOtherMouseDown:
     case NSRightMouseDown:
-        SDL_SendMouseButton(SDL_PRESSED, ConvertMouseButtonToSDL([event buttonNumber]));
+        SDL_SendMouseButton(window, SDL_PRESSED, ConvertMouseButtonToSDL([event buttonNumber]));
         break;
     case NSLeftMouseUp:
     case NSOtherMouseUp:
     case NSRightMouseUp:
-        SDL_SendMouseButton(SDL_RELEASED, ConvertMouseButtonToSDL([event buttonNumber]));
+        SDL_SendMouseButton(window, SDL_RELEASED, ConvertMouseButtonToSDL([event buttonNumber]));
         break;
     case NSLeftMouseDragged:
     case NSRightMouseDragged:
     case NSOtherMouseDragged: /* usually middle mouse dragged */
     case NSMouseMoved:
-        SDL_SendMouseMotion(0, (int)point.x, (int)point.y);
+        SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
         break;
     default: /* just to avoid compiler warnings */
         break;