More improvements for bug #373 SDL-1.2
authorSam Lantinga
Sat, 14 Jul 2007 08:27:06 +0000
branchSDL-1.2
changeset 406658a5055da431
parent 4065 0c76e6d1c3d6
child 4067 07d621a03a94
More improvements for bug #373

Show the SDL cursor in the window and the arrow cursor outside the window.

This is also supposed to show the SDL cursor when activated, but that code
isn't working yet...
src/video/quartz/SDL_QuartzEvents.m
src/video/quartz/SDL_QuartzVideo.h
src/video/quartz/SDL_QuartzWM.m
     1.1 --- a/src/video/quartz/SDL_QuartzEvents.m	Sat Jul 14 08:00:50 2007 +0000
     1.2 +++ b/src/video/quartz/SDL_QuartzEvents.m	Sat Jul 14 08:27:06 2007 +0000
     1.3 @@ -623,11 +623,22 @@
     1.4  
     1.5  void QZ_DoActivate (_THIS) {
     1.6  
     1.7 -    SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS | (QZ_IsMouseInWindow (this) ? SDL_APPMOUSEFOCUS : 0));
     1.8 -    
     1.9 -    /* Hide the cursor if it was hidden by SDL_ShowCursor() */
    1.10 -    if (!cursor_should_be_visible)
    1.11 -        QZ_HideMouse (this);
    1.12 +    BOOL isInGameWin = QZ_IsMouseInWindow (this);
    1.13 +
    1.14 +    SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS | (isInGameWin ? SDL_APPMOUSEFOCUS : 0));
    1.15 +
    1.16 +    /* Reset the cursor state */
    1.17 +    /* FIXME: This doesn't currently work...
    1.18 +       Apparently you can't set the cursor inside windowDidBecomeKey
    1.19 +     */
    1.20 +    if ( isInGameWin ) {
    1.21 +        if (cursor_should_be_visible)
    1.22 +            SDL_SetCursor (NULL);
    1.23 +        else
    1.24 +            QZ_HideMouse (this);
    1.25 +    } else {
    1.26 +        QZ_ShowMouse (this, [NSCursor arrowCursor]);
    1.27 +    }
    1.28  
    1.29      /* Regrab input, only if it was previously grabbed */
    1.30      if ( current_grab_mode == SDL_GRAB_ON ) {
    1.31 @@ -656,7 +667,7 @@
    1.32  
    1.33      /* Show the cursor if it was hidden by SDL_ShowCursor() */
    1.34      if (!cursor_should_be_visible)
    1.35 -        QZ_ShowMouse (this);
    1.36 +        QZ_ShowMouse (this, [NSCursor arrowCursor]);
    1.37  }
    1.38  
    1.39  void QZ_SleepNotificationHandler (void * refcon,
    1.40 @@ -870,8 +881,7 @@
    1.41                          into the game window. This still generates a mouse moved event,
    1.42                          but not as a result of the warp (so it's in the right direction).
    1.43                      */
    1.44 -                    if ( grab_state == QZ_VISIBLE_GRAB &&
    1.45 -                         !isInGameWin ) {
    1.46 +                    if ( grab_state == QZ_VISIBLE_GRAB && !isInGameWin ) {
    1.47                         
    1.48                          NSPoint p;
    1.49                          QZ_GetMouseLocation (this, &p);
    1.50 @@ -909,15 +919,20 @@
    1.51                                cursor enters the window again, making it obvious
    1.52                                to the user that the grab is broken.*/
    1.53                              CGAssociateMouseAndMouseCursorPosition (1);
    1.54 -                        if (!cursor_should_be_visible)
    1.55 -                            QZ_ShowMouse (this);
    1.56 +
    1.57 +                        QZ_ShowMouse (this, [NSCursor arrowCursor]);
    1.58                      }
    1.59                      else
    1.60                      if ( isInGameWin && (SDL_GetAppState() & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) == SDL_APPINPUTFOCUS ) {
    1.61                      
    1.62                          SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
    1.63 -                        if (!cursor_should_be_visible)
    1.64 +
    1.65 +                        if (cursor_should_be_visible) {
    1.66 +                            SDL_SetCursor (NULL);
    1.67 +                        } else {
    1.68                              QZ_HideMouse (this);
    1.69 +                        }
    1.70 +
    1.71                          if (grab_state == QZ_INVISIBLE_GRAB) { /*see comment above*/
    1.72                              QZ_PrivateWarpCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
    1.73                              CGAssociateMouseAndMouseCursorPosition (0);
     2.1 --- a/src/video/quartz/SDL_QuartzVideo.h	Sat Jul 14 08:00:50 2007 +0000
     2.2 +++ b/src/video/quartz/SDL_QuartzVideo.h	Sat Jul 14 08:27:06 2007 +0000
     2.3 @@ -224,7 +224,7 @@
     2.4  void         QZ_PrivateWarpCursor (_THIS, int x, int y);
     2.5  void         QZ_ChangeGrabState (_THIS, int action);
     2.6  void         QZ_RegisterForSleepNotifications (_THIS);
     2.7 -void         QZ_ShowMouse (_THIS);
     2.8 +void         QZ_ShowMouse (_THIS, NSCursor *cursor);
     2.9  void         QZ_HideMouse (_THIS);
    2.10  void         QZ_PrivateGlobalToLocal (_THIS, NSPoint *p);
    2.11  void         QZ_PrivateCocoaToSDL (_THIS, NSPoint *p);
     3.1 --- a/src/video/quartz/SDL_QuartzWM.m	Sat Jul 14 08:00:50 2007 +0000
     3.2 +++ b/src/video/quartz/SDL_QuartzWM.m	Sat Jul 14 08:27:06 2007 +0000
     3.3 @@ -90,11 +90,12 @@
     3.4      return(NULL);
     3.5  }
     3.6  
     3.7 -void QZ_ShowMouse (_THIS) {
     3.8 +void QZ_ShowMouse (_THIS, NSCursor *cursor) {
     3.9      if (!cursor_visible) {
    3.10          [ NSCursor unhide ];
    3.11          cursor_visible = YES;
    3.12      }
    3.13 +    [ cursor set ];
    3.14  }
    3.15  
    3.16  void QZ_HideMouse (_THIS) {
    3.17 @@ -116,16 +117,15 @@
    3.18  int QZ_ShowWMCursor (_THIS, WMcursor *cursor) { 
    3.19  
    3.20      if ( cursor == NULL) {
    3.21 +        QZ_HideMouse (this);
    3.22          if ( cursor_should_be_visible ) {
    3.23 -            QZ_HideMouse (this);
    3.24              cursor_should_be_visible = NO;
    3.25              QZ_ChangeGrabState (this, QZ_HIDECURSOR);
    3.26          }
    3.27      }
    3.28      else {
    3.29 -        [ cursor->nscursor set ];
    3.30 +        QZ_ShowMouse (this, cursor->nscursor);
    3.31          if ( ! cursor_should_be_visible ) {
    3.32 -            QZ_ShowMouse (this);
    3.33              cursor_should_be_visible = YES;
    3.34              QZ_ChangeGrabState (this, QZ_SHOWCURSOR);
    3.35          }