comparison src/video/quartz/SDL_QuartzEvents.m @ 1629:ef4a796e7f24

Fixed bug #55 From Christian Walther: When writing my patch for #12, I ended up doing all sorts of changes to the way application/window activating/deactivating is handled in the Quartz backend, resulting in the attached patch. It does make the code a bit cleaner IMHO, but as it might be regarded as a case of "if it ain't broken, don't fix it" I'd like to hear other people's opinion about it. Please shout if some change strikes you as unnecessary or wrong, and I'll explain the reasons behind it. As far as I tested it, it does not introduce any new bugs, but I may well have missed some. - The most fundamental change (that triggered most of the others) is irrelevant for the usual single-window SDL applications, it only affects the people who are crazy enough to display other Cocoa windows alongside the SDL window (I'm actually doing this currently, although the additional window only displays debugging info and won't be present in the final product): Before, some things were done on the application becoming active, some on the window becoming key, and some on the window becoming main. Conceptually, all these actions belong to the window becoming key, so that's what I implemented. However, since in a single-window application these three events always happen together, the previous implementation "ain't broken". - This slightly changed the meaning of the SDL_APPMOUSEFOCUS flag from SDL_GetAppState(): Before, it meant "window is main and mouse is inside window (or mode is fullscreen)". Now, it means "window is key and mouse is inside window (or mode is fullscreen)". It makes more sense to me that way. (See http://developer.apple.com/documentation/Cocoa/Conceptual/WinPanel/Concepts/ChangingMainKeyWindow.html for a discussion of what key and main windows are.) The other two flags are unchanged: SDL_APPACTIVE = application is not hidden and window is not minimized, SDL_APPINPUTFOCUS = window is key (or mode is fullscreen). - As a side effect, the reorganization fixes the following two issues (and maybe others) (but they could also be fixed in less invasive ways): * A regression that was introduced in revision 1.42 of SDL_QuartzVideo.m (http://libsdl.org/cgi/cvsweb.cgi/SDL12/src/video/quartz/SDL_QuartzVideo.m.diff?r1=1.41&r2=1.42) (from half-desirable to undesirable behavior): Situation: While in windowed mode, hide the cursor using SDL_ShowCursor(SDL_DISABLE), move the mouse outside of the window so that the cursor becomes visible again, and SDL_SetVideoMode() to a fullscreen mode. What happened before revision 1.42: The cursor is visible, but becomes invisible as soon as the mouse is moved (half-desirable). What happens in revision 1.42 and after (including current CVS): The cursor is visible and stays visible (undesirable). What happens after my patch: The cursor is invisible from the beginning (desirable). * When the cursor is hidden and grabbed, switch away from the application using cmd-tab (which ungrabs and makes the cursor visible), move the cursor outside of the SDL window, then cmd-tab back to the application. In 1.2.8 and in the current CVS, the cursor is re-grabbed, but it stays visible (immovable in the middle of the window). With my patch, the cursor is correctly re-grabbed and hidden. (For some reason, it still doesn't work correctly if you switch back to the application using the dock instead of cmd-tab. I haven't been able to figure out why. I can step over [NSCursor hide] being called in the debugger, but it seems to have no effect.) - The patch includes my patch for #12 (it was easier to obtain using cvs diff that way). If you apply both of them, you will end up with 6 duplicate lines in SDL_QuartzEvents.m.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 13 Apr 2006 14:17:48 +0000
parents 34b9e479047e
children 782fd950bd46 406b8325ee34
comparison
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 ];