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
This commit is contained in:
parent
8cafde92ae
commit
320eb4600b
6 changed files with 50 additions and 30 deletions
|
@ -112,7 +112,7 @@ SDL_SetMouseFocus(SDL_Window * window)
|
|||
}
|
||||
|
||||
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;
|
||||
int posted;
|
||||
|
@ -120,6 +120,10 @@ SDL_SendMouseMotion(int relative, int x, int y)
|
|||
int yrel;
|
||||
int x_max = 0, y_max = 0;
|
||||
|
||||
if (window) {
|
||||
SDL_SetMouseFocus(window);
|
||||
}
|
||||
|
||||
/* the relative motion is calculated regarding the system cursor last position */
|
||||
if (relative) {
|
||||
xrel = x;
|
||||
|
@ -194,12 +198,16 @@ SDL_SendMouseMotion(int relative, int x, int y)
|
|||
}
|
||||
|
||||
int
|
||||
SDL_SendMouseButton(Uint8 state, Uint8 button)
|
||||
SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button)
|
||||
{
|
||||
SDL_Mouse *mouse = &SDL_mouse;
|
||||
int posted;
|
||||
Uint32 type;
|
||||
|
||||
if (window) {
|
||||
SDL_SetMouseFocus(window);
|
||||
}
|
||||
|
||||
/* Figure out which event to perform */
|
||||
switch (state) {
|
||||
case SDL_PRESSED:
|
||||
|
@ -239,11 +247,15 @@ SDL_SendMouseButton(Uint8 state, Uint8 button)
|
|||
}
|
||||
|
||||
int
|
||||
SDL_SendMouseWheel(int x, int y)
|
||||
SDL_SendMouseWheel(SDL_Window * window, int x, int y)
|
||||
{
|
||||
SDL_Mouse *mouse = &SDL_mouse;
|
||||
int posted;
|
||||
|
||||
if (window) {
|
||||
SDL_SetMouseFocus(window);
|
||||
}
|
||||
|
||||
if (!x && !y) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -304,8 +316,7 @@ SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
|
|||
if (mouse->WarpMouse) {
|
||||
mouse->WarpMouse(mouse, window, x, y);
|
||||
} else {
|
||||
SDL_SetMouseFocus(window);
|
||||
SDL_SendMouseMotion(0, x, y);
|
||||
SDL_SendMouseMotion(window, 0, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,13 +40,13 @@ extern void SDL_ResetMouse(void);
|
|||
extern void SDL_SetMouseFocus(SDL_Window * window);
|
||||
|
||||
/* 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 */
|
||||
extern int SDL_SendMouseButton(Uint8 state, Uint8 button);
|
||||
extern int SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button);
|
||||
|
||||
/* 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 */
|
||||
extern void SDL_MouseQuit(void);
|
||||
|
|
|
@ -52,6 +52,7 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
|
|||
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 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
|
|||
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 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
|
|||
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;
|
||||
|
|
|
@ -171,7 +171,7 @@ static __inline__ void ConvertNSRect(NSRect *r)
|
|||
button = [theEvent buttonNumber];
|
||||
break;
|
||||
}
|
||||
SDL_SendMouseButton(SDL_PRESSED, button);
|
||||
SDL_SendMouseButton(_data->window, SDL_PRESSED, button);
|
||||
}
|
||||
|
||||
- (void)rightMouseDown:(NSEvent *)theEvent
|
||||
|
@ -202,7 +202,7 @@ static __inline__ void ConvertNSRect(NSRect *r)
|
|||
button = [theEvent buttonNumber];
|
||||
break;
|
||||
}
|
||||
SDL_SendMouseButton(SDL_RELEASED, button);
|
||||
SDL_SendMouseButton(_data->window, SDL_RELEASED, button);
|
||||
}
|
||||
|
||||
- (void)rightMouseUp:(NSEvent *)theEvent
|
||||
|
@ -228,8 +228,7 @@ static __inline__ void ConvertNSRect(NSRect *r)
|
|||
SDL_SetMouseFocus(NULL);
|
||||
}
|
||||
} else {
|
||||
SDL_SetMouseFocus(_data->window);
|
||||
SDL_SendMouseMotion(0, (int)point.x, (int)point.y);
|
||||
SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -250,7 +249,20 @@ static __inline__ void ConvertNSRect(NSRect *r)
|
|||
|
||||
- (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
|
||||
|
|
|
@ -177,18 +177,15 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
break;
|
||||
|
||||
case WM_MOUSEMOVE:
|
||||
SDL_SetMouseFocus(data->window);
|
||||
SDL_SendMouseMotion(0, LOWORD(lParam), HIWORD(lParam));
|
||||
SDL_SendMouseMotion(data->window, 0, LOWORD(lParam), HIWORD(lParam));
|
||||
break;
|
||||
|
||||
case WM_LBUTTONDOWN:
|
||||
SDL_SetMouseFocus(data->window);
|
||||
SDL_SendMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT);
|
||||
SDL_SendMouseButton(data->window, SDL_PRESSED, SDL_BUTTON_LEFT);
|
||||
break;
|
||||
|
||||
case WM_LBUTTONUP:
|
||||
SDL_SetMouseFocus(data->window);
|
||||
SDL_SendMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT);
|
||||
SDL_SendMouseButton(data->window, SDL_RELEASED, SDL_BUTTON_LEFT);
|
||||
break;
|
||||
|
||||
case WM_MOUSELEAVE:
|
||||
|
|
|
@ -272,17 +272,17 @@ X11_DispatchEvent(_THIS)
|
|||
#ifdef DEBUG_MOTION
|
||||
printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
|
||||
#endif
|
||||
SDL_SendMouseMotion(0, xevent.xmotion.x, xevent.xmotion.y);
|
||||
SDL_SendMouseMotion(data->window, 0, xevent.xmotion.x, xevent.xmotion.y);
|
||||
}
|
||||
break;
|
||||
|
||||
case ButtonPress:{
|
||||
SDL_SendMouseButton(SDL_PRESSED, xevent.xbutton.button);
|
||||
SDL_SendMouseButton(data->window, SDL_PRESSED, xevent.xbutton.button);
|
||||
}
|
||||
break;
|
||||
|
||||
case ButtonRelease:{
|
||||
SDL_SendMouseButton(SDL_RELEASED, xevent.xbutton.button);
|
||||
SDL_SendMouseButton(data->window, SDL_RELEASED, xevent.xbutton.button);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue