Fixed fullscreen mouse events on MacOS X
authorSam Lantinga <slouken@libsdl.org>
Sun, 22 Jul 2001 20:57:24 +0000
changeset 117aac75d5f7869
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
     1.1 --- a/docs.html	Sat Jul 21 18:40:28 2001 +0000
     1.2 +++ b/docs.html	Sun Jul 22 20:57:24 2001 +0000
     1.3 @@ -16,6 +16,8 @@
     1.4  Major changes since SDL 1.0.0:
     1.5  </H2>
     1.6  <UL>
     1.7 +	<LI> 1.2.2: Fixed crash when quitting fullscreen mode on MacOS X
     1.8 +	<LI> 1.2.2: Fixed fullscreen mouse events on MacOS X
     1.9  	<LI> 1.2.2: Now returns an error if unable to open audio on BeOS
    1.10  	<LI> 1.2.2: Now gets correct keyboard state when starting up on X11
    1.11  	<LI> 1.2.2: Improved the DGA 2.0 and framebuffer console drivers
     2.1 --- a/src/video/quartz/SDL_QuartzEvents.m	Sat Jul 21 18:40:28 2001 +0000
     2.2 +++ b/src/video/quartz/SDL_QuartzEvents.m	Sun Jul 22 20:57:24 2001 +0000
     2.3 @@ -195,8 +195,8 @@
     2.4      currentMods = newMods;
     2.5  }
     2.6  
     2.7 -static void QZ_DoActivate (_THIS, NSPoint p) {
     2.8 -    
     2.9 +static void QZ_DoActivate (_THIS)
    2.10 +{
    2.11      inForeground = YES;
    2.12  
    2.13      /* Regrab the mouse */
    2.14 @@ -220,13 +220,10 @@
    2.15      SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
    2.16  }
    2.17  
    2.18 -static void QZ_PumpEvents (_THIS) { 
    2.19 -
    2.20 +static void QZ_PumpEvents (_THIS)
    2.21 +{ 
    2.22      NSDate *distantPast = [ NSDate distantPast ];
    2.23      
    2.24 -    //NSAutoreleasePool *pool;
    2.25 -    //pool = [ [ NSAutoreleasePool alloc ] init ];
    2.26 -    
    2.27      NSEvent *event;
    2.28      NSRect winRect;
    2.29      NSRect titleBarRect;
    2.30 @@ -244,29 +241,28 @@
    2.31      
    2.32          if (event != nil) {
    2.33              unsigned int type;
    2.34 -            NSPoint p;
    2.35 -            
    2.36 -            type = [ event type ];
    2.37 -            p = [ event locationInWindow ];
    2.38 -            
    2.39 -            #define DO_MOUSE_DOWN(button, sendToWindow)                                                \
    2.40 -                if ( inForeground ) {                                                                  \
    2.41 -                    if ( NSPointInRect(p,winRect))                                                     \
    2.42 -                        SDL_PrivateMouseButton (SDL_PRESSED, button, p.x, SDL_VideoSurface->h - p.y);  \
    2.43 -                    else if (sendToWindow)                                                             \
    2.44 -                            [ window sendEvent:event ];                                                   \
    2.45 -                }                                                                                      \
    2.46 -                else {                                                                                 \
    2.47 -                    QZ_DoActivate (this, p);                                                           \
    2.48 +
    2.49 +            #define DO_MOUSE_DOWN(button, sendToWindow)                      \
    2.50 +                if ( inForeground ) {                                        \
    2.51 +                    if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) ||       \
    2.52 +                         NSPointInRect([event locationInWindow], winRect) )  \
    2.53 +                        SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0);  \
    2.54 +                    else if (sendToWindow)                                   \
    2.55 +                            [ window sendEvent:event ];                      \
    2.56 +                }                                                            \
    2.57 +                else {                                                       \
    2.58 +                    QZ_DoActivate (this);                                    \
    2.59                  }       
    2.60              
    2.61 -            #define DO_MOUSE_UP(button, sendToWindow)                                          \
    2.62 -                if ( ! NSPointInRect (p, titleBarRect) ) \
    2.63 -                    SDL_PrivateMouseButton (SDL_RELEASED, button, p.x, SDL_VideoSurface->h - p.y); \
    2.64 -                if (sendToWindow)                                                              \
    2.65 +            #define DO_MOUSE_UP(button, sendToWindow)                        \
    2.66 +                if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) ||           \
    2.67 +                     !NSPointInRect([event locationInWindow], titleBarRect) )\
    2.68 +                    SDL_PrivateMouseButton (SDL_RELEASED, button, 0, 0);     \
    2.69 +                if (sendToWindow)                                            \
    2.70                      [ window sendEvent:event ]
    2.71                      
    2.72 -            switch ( type) {
    2.73 +            type = [ event type ];
    2.74 +            switch (type) {
    2.75              
    2.76              case NSLeftMouseDown:  
    2.77                  if ( NSCommandKeyMask & currentMods ) {
    2.78 @@ -302,33 +298,39 @@
    2.79              case NSLeftMouseDragged:
    2.80              case NSRightMouseDragged:
    2.81              case 27:
    2.82 -                SDL_PrivateMouseMotion (SDL_PRESSED, 0, p.x, SDL_VideoSurface->h - p.y);
    2.83 -                break;
    2.84              case NSMouseMoved:
    2.85                  {
    2.86                     static int moves = 0;
    2.87 -                    
    2.88 +                   NSPoint p;
    2.89 +            
    2.90 +                   if ( SDL_VideoSurface->flags & SDL_FULLSCREEN ) {
    2.91 +                       p = [ NSEvent mouseLocation ];
    2.92 +                       p.y = [[NSScreen mainScreen] frame].size.height - p.y;
    2.93 +                   } else {
    2.94 +            	       p = [ event locationInWindow ];
    2.95 +                       p.y = SDL_VideoSurface->h - p.y;
    2.96 +                   }
    2.97 +
    2.98                     if ( (moves % 10) == 0 ) {
    2.99 -                        SDL_PrivateMouseMotion (SDL_RELEASED, 0, p.x, SDL_VideoSurface->h - p.y);
   2.100 -                        moves = 0;
   2.101 +                        SDL_PrivateMouseMotion (0, 0, p.x, p.y);
   2.102                     }
   2.103                     else {
   2.104                          CGMouseDelta dx, dy;
   2.105                          CGGetLastMouseDelta (&dx, &dy);
   2.106 -                        SDL_PrivateMouseMotion (SDL_RELEASED, 1, dx, dy);
   2.107 -                        moves++;
   2.108 +                        SDL_PrivateMouseMotion (0, 1, dx, dy);
   2.109                     }
   2.110 +                   moves++;
   2.111                  }
   2.112                  break;
   2.113              case NSScrollWheel:
   2.114                  {
   2.115 -                    if (NSPointInRect(p, winRect)) {
   2.116 +                    if (NSPointInRect([ event locationInWindow ], winRect)) {
   2.117                          float dy;
   2.118                          dy = [ event deltaY ];
   2.119                          if ( dy > 0.0 ) /* Scroll up */
   2.120 -                            SDL_PrivateMouseButton (SDL_PRESSED, 4, p.x, SDL_VideoSurface->h - p.y);
   2.121 +                            SDL_PrivateMouseButton (SDL_PRESSED, 4, 0, 0);
   2.122                          else /* Scroll down */
   2.123 -                            SDL_PrivateMouseButton (SDL_PRESSED, 5, p.x, SDL_VideoSurface->h - p.y);
   2.124 +                            SDL_PrivateMouseButton (SDL_PRESSED, 5, 0, 0);
   2.125                      }
   2.126                  }
   2.127                  break;
   2.128 @@ -346,7 +348,7 @@
   2.129              case NSAppKitDefined:
   2.130                  switch ( [ event subtype ] ) {
   2.131                  case NSApplicationActivatedEventType:
   2.132 -                    QZ_DoActivate (this, p);
   2.133 +                    QZ_DoActivate (this);
   2.134                      break;
   2.135                  case NSApplicationDeactivatedEventType:
   2.136                      QZ_DoDeactivate (this);
   2.137 @@ -361,8 +363,6 @@
   2.138              case NSCursorUpdate: break;
   2.139              }
   2.140          }
   2.141 -       // [ pool release ];
   2.142 -
   2.143        } while (event != nil);
   2.144  }
   2.145  
     3.1 --- a/src/video/quartz/SDL_QuartzVideo.m	Sat Jul 21 18:40:28 2001 +0000
     3.2 +++ b/src/video/quartz/SDL_QuartzVideo.m	Sun Jul 22 20:57:24 2001 +0000
     3.3 @@ -231,6 +231,7 @@
     3.4      if ( mode_flags & SDL_FULLSCREEN ) {
     3.5          CGDisplaySwitchToMode (display_id, save_mode);
     3.6          CGDisplayRelease (display_id);
     3.7 +        this->screen->pixels = NULL;
     3.8      }
     3.9      /* Release window mode data structures */
    3.10      else {