Navigation Menu

Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed mouse enter/leave events for a single window.
Browse files Browse the repository at this point in the history
You lose mouse focus in Cocoa when the window is no longer key.
  • Loading branch information
slouken committed Oct 28, 2006
1 parent e6007db commit 7a9dd46
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -129,14 +129,24 @@ - (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);
}

- (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);
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7a9dd46

Please sign in to comment.