Fixed mouse events for fullscreen windows on Mac OS X
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404260
This commit is contained in:
parent
013a718a1f
commit
e12e0c04d3
6 changed files with 102 additions and 11 deletions
|
@ -171,6 +171,7 @@ struct SDL_VideoDisplay
|
||||||
|
|
||||||
int num_windows;
|
int num_windows;
|
||||||
SDL_Window *windows;
|
SDL_Window *windows;
|
||||||
|
SDL_Window *fullscreen_window;
|
||||||
|
|
||||||
SDL_Renderer *current_renderer;
|
SDL_Renderer *current_renderer;
|
||||||
|
|
||||||
|
|
|
@ -768,6 +768,7 @@ SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt)
|
||||||
SDL_DisplayMode fullscreen_mode;
|
SDL_DisplayMode fullscreen_mode;
|
||||||
if (SDL_GetWindowDisplayMode(window->id, &fullscreen_mode) == 0) {
|
if (SDL_GetWindowDisplayMode(window->id, &fullscreen_mode) == 0) {
|
||||||
SDL_SetDisplayModeForDisplay(display, &fullscreen_mode);
|
SDL_SetDisplayModeForDisplay(display, &fullscreen_mode);
|
||||||
|
display->fullscreen_window = window;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -775,6 +776,7 @@ SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt)
|
||||||
|
|
||||||
/* Nope, restore the desktop mode */
|
/* Nope, restore the desktop mode */
|
||||||
SDL_SetDisplayModeForDisplay(display, NULL);
|
SDL_SetDisplayModeForDisplay(display, NULL);
|
||||||
|
display->fullscreen_window = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -187,6 +187,20 @@ Cocoa_PumpEvents(_THIS)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch ([event type]) {
|
switch ([event type]) {
|
||||||
|
case NSLeftMouseDown:
|
||||||
|
case NSOtherMouseDown:
|
||||||
|
case NSRightMouseDown:
|
||||||
|
case NSLeftMouseUp:
|
||||||
|
case NSOtherMouseUp:
|
||||||
|
case NSRightMouseUp:
|
||||||
|
case NSLeftMouseDragged:
|
||||||
|
case NSRightMouseDragged:
|
||||||
|
case NSOtherMouseDragged: /* usually middle mouse dragged */
|
||||||
|
case NSMouseMoved:
|
||||||
|
Cocoa_HandleMouseEvent(_this, event);
|
||||||
|
/* Pass through to NSApp to make sure everything stays in sync */
|
||||||
|
[NSApp sendEvent:event];
|
||||||
|
break;
|
||||||
case NSKeyDown:
|
case NSKeyDown:
|
||||||
case NSKeyUp:
|
case NSKeyUp:
|
||||||
case NSFlagsChanged:
|
case NSFlagsChanged:
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#define _SDL_cocoamouse_h
|
#define _SDL_cocoamouse_h
|
||||||
|
|
||||||
extern void Cocoa_InitMouse(_THIS);
|
extern void Cocoa_InitMouse(_THIS);
|
||||||
|
extern void Cocoa_HandleMouseEvent(_THIS, NSEvent * event);
|
||||||
extern void Cocoa_QuitMouse(_THIS);
|
extern void Cocoa_QuitMouse(_THIS);
|
||||||
|
|
||||||
#endif /* _SDL_cocoamouse_h */
|
#endif /* _SDL_cocoamouse_h */
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
*/
|
*/
|
||||||
#include "SDL_config.h"
|
#include "SDL_config.h"
|
||||||
|
|
||||||
|
#include "SDL_events.h"
|
||||||
#include "SDL_cocoavideo.h"
|
#include "SDL_cocoavideo.h"
|
||||||
|
|
||||||
#include "../../events/SDL_mouse_c.h"
|
#include "../../events/SDL_mouse_c.h"
|
||||||
|
@ -35,6 +36,87 @@ Cocoa_InitMouse(_THIS)
|
||||||
data->mouse = SDL_AddMouse(&mouse, "Mouse", 0, 0, 1);
|
data->mouse = SDL_AddMouse(&mouse, "Mouse", 0, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
ConvertMouseButtonToSDL(int button)
|
||||||
|
{
|
||||||
|
switch (button)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return(SDL_BUTTON_LEFT); /* 1 */
|
||||||
|
case 1:
|
||||||
|
return(SDL_BUTTON_RIGHT); /* 3 */
|
||||||
|
case 2:
|
||||||
|
return(SDL_BUTTON_MIDDLE); /* 2 */
|
||||||
|
}
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
|
||||||
|
{
|
||||||
|
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
||||||
|
SDL_Mouse *mouse = SDL_GetMouse(data->mouse);
|
||||||
|
int i;
|
||||||
|
NSPoint point;
|
||||||
|
SDL_Window *window;
|
||||||
|
|
||||||
|
/* See if there are any fullscreen windows that might handle this event */
|
||||||
|
window = NULL;
|
||||||
|
for (i = 0; i < _this->num_displays; ++i) {
|
||||||
|
SDL_VideoDisplay *display = &_this->displays[i];
|
||||||
|
SDL_Window *candidate = display->fullscreen_window;
|
||||||
|
|
||||||
|
if (candidate) {
|
||||||
|
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
|
||||||
|
NSRect rect = CGDisplayBounds(displaydata->display);
|
||||||
|
|
||||||
|
point = [NSEvent mouseLocation];
|
||||||
|
point.x = point.x - rect.origin.x;
|
||||||
|
point.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - point.y - rect.origin.y;
|
||||||
|
if (point.x < 0 || point.x >= candidate->w ||
|
||||||
|
point.y < 0 || point.y >= candidate->h) {
|
||||||
|
/* The mouse is out of this fullscreen display */
|
||||||
|
if (mouse->focus == candidate->id) {
|
||||||
|
SDL_SetMouseFocus(data->mouse, 0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* This is it! */
|
||||||
|
window = candidate;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!window) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the focus appropriately */
|
||||||
|
if (mouse->focus != window->id) {
|
||||||
|
SDL_SetMouseFocus(data->mouse, window->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ([event type]) {
|
||||||
|
case NSLeftMouseDown:
|
||||||
|
case NSOtherMouseDown:
|
||||||
|
case NSRightMouseDown:
|
||||||
|
SDL_SendMouseButton(data->mouse, SDL_PRESSED, ConvertMouseButtonToSDL([event buttonNumber]));
|
||||||
|
break;
|
||||||
|
case NSLeftMouseUp:
|
||||||
|
case NSOtherMouseUp:
|
||||||
|
case NSRightMouseUp:
|
||||||
|
SDL_SendMouseButton(data->mouse, SDL_RELEASED, ConvertMouseButtonToSDL([event buttonNumber]));
|
||||||
|
break;
|
||||||
|
case NSLeftMouseDragged:
|
||||||
|
case NSRightMouseDragged:
|
||||||
|
case NSOtherMouseDragged: /* usually middle mouse dragged */
|
||||||
|
case NSMouseMoved:
|
||||||
|
SDL_SendMouseMotion(data->mouse, 0, (int)point.x, (int)point.y, 0);
|
||||||
|
break;
|
||||||
|
default: /* just to avoid compiler warnings */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Cocoa_QuitMouse(_THIS)
|
Cocoa_QuitMouse(_THIS)
|
||||||
{
|
{
|
||||||
|
|
|
@ -235,17 +235,8 @@ static __inline__ void ConvertNSRect(NSRect *r)
|
||||||
|
|
||||||
index = _data->videodata->mouse;
|
index = _data->videodata->mouse;
|
||||||
mouse = SDL_GetMouse(index);
|
mouse = SDL_GetMouse(index);
|
||||||
|
point = [theEvent locationInWindow];
|
||||||
point = [NSEvent mouseLocation];
|
point.y = window->h - point.y;
|
||||||
if ( (window->flags & SDL_WINDOW_FULLSCREEN) ) {
|
|
||||||
NSRect rect = CGDisplayBounds(_data->display);
|
|
||||||
|
|
||||||
point.x = point.x - rect.origin.x;
|
|
||||||
point.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - point.y - rect.origin.y;
|
|
||||||
} else {
|
|
||||||
point.x = point.x - window->x;
|
|
||||||
point.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - point.y - window->y;
|
|
||||||
}
|
|
||||||
if ( point.x < 0 || point.x >= window->w ||
|
if ( point.x < 0 || point.x >= window->w ||
|
||||||
point.y < 0 || point.y >= window->h ) {
|
point.y < 0 || point.y >= window->h ) {
|
||||||
if (mouse->focus != 0) {
|
if (mouse->focus != 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue