src/video/quartz/SDL_QuartzEvents.m
changeset 779 68c8da837fc0
parent 761 c5b2b6d2d1fe
child 782 dbc5905402b0
equal deleted inserted replaced
778:8ac3f46f9d09 779:68c8da837fc0
   314         
   314         
   315         /* Restore cursor location if input was grabbed */
   315         /* Restore cursor location if input was grabbed */
   316         QZ_PrivateWarpCursor (this, cursor_loc.x, cursor_loc.y);
   316         QZ_PrivateWarpCursor (this, cursor_loc.x, cursor_loc.y);
   317         QZ_ChangeGrabState (this, QZ_ENABLE_GRAB);
   317         QZ_ChangeGrabState (this, QZ_ENABLE_GRAB);
   318     }
   318     }
   319 
       
   320     SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS);
       
   321 }
   319 }
   322 
   320 
   323 static void QZ_DoDeactivate (_THIS) {
   321 static void QZ_DoDeactivate (_THIS) {
   324 
   322 
   325     /* Get the current cursor location, for restore on activate */
   323     /* Get the current cursor location, for restore on activate */
   332     CGAssociateMouseAndMouseCursorPosition (1);
   330     CGAssociateMouseAndMouseCursorPosition (1);
   333 
   331 
   334     /* Show the cursor if it was hidden by SDL_ShowCursor() */
   332     /* Show the cursor if it was hidden by SDL_ShowCursor() */
   335     if (!cursor_should_be_visible)
   333     if (!cursor_should_be_visible)
   336         QZ_ShowMouse (this);
   334         QZ_ShowMouse (this);
   337 
       
   338     SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
       
   339 }
   335 }
   340 
   336 
   341 void QZ_SleepNotificationHandler (void * refcon,
   337 void QZ_SleepNotificationHandler (void * refcon,
   342                                   io_service_t service,
   338                                   io_service_t service,
   343                                   natural_t messageType,
   339                                   natural_t messageType,
   460                             [ NSApp sendEvent:event ];                                  \
   456                             [ NSApp sendEvent:event ];                                  \
   461             } while(0)
   457             } while(0)
   462             
   458             
   463             type = [ event type ];
   459             type = [ event type ];
   464             isForGameWin = (qz_window == [ event window ]);
   460             isForGameWin = (qz_window == [ event window ]);
   465             isInGameWin = (mode_flags & SDL_FULLSCREEN) ? true : NSPointInRect([event locationInWindow], [ window_view frame ]);
   461             isInGameWin = QZ_IsMouseInWindow (this);
   466             switch (type) {
   462             switch (type) {
   467                 case NSLeftMouseDown:
   463                 case NSLeftMouseDown:
   468                     if ( getenv("SDL_HAS3BUTTONMOUSE") ) {
   464                     if ( getenv("SDL_HAS3BUTTONMOUSE") ) {
   469                         DO_MOUSE_DOWN (SDL_BUTTON_LEFT);
   465                         DO_MOUSE_DOWN (SDL_BUTTON_LEFT);
   470                     } else {
   466                     } else {
   536                             use absolute coordinates, this serves to
   532                             use absolute coordinates, this serves to
   537                             compensate any inaccuracy in deltas, and
   533                             compensate any inaccuracy in deltas, and
   538                             provides the first known mouse position,
   534                             provides the first known mouse position,
   539                             since everything after this uses deltas
   535                             since everything after this uses deltas
   540                         */
   536                         */
   541                         NSPoint p = [ event locationInWindow ];
   537                         NSPoint p = [ qz_window mouseLocationOutsideOfEventStream ];
   542                         QZ_PrivateCocoaToSDL (this, &p);
   538                         QZ_PrivateCocoaToSDL (this, &p);
   543                         SDL_PrivateMouseMotion (0, 0, p.x, p.y);
   539                         SDL_PrivateMouseMotion (0, 0, p.x, p.y);
   544                         firstMouseEvent = 0;
   540                         firstMouseEvent = 0;
   545                     }
   541                     }
   546                     else {
   542                     else {
   559                         but not as a result of the warp (so it's in the right direction).
   555                         but not as a result of the warp (so it's in the right direction).
   560                     */
   556                     */
   561                     if ( grab_state == QZ_VISIBLE_GRAB &&
   557                     if ( grab_state == QZ_VISIBLE_GRAB &&
   562                          !isInGameWin ) {
   558                          !isInGameWin ) {
   563                        
   559                        
   564                         NSPoint p = [ event locationInWindow ]; 
   560                         NSPoint p = [ qz_window mouseLocationOutsideOfEventStream ]; 
   565                         QZ_PrivateCocoaToSDL (this, &p);
   561                         QZ_PrivateCocoaToSDL (this, &p);
   566 
   562 
   567                         if ( p.x < 0.0 ) 
   563                         if ( p.x < 0.0 ) 
   568                             p.x = 0.0;
   564                             p.x = 0.0;
   569                         
   565                         
   580                     }
   576                     }
   581                     else
   577                     else
   582                     if ( !isInGameWin && (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
   578                     if ( !isInGameWin && (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
   583                     
   579                     
   584                         SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS);
   580                         SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS);
       
   581                         if (!cursor_should_be_visible)
       
   582                             QZ_ShowMouse (this);
   585                     }
   583                     }
   586                     else
   584                     else
   587                     if ( isInGameWin && !(SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
   585                     if ( isInGameWin && !(SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
   588                     
   586                     
   589                         SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
   587                         SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
       
   588                         if (!cursor_should_be_visible)
       
   589                             QZ_HideMouse (this);
   590                     }
   590                     }
   591                     break;
   591                     break;
   592                 case NSScrollWheel:
   592                 case NSScrollWheel:
   593                     if ( isInGameWin ) {
   593                     if ( isInGameWin ) {
   594                         float dy;
   594                         float dy;