From 7a9dd46590d6cc9c91ffe47afded1aab120fef2d Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 28 Oct 2006 16:41:54 +0000 Subject: [PATCH] Fixed mouse enter/leave events for a single window. You lose mouse focus in Cocoa when the window is no longer key. --- src/video/cocoa/SDL_cocoawindow.m | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index a522e86f6..e8034e630 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -129,6 +129,7 @@ - (void)windowDidBecomeKey:(NSNotification *)aNotification { int index; + /* We're going to get keyboard events, since we're key. */ index = _data->videodata->keyboard; SDL_SetKeyboardFocus(index, _data->windowID); } @@ -136,7 +137,16 @@ - (void)windowDidBecomeKey:(NSNotification *)aNotification - (void)windowDidResignKey:(NSNotification *)aNotification { int index; + SDL_Mouse *mouse; + + /* Some other window will get mouse events, since we're not key. */ + index = _data->videodata->mouse; + mouse = SDL_GetMouse(index); + if (mouse->focus == _data->windowID) { + SDL_SetMouseFocus(index, 0); + } + /* Some other window will get keyboard events, since we're not key. */ index = _data->videodata->keyboard; SDL_SetKeyboardFocus(index, 0); } @@ -227,14 +237,21 @@ - (void)mouseMoved:(NSEvent *)theEvent index = _data->videodata->mouse; mouse = SDL_GetMouse(index); - if (mouse->focus != _data->windowID) { - SDL_SetMouseFocus(index, _data->windowID); - } point = [NSEvent mouseLocation]; point.x = point.x - rect.origin.x; point.y = rect.size.height - (point.y - rect.origin.y); - SDL_SendMouseMotion(index, 0, (int)point.x, (int)point.y); + if ( point.x < 0 || point.x >= rect.size.width || + point.y < 0 || point.y >= rect.size.height ) { + if (mouse->focus != 0) { + SDL_SetMouseFocus(index, 0); + } + } else { + if (mouse->focus != _data->windowID) { + SDL_SetMouseFocus(index, _data->windowID); + } + SDL_SendMouseMotion(index, 0, (int)point.x, (int)point.y); + } } - (void)mouseDragged:(NSEvent *)theEvent