src/video/quartz/SDL_QuartzEvents.m
changeset 1629 ef4a796e7f24
parent 1560 34b9e479047e
child 1662 782fd950bd46
child 1876 406b8325ee34
equal deleted inserted replaced
1628:10b4827452a8 1629:ef4a796e7f24
   612     if (qz_window)
   612     if (qz_window)
   613         QZ_PrivateGlobalToLocal (this, p);
   613         QZ_PrivateGlobalToLocal (this, p);
   614     QZ_PrivateCocoaToSDL (this, p);
   614     QZ_PrivateCocoaToSDL (this, p);
   615 }
   615 }
   616 
   616 
   617 static void QZ_DoActivate (_THIS)
   617 void QZ_DoActivate (_THIS) {
   618 {
   618 
       
   619     SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS | (QZ_IsMouseInWindow (this) ? SDL_APPMOUSEFOCUS : 0));
       
   620     
   619     /* Hide the cursor if it was hidden by SDL_ShowCursor() */
   621     /* Hide the cursor if it was hidden by SDL_ShowCursor() */
   620     if (!cursor_should_be_visible)
   622     if (!cursor_should_be_visible)
   621         QZ_HideMouse (this);
   623         QZ_HideMouse (this);
   622 
   624 
   623     /* Regrab input, only if it was previously grabbed */
   625     /* Regrab input, only if it was previously grabbed */
   633         QZ_GetMouseLocation (this, &p);
   635         QZ_GetMouseLocation (this, &p);
   634         SDL_PrivateMouseMotion (0, 0, p.x, p.y);
   636         SDL_PrivateMouseMotion (0, 0, p.x, p.y);
   635     }
   637     }
   636 }
   638 }
   637 
   639 
   638 static void QZ_DoDeactivate (_THIS) {
   640 void QZ_DoDeactivate (_THIS) {
       
   641     
       
   642     SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS | SDL_APPMOUSEFOCUS);
   639 
   643 
   640     /* Get the current cursor location, for restore on activate */
   644     /* Get the current cursor location, for restore on activate */
   641     QZ_GetMouseLocation (this, &cursor_loc);
   645     QZ_GetMouseLocation (this, &cursor_loc);
   642     
   646     
   643     /* Reassociate mouse and cursor */
   647     /* Reassociate mouse and cursor */
   751             int button;
   755             int button;
   752             unsigned int type;
   756             unsigned int type;
   753             BOOL isInGameWin;
   757             BOOL isInGameWin;
   754             
   758             
   755             #define DO_MOUSE_DOWN(button) do {                                               \
   759             #define DO_MOUSE_DOWN(button) do {                                               \
   756                             if ( [ NSApp isActive ] ) {                                      \
   760                             if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) {                   \
   757                                 if ( isInGameWin ) {                                         \
   761                                 SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0);          \
   758                                     SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0);      \
   762                                 expect_mouse_up |= 1<<button;                                \
   759                                     expect_mouse_up |= 1<<button;                            \
       
   760                                 }                                                            \
       
   761                             }                                                                \
       
   762                             else {                                                           \
       
   763                                 QZ_DoActivate (this);                                        \
       
   764                             }                                                                \
   763                             }                                                                \
   765                             [ NSApp sendEvent:event ];                                       \
   764                             [ NSApp sendEvent:event ];                                       \
   766             } while(0)
   765             } while(0)
   767             
   766             
   768             #define DO_MOUSE_UP(button) do {                                            \
   767             #define DO_MOUSE_UP(button) do {                                            \
   914                             CGAssociateMouseAndMouseCursorPosition (1);
   913                             CGAssociateMouseAndMouseCursorPosition (1);
   915                         if (!cursor_should_be_visible)
   914                         if (!cursor_should_be_visible)
   916                             QZ_ShowMouse (this);
   915                             QZ_ShowMouse (this);
   917                     }
   916                     }
   918                     else
   917                     else
   919                     if ( isInGameWin && !(SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
   918                     if ( isInGameWin && (SDL_GetAppState() & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) == SDL_APPINPUTFOCUS ) {
   920                     
   919                     
   921                         SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
   920                         SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
   922                         if (!cursor_should_be_visible)
   921                         if (!cursor_should_be_visible)
   923                             QZ_HideMouse (this);
   922                             QZ_HideMouse (this);
   924                         if (grab_state == QZ_INVISIBLE_GRAB) { /*see comment above*/
   923                         if (grab_state == QZ_INVISIBLE_GRAB) { /*see comment above*/
   948                 case NSKeyDown:
   947                 case NSKeyDown:
   949                     QZ_DoKey (this, SDL_PRESSED, event);
   948                     QZ_DoKey (this, SDL_PRESSED, event);
   950                     break;
   949                     break;
   951                 case NSFlagsChanged:
   950                 case NSFlagsChanged:
   952                     break;
   951                     break;
   953                 case NSAppKitDefined:
   952                     /* case NSAppKitDefined: break; */
   954                     switch ( [ event subtype ] ) {
       
   955                         case NSApplicationActivatedEventType:
       
   956                             QZ_DoActivate (this);
       
   957                             break;
       
   958                         case NSApplicationDeactivatedEventType:
       
   959                             QZ_DoDeactivate (this);
       
   960                             break;
       
   961                     }
       
   962                     [ NSApp sendEvent:event ];
       
   963                     break;
       
   964                     /* case NSApplicationDefined: break; */
   953                     /* case NSApplicationDefined: break; */
   965                     /* case NSPeriodic: break; */
   954                     /* case NSPeriodic: break; */
   966                     /* case NSCursorUpdate: break; */
   955                     /* case NSCursorUpdate: break; */
   967                 default:
   956                 default:
   968                     [ NSApp sendEvent:event ];
   957                     [ NSApp sendEvent:event ];