Commit 3d24370c authored by Sam Lantinga's avatar Sam Lantinga

Fixed mouse enter/leave events for a single window.

You lose mouse focus in Cocoa when the window is no longer key.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402207
parent fa0d6bd0
...@@ -129,6 +129,7 @@ static __inline__ void ConvertNSRect(NSRect *r) ...@@ -129,6 +129,7 @@ static __inline__ void ConvertNSRect(NSRect *r)
{ {
int index; int index;
/* We're going to get keyboard events, since we're key. */
index = _data->videodata->keyboard; index = _data->videodata->keyboard;
SDL_SetKeyboardFocus(index, _data->windowID); SDL_SetKeyboardFocus(index, _data->windowID);
} }
...@@ -136,7 +137,16 @@ static __inline__ void ConvertNSRect(NSRect *r) ...@@ -136,7 +137,16 @@ static __inline__ void ConvertNSRect(NSRect *r)
- (void)windowDidResignKey:(NSNotification *)aNotification - (void)windowDidResignKey:(NSNotification *)aNotification
{ {
int index; 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; index = _data->videodata->keyboard;
SDL_SetKeyboardFocus(index, 0); SDL_SetKeyboardFocus(index, 0);
} }
...@@ -227,14 +237,21 @@ static __inline__ void ConvertNSRect(NSRect *r) ...@@ -227,14 +237,21 @@ static __inline__ void ConvertNSRect(NSRect *r)
index = _data->videodata->mouse; index = _data->videodata->mouse;
mouse = SDL_GetMouse(index); mouse = SDL_GetMouse(index);
if (mouse->focus != _data->windowID) {
SDL_SetMouseFocus(index, _data->windowID);
}
point = [NSEvent mouseLocation]; point = [NSEvent mouseLocation];
point.x = point.x - rect.origin.x; point.x = point.x - rect.origin.x;
point.y = rect.size.height - (point.y - rect.origin.y); 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 - (void)mouseDragged:(NSEvent *)theEvent
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment