Fixed fullscreen mouse events on MacOS X
authorSam Lantinga <slouken@libsdl.org>
Sun, 22 Jul 2001 20:57:24 +0000
changeset 117 aac75d5f7869
parent 116 e811db89bfbe
child 118 7c47e511459d
Fixed fullscreen mouse events on MacOS X Fixed crash when quitting fullscreen mode on MacOS X
docs.html
src/video/quartz/SDL_QuartzEvents.m
src/video/quartz/SDL_QuartzVideo.m
--- a/docs.html	Sat Jul 21 18:40:28 2001 +0000
+++ b/docs.html	Sun Jul 22 20:57:24 2001 +0000
@@ -16,6 +16,8 @@
 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
--- a/src/video/quartz/SDL_QuartzEvents.m	Sat Jul 21 18:40:28 2001 +0000
+++ b/src/video/quartz/SDL_QuartzEvents.m	Sun Jul 22 20:57:24 2001 +0000
@@ -195,8 +195,8 @@
     currentMods = newMods;
 }
 
-static void QZ_DoActivate (_THIS, NSPoint p) {
-    
+static void QZ_DoActivate (_THIS)
+{
     inForeground = YES;
 
     /* Regrab the mouse */
@@ -220,13 +220,10 @@
     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;
@@ -244,29 +241,28 @@
     
         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 ) {
@@ -302,33 +298,39 @@
             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;
@@ -346,7 +348,7 @@
             case NSAppKitDefined:
                 switch ( [ event subtype ] ) {
                 case NSApplicationActivatedEventType:
-                    QZ_DoActivate (this, p);
+                    QZ_DoActivate (this);
                     break;
                 case NSApplicationDeactivatedEventType:
                     QZ_DoDeactivate (this);
@@ -361,8 +363,6 @@
             case NSCursorUpdate: break;
             }
         }
-       // [ pool release ];
-
       } while (event != nil);
 }
 
--- a/src/video/quartz/SDL_QuartzVideo.m	Sat Jul 21 18:40:28 2001 +0000
+++ b/src/video/quartz/SDL_QuartzVideo.m	Sun Jul 22 20:57:24 2001 +0000
@@ -231,6 +231,7 @@
     if ( mode_flags & SDL_FULLSCREEN ) {
         CGDisplaySwitchToMode (display_id, save_mode);
         CGDisplayRelease (display_id);
+        this->screen->pixels = NULL;
     }
     /* Release window mode data structures */
     else {