comparison src/video/quartz/SDL_QuartzEvents.m @ 4070:b8f2db95145e SDL-1.2

Patch from Christian Walther Yes, the idea to use a cursor rectangle instead of [NSCursor set] has occurred to me too, and it does seem to be the most elegant way. Here's my attempt at an implementation
author Sam Lantinga <slouken@libsdl.org>
date Sun, 15 Jul 2007 15:58:00 +0000
parents 58a5055da431
children 6930cd5ab933
comparison
equal deleted inserted replaced
4069:f19931785c42 4070:b8f2db95145e
20 slouken@libsdl.org 20 slouken@libsdl.org
21 */ 21 */
22 #include "SDL_config.h" 22 #include "SDL_config.h"
23 23
24 #include "SDL_QuartzVideo.h" 24 #include "SDL_QuartzVideo.h"
25 #include "SDL_QuartzWM.h"
25 26
26 #include <IOKit/IOMessage.h> /* For wake from sleep detection */ 27 #include <IOKit/IOMessage.h> /* For wake from sleep detection */
27 #include <IOKit/pwr_mgt/IOPMLib.h> /* For wake from sleep detection */ 28 #include <IOKit/pwr_mgt/IOPMLib.h> /* For wake from sleep detection */
28 #include "SDL_QuartzKeys.h" 29 #include "SDL_QuartzKeys.h"
29 30
621 QZ_PrivateCocoaToSDL (this, p); 622 QZ_PrivateCocoaToSDL (this, p);
622 } 623 }
623 624
624 void QZ_DoActivate (_THIS) { 625 void QZ_DoActivate (_THIS) {
625 626
626 BOOL isInGameWin = QZ_IsMouseInWindow (this); 627 SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS | (QZ_IsMouseInWindow (this) ? SDL_APPMOUSEFOCUS : 0));
627 628
628 SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS | (isInGameWin ? SDL_APPMOUSEFOCUS : 0)); 629 QZ_UpdateCursor(this);
629
630 /* Reset the cursor state */
631 /* FIXME: This doesn't currently work...
632 Apparently you can't set the cursor inside windowDidBecomeKey
633 */
634 if ( isInGameWin ) {
635 if (cursor_should_be_visible)
636 SDL_SetCursor (NULL);
637 else
638 QZ_HideMouse (this);
639 } else {
640 QZ_ShowMouse (this, [NSCursor arrowCursor]);
641 }
642 630
643 /* Regrab input, only if it was previously grabbed */ 631 /* Regrab input, only if it was previously grabbed */
644 if ( current_grab_mode == SDL_GRAB_ON ) { 632 if ( current_grab_mode == SDL_GRAB_ON ) {
645 633
646 /* Restore cursor location if input was grabbed */ 634 /* Restore cursor location if input was grabbed */
663 QZ_GetMouseLocation (this, &cursor_loc); 651 QZ_GetMouseLocation (this, &cursor_loc);
664 652
665 /* Reassociate mouse and cursor */ 653 /* Reassociate mouse and cursor */
666 CGAssociateMouseAndMouseCursorPosition (1); 654 CGAssociateMouseAndMouseCursorPosition (1);
667 655
668 /* Show the cursor if it was hidden by SDL_ShowCursor() */ 656 QZ_UpdateCursor(this);
669 if (!cursor_should_be_visible)
670 QZ_ShowMouse (this, [NSCursor arrowCursor]);
671 } 657 }
672 658
673 void QZ_SleepNotificationHandler (void * refcon, 659 void QZ_SleepNotificationHandler (void * refcon,
674 io_service_t service, 660 io_service_t service,
675 natural_t messageType, 661 natural_t messageType,
902 } 888 }
903 else 889 else
904 if ( !isInGameWin && (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) { 890 if ( !isInGameWin && (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
905 891
906 SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS); 892 SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS);
893
907 if (grab_state == QZ_INVISIBLE_GRAB) 894 if (grab_state == QZ_INVISIBLE_GRAB)
908 /*The cursor has left the window even though it is 895 /*The cursor has left the window even though it is
909 disassociated from the mouse (and therefore 896 disassociated from the mouse (and therefore
910 shouldn't move): this can happen with Wacom 897 shouldn't move): this can happen with Wacom
911 tablets, and it effectively breaks the grab, since 898 tablets, and it effectively breaks the grab, since
918 before by reassociating cursor and mouse until the 905 before by reassociating cursor and mouse until the
919 cursor enters the window again, making it obvious 906 cursor enters the window again, making it obvious
920 to the user that the grab is broken.*/ 907 to the user that the grab is broken.*/
921 CGAssociateMouseAndMouseCursorPosition (1); 908 CGAssociateMouseAndMouseCursorPosition (1);
922 909
923 QZ_ShowMouse (this, [NSCursor arrowCursor]); 910 QZ_UpdateCursor(this);
924 } 911 }
925 else 912 else
926 if ( isInGameWin && (SDL_GetAppState() & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) == SDL_APPINPUTFOCUS ) { 913 if ( isInGameWin && (SDL_GetAppState() & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) == SDL_APPINPUTFOCUS ) {
927 914
928 SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS); 915 SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
929 916
930 if (cursor_should_be_visible) { 917 QZ_UpdateCursor(this);
931 SDL_SetCursor (NULL);
932 } else {
933 QZ_HideMouse (this);
934 }
935 918
936 if (grab_state == QZ_INVISIBLE_GRAB) { /*see comment above*/ 919 if (grab_state == QZ_INVISIBLE_GRAB) { /*see comment above*/
937 QZ_PrivateWarpCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2); 920 QZ_PrivateWarpCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
938 CGAssociateMouseAndMouseCursorPosition (0); 921 CGAssociateMouseAndMouseCursorPosition (0);
939 } 922 }