Skip to content

Commit

Permalink
Fixed fullscreen mouse events on MacOS X
Browse files Browse the repository at this point in the history
Fixed crash when quitting fullscreen mode on MacOS X
  • Loading branch information
slouken committed Jul 22, 2001
1 parent 84c3933 commit 9c445e2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 39 deletions.
2 changes: 2 additions & 0 deletions docs.html
Expand Up @@ -16,6 +16,8 @@ <H2>
Major changes since SDL 1.0.0:
</H2>
<UL>
<LI> 1.2.2: Fixed crash when quitting fullscreen mode on MacOS X
<LI> 1.2.2: Fixed fullscreen mouse events on MacOS X
<LI> 1.2.2: Now returns an error if unable to open audio on BeOS
<LI> 1.2.2: Now gets correct keyboard state when starting up on X11
<LI> 1.2.2: Improved the DGA 2.0 and framebuffer console drivers
Expand Down
78 changes: 39 additions & 39 deletions src/video/quartz/SDL_QuartzEvents.m
Expand Up @@ -195,8 +195,8 @@ static void QZ_DoModifiers (unsigned int newMods) {
currentMods = newMods;
}

static void QZ_DoActivate (_THIS, NSPoint p) {
static void QZ_DoActivate (_THIS)
{
inForeground = YES;

/* Regrab the mouse */
Expand All @@ -220,13 +220,10 @@ static void QZ_DoDeactivate (_THIS) {
SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
}

static void QZ_PumpEvents (_THIS) {

static void QZ_PumpEvents (_THIS)
{
NSDate *distantPast = [ NSDate distantPast ];

//NSAutoreleasePool *pool;
//pool = [ [ NSAutoreleasePool alloc ] init ];

NSEvent *event;
NSRect winRect;
NSRect titleBarRect;
Expand All @@ -244,29 +241,28 @@ static void QZ_PumpEvents (_THIS) {

if (event != nil) {
unsigned int type;
NSPoint p;

type = [ event type ];
p = [ event locationInWindow ];

#define DO_MOUSE_DOWN(button, sendToWindow) \
if ( inForeground ) { \
if ( NSPointInRect(p,winRect)) \
SDL_PrivateMouseButton (SDL_PRESSED, button, p.x, SDL_VideoSurface->h - p.y); \
else if (sendToWindow) \
[ window sendEvent:event ]; \
} \
else { \
QZ_DoActivate (this, p); \

#define DO_MOUSE_DOWN(button, sendToWindow) \
if ( inForeground ) { \
if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) || \
NSPointInRect([event locationInWindow], winRect) ) \
SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \
else if (sendToWindow) \
[ window sendEvent:event ]; \
} \
else { \
QZ_DoActivate (this); \
}

#define DO_MOUSE_UP(button, sendToWindow) \
if ( ! NSPointInRect (p, titleBarRect) ) \
SDL_PrivateMouseButton (SDL_RELEASED, button, p.x, SDL_VideoSurface->h - p.y); \
if (sendToWindow) \
#define DO_MOUSE_UP(button, sendToWindow) \
if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) || \
!NSPointInRect([event locationInWindow], titleBarRect) )\
SDL_PrivateMouseButton (SDL_RELEASED, button, 0, 0); \
if (sendToWindow) \
[ window sendEvent:event ]

switch ( type) {
type = [ event type ];
switch (type) {

case NSLeftMouseDown:
if ( NSCommandKeyMask & currentMods ) {
Expand Down Expand Up @@ -302,33 +298,39 @@ static void QZ_PumpEvents (_THIS) {
case NSLeftMouseDragged:
case NSRightMouseDragged:
case 27:
SDL_PrivateMouseMotion (SDL_PRESSED, 0, p.x, SDL_VideoSurface->h - p.y);
break;
case NSMouseMoved:
{
static int moves = 0;

NSPoint p;

if ( SDL_VideoSurface->flags & SDL_FULLSCREEN ) {
p = [ NSEvent mouseLocation ];
p.y = [[NSScreen mainScreen] frame].size.height - p.y;
} else {
p = [ event locationInWindow ];
p.y = SDL_VideoSurface->h - p.y;
}

if ( (moves % 10) == 0 ) {
SDL_PrivateMouseMotion (SDL_RELEASED, 0, p.x, SDL_VideoSurface->h - p.y);
moves = 0;
SDL_PrivateMouseMotion (0, 0, p.x, p.y);
}
else {
CGMouseDelta dx, dy;
CGGetLastMouseDelta (&dx, &dy);
SDL_PrivateMouseMotion (SDL_RELEASED, 1, dx, dy);
moves++;
SDL_PrivateMouseMotion (0, 1, dx, dy);
}
moves++;
}
break;
case NSScrollWheel:
{
if (NSPointInRect(p, winRect)) {
if (NSPointInRect([ event locationInWindow ], winRect)) {
float dy;
dy = [ event deltaY ];
if ( dy > 0.0 ) /* Scroll up */
SDL_PrivateMouseButton (SDL_PRESSED, 4, p.x, SDL_VideoSurface->h - p.y);
SDL_PrivateMouseButton (SDL_PRESSED, 4, 0, 0);
else /* Scroll down */
SDL_PrivateMouseButton (SDL_PRESSED, 5, p.x, SDL_VideoSurface->h - p.y);
SDL_PrivateMouseButton (SDL_PRESSED, 5, 0, 0);
}
}
break;
Expand All @@ -346,7 +348,7 @@ static void QZ_PumpEvents (_THIS) {
case NSAppKitDefined:
switch ( [ event subtype ] ) {
case NSApplicationActivatedEventType:
QZ_DoActivate (this, p);
QZ_DoActivate (this);
break;
case NSApplicationDeactivatedEventType:
QZ_DoDeactivate (this);
Expand All @@ -361,8 +363,6 @@ static void QZ_PumpEvents (_THIS) {
case NSCursorUpdate: break;
}
}
// [ pool release ];

} while (event != nil);
}

1 change: 1 addition & 0 deletions src/video/quartz/SDL_QuartzVideo.m
Expand Up @@ -231,6 +231,7 @@ static void QZ_UnsetVideoMode (_THIS) {
if ( mode_flags & SDL_FULLSCREEN ) {
CGDisplaySwitchToMode (display_id, save_mode);
CGDisplayRelease (display_id);
this->screen->pixels = NULL;
}
/* Release window mode data structures */
else {
Expand Down

0 comments on commit 9c445e2

Please sign in to comment.