Commit 320eb460 authored by Sam Lantinga's avatar Sam Lantinga

Cleaned up the mouse window focus handling: you always pass in the relative...

Cleaned up the mouse window focus handling: you always pass in the relative window when sending a mouse event.
Fixed a bug where only mouse wheel up was sent on Mac OS X
Fixed a bug where mouse window focus was getting hosed by the fullscreen mouse code on Mac OS X
parent 8cafde92
...@@ -112,7 +112,7 @@ SDL_SetMouseFocus(SDL_Window * window) ...@@ -112,7 +112,7 @@ SDL_SetMouseFocus(SDL_Window * window)
} }
int int
SDL_SendMouseMotion(int relative, int x, int y) SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y)
{ {
SDL_Mouse *mouse = &SDL_mouse; SDL_Mouse *mouse = &SDL_mouse;
int posted; int posted;
...@@ -120,6 +120,10 @@ SDL_SendMouseMotion(int relative, int x, int y) ...@@ -120,6 +120,10 @@ SDL_SendMouseMotion(int relative, int x, int y)
int yrel; int yrel;
int x_max = 0, y_max = 0; int x_max = 0, y_max = 0;
if (window) {
SDL_SetMouseFocus(window);
}
/* the relative motion is calculated regarding the system cursor last position */ /* the relative motion is calculated regarding the system cursor last position */
if (relative) { if (relative) {
xrel = x; xrel = x;
...@@ -194,12 +198,16 @@ SDL_SendMouseMotion(int relative, int x, int y) ...@@ -194,12 +198,16 @@ SDL_SendMouseMotion(int relative, int x, int y)
} }
int int
SDL_SendMouseButton(Uint8 state, Uint8 button) SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button)
{ {
SDL_Mouse *mouse = &SDL_mouse; SDL_Mouse *mouse = &SDL_mouse;
int posted; int posted;
Uint32 type; Uint32 type;
if (window) {
SDL_SetMouseFocus(window);
}
/* Figure out which event to perform */ /* Figure out which event to perform */
switch (state) { switch (state) {
case SDL_PRESSED: case SDL_PRESSED:
...@@ -239,11 +247,15 @@ SDL_SendMouseButton(Uint8 state, Uint8 button) ...@@ -239,11 +247,15 @@ SDL_SendMouseButton(Uint8 state, Uint8 button)
} }
int int
SDL_SendMouseWheel(int x, int y) SDL_SendMouseWheel(SDL_Window * window, int x, int y)
{ {
SDL_Mouse *mouse = &SDL_mouse; SDL_Mouse *mouse = &SDL_mouse;
int posted; int posted;
if (window) {
SDL_SetMouseFocus(window);
}
if (!x && !y) { if (!x && !y) {
return 0; return 0;
} }
...@@ -304,8 +316,7 @@ SDL_WarpMouseInWindow(SDL_Window * window, int x, int y) ...@@ -304,8 +316,7 @@ SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
if (mouse->WarpMouse) { if (mouse->WarpMouse) {
mouse->WarpMouse(mouse, window, x, y); mouse->WarpMouse(mouse, window, x, y);
} else { } else {
SDL_SetMouseFocus(window); SDL_SendMouseMotion(window, 0, x, y);
SDL_SendMouseMotion(0, x, y);
} }
} }
......
...@@ -40,13 +40,13 @@ extern void SDL_ResetMouse(void); ...@@ -40,13 +40,13 @@ extern void SDL_ResetMouse(void);
extern void SDL_SetMouseFocus(SDL_Window * window); extern void SDL_SetMouseFocus(SDL_Window * window);
/* Send a mouse motion event */ /* Send a mouse motion event */
extern int SDL_SendMouseMotion(int relative, int x, int y); extern int SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y);
/* Send a mouse button event */ /* Send a mouse button event */
extern int SDL_SendMouseButton(Uint8 state, Uint8 button); extern int SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button);
/* Send a mouse wheel event */ /* Send a mouse wheel event */
extern int SDL_SendMouseWheel(int x, int y); extern int SDL_SendMouseWheel(SDL_Window * window, int x, int y);
/* Shutdown the mouse subsystem */ /* Shutdown the mouse subsystem */
extern void SDL_MouseQuit(void); extern void SDL_MouseQuit(void);
......
...@@ -52,6 +52,7 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event) ...@@ -52,6 +52,7 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
int i; int i;
NSPoint point = { 0, 0 }; NSPoint point = { 0, 0 };
SDL_Window *window; SDL_Window *window;
SDL_Window *focus = SDL_GetMouseFocus();
/* See if there are any fullscreen windows that might handle this event */ /* See if there are any fullscreen windows that might handle this event */
window = NULL; window = NULL;
...@@ -66,19 +67,18 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event) ...@@ -66,19 +67,18 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
point = [NSEvent mouseLocation]; point = [NSEvent mouseLocation];
point.x = point.x - bounds.x; point.x = point.x - bounds.x;
point.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - point.y - bounds.y; 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)) { (point.y >= 0 && point.y < candidate->h)) {
/* This is it! */ /* This is it! */
window = candidate; window = candidate;
break; break;
} else if (candidate == focus) {
SDL_SetMouseFocus(NULL);
} }
} }
} }
/* Set the focus appropriately */ if (!window) {
SDL_SetMouseFocus(window);
if (window) {
return; return;
} }
...@@ -86,18 +86,18 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event) ...@@ -86,18 +86,18 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
case NSLeftMouseDown: case NSLeftMouseDown:
case NSOtherMouseDown: case NSOtherMouseDown:
case NSRightMouseDown: case NSRightMouseDown:
SDL_SendMouseButton(SDL_PRESSED, ConvertMouseButtonToSDL([event buttonNumber])); SDL_SendMouseButton(window, SDL_PRESSED, ConvertMouseButtonToSDL([event buttonNumber]));
break; break;
case NSLeftMouseUp: case NSLeftMouseUp:
case NSOtherMouseUp: case NSOtherMouseUp:
case NSRightMouseUp: case NSRightMouseUp:
SDL_SendMouseButton(SDL_RELEASED, ConvertMouseButtonToSDL([event buttonNumber])); SDL_SendMouseButton(window, SDL_RELEASED, ConvertMouseButtonToSDL([event buttonNumber]));
break; break;
case NSLeftMouseDragged: case NSLeftMouseDragged:
case NSRightMouseDragged: case NSRightMouseDragged:
case NSOtherMouseDragged: /* usually middle mouse dragged */ case NSOtherMouseDragged: /* usually middle mouse dragged */
case NSMouseMoved: case NSMouseMoved:
SDL_SendMouseMotion(0, (int)point.x, (int)point.y); SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
break; break;
default: /* just to avoid compiler warnings */ default: /* just to avoid compiler warnings */
break; break;
......
...@@ -171,7 +171,7 @@ static __inline__ void ConvertNSRect(NSRect *r) ...@@ -171,7 +171,7 @@ static __inline__ void ConvertNSRect(NSRect *r)
button = [theEvent buttonNumber]; button = [theEvent buttonNumber];
break; break;
} }
SDL_SendMouseButton(SDL_PRESSED, button); SDL_SendMouseButton(_data->window, SDL_PRESSED, button);
} }
- (void)rightMouseDown:(NSEvent *)theEvent - (void)rightMouseDown:(NSEvent *)theEvent
...@@ -202,7 +202,7 @@ static __inline__ void ConvertNSRect(NSRect *r) ...@@ -202,7 +202,7 @@ static __inline__ void ConvertNSRect(NSRect *r)
button = [theEvent buttonNumber]; button = [theEvent buttonNumber];
break; break;
} }
SDL_SendMouseButton(SDL_RELEASED, button); SDL_SendMouseButton(_data->window, SDL_RELEASED, button);
} }
- (void)rightMouseUp:(NSEvent *)theEvent - (void)rightMouseUp:(NSEvent *)theEvent
...@@ -228,8 +228,7 @@ static __inline__ void ConvertNSRect(NSRect *r) ...@@ -228,8 +228,7 @@ static __inline__ void ConvertNSRect(NSRect *r)
SDL_SetMouseFocus(NULL); SDL_SetMouseFocus(NULL);
} }
} else { } else {
SDL_SetMouseFocus(_data->window); SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
SDL_SendMouseMotion(0, (int)point.x, (int)point.y);
} }
} }
...@@ -250,7 +249,20 @@ static __inline__ void ConvertNSRect(NSRect *r) ...@@ -250,7 +249,20 @@ static __inline__ void ConvertNSRect(NSRect *r)
- (void)scrollWheel:(NSEvent *)theEvent - (void)scrollWheel:(NSEvent *)theEvent
{ {
SDL_SendMouseWheel((int)([theEvent deltaX]+0.9f), (int)([theEvent deltaY]+0.9f)); float x = [theEvent deltaX];
float y = [theEvent deltaY];
if (x > 0) {
x += 0.9f;
} else if (x < 0) {
x -= 0.9f;
}
if (y > 0) {
y += 0.9f;
} else if (y < 0) {
y -= 0.9f;
}
SDL_SendMouseWheel(_data->window, (int)x, (int)y);
} }
@end @end
......
...@@ -177,18 +177,15 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) ...@@ -177,18 +177,15 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
break; break;
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
SDL_SetMouseFocus(data->window); SDL_SendMouseMotion(data->window, 0, LOWORD(lParam), HIWORD(lParam));
SDL_SendMouseMotion(0, LOWORD(lParam), HIWORD(lParam));
break; break;
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
SDL_SetMouseFocus(data->window); SDL_SendMouseButton(data->window, SDL_PRESSED, SDL_BUTTON_LEFT);
SDL_SendMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT);
break; break;
case WM_LBUTTONUP: case WM_LBUTTONUP:
SDL_SetMouseFocus(data->window); SDL_SendMouseButton(data->window, SDL_RELEASED, SDL_BUTTON_LEFT);
SDL_SendMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT);
break; break;
case WM_MOUSELEAVE: case WM_MOUSELEAVE:
......
...@@ -272,17 +272,17 @@ X11_DispatchEvent(_THIS) ...@@ -272,17 +272,17 @@ X11_DispatchEvent(_THIS)
#ifdef DEBUG_MOTION #ifdef DEBUG_MOTION
printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y); printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
#endif #endif
SDL_SendMouseMotion(0, xevent.xmotion.x, xevent.xmotion.y); SDL_SendMouseMotion(data->window, 0, xevent.xmotion.x, xevent.xmotion.y);
} }
break; break;
case ButtonPress:{ case ButtonPress:{
SDL_SendMouseButton(SDL_PRESSED, xevent.xbutton.button); SDL_SendMouseButton(data->window, SDL_PRESSED, xevent.xbutton.button);
} }
break; break;
case ButtonRelease:{ case ButtonRelease:{
SDL_SendMouseButton(SDL_RELEASED, xevent.xbutton.button); SDL_SendMouseButton(data->window, SDL_RELEASED, xevent.xbutton.button);
} }
break; break;
......
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