Date: Thu, 17 Apr 2003 23:27:34 -0400
authorSam Lantinga <slouken@libsdl.org>
Sun, 20 Apr 2003 05:41:16 +0000
changeset 6157ec821f3cbd0
parent 614 0b4c3f5ff63d
child 616 12c746afbc27
Date: Thu, 17 Apr 2003 23:27:34 -0400
From: Darrell Walisser
Subject: Yet another OS X cursor bug

The synopsis:

1. Call SDL_ShowCursor(0);
2. Call SDL_SetVideoMode();
3. Call SDL_GetEvent();
3. Call SDL_ShowCursor(1);

The result: Sometimes the cursor doesn't come back! Ack! Oddly enough,
it does come back when mousing over the dock or clicking in the menu
bar. But that's besides the point.

The reason why this is happening is a flaw in the handling of
activation/deactivation events. The short explanation is that the
HideCursor() and ShowCursor() calls must be balanced, but if the cursor
was initially hidden, HideCursor() was called again on the activate
event - so now the next ShowCursor() fails (as does the next, and the
next, for some reason).

So, here's the patch. All it does is keep track of the
HideCursor()/ShowCursor() calls so that they will always be balanced.
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	Sun Apr 20 05:36:52 2003 +0000
     1.2 +++ b/src/video/quartz/SDL_QuartzEvents.m	Sun Apr 20 05:41:16 2003 +0000
     1.3 @@ -301,9 +301,10 @@
     1.4  {
     1.5      in_foreground = YES;
     1.6      
     1.7 -    /* Hide the mouse cursor if was hidden */
     1.8 -    if (!cursor_visible) {
     1.9 +    /* Hide the cursor if it was hidden by SDL_ShowCursor() */
    1.10 +    if (!cursor_visible && !cursor_hidden) {
    1.11          HideCursor ();
    1.12 +        cursor_hidden = YES;
    1.13      }
    1.14  
    1.15      /* Regrab input, only if it was previously grabbed */
    1.16 @@ -330,8 +331,11 @@
    1.17      /* Reassociate mouse and cursor */
    1.18      CGAssociateMouseAndMouseCursorPosition (1);
    1.19  
    1.20 -    /* Show the cursor */
    1.21 -    ShowCursor ();
    1.22 +    /* Show the cursor if it was hidden by SDL_ShowCursor() */
    1.23 +    if (!cursor_visible && cursor_hidden) {
    1.24 +        ShowCursor ();
    1.25 +        cursor_hidden = NO;
    1.26 +    }
    1.27  
    1.28      SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
    1.29  }
     2.1 --- a/src/video/quartz/SDL_QuartzVideo.h	Sun Apr 20 05:36:52 2003 +0000
     2.2 +++ b/src/video/quartz/SDL_QuartzVideo.h	Sun Apr 20 05:41:16 2003 +0000
     2.3 @@ -138,7 +138,8 @@
     2.4      Uint8              expect_mouse_up;    /* used to determine when to send mouse up events */
     2.5      Uint8              grab_state;         /* used to manage grab behavior */
     2.6      NSPoint            cursor_loc;         /* saved cursor coords, for activate/deactivate when grabbed */
     2.7 -    BOOL          	   cursor_visible;     /* tells if cursor was hidden or not */
     2.8 +    BOOL          	   cursor_visible;     /* tells if cursor was instructed to be hidden or not (SDL_ShowCursor) */
     2.9 +    BOOL               cursor_hidden;      /* tells if cursor is *actually* hidden or not */
    2.10      Uint8*             sw_buffers[2];      /* pointers to the two software buffers for double-buffer emulation */
    2.11      SDL_Thread         *thread;            /* thread for async updates to the screen */
    2.12      SDL_sem            *sem1, *sem2;       /* synchronization for async screen updates */
    2.13 @@ -183,6 +184,7 @@
    2.14  #define grab_state (this->hidden->grab_state)
    2.15  #define cursor_loc (this->hidden->cursor_loc)
    2.16  #define cursor_visible (this->hidden->cursor_visible)
    2.17 +#define cursor_hidden (this->hidden->cursor_hidden)
    2.18  #define sw_buffers (this->hidden->sw_buffers)
    2.19  #define thread (this->hidden->thread)
    2.20  #define sem1 (this->hidden->sem1)
     3.1 --- a/src/video/quartz/SDL_QuartzWM.m	Sun Apr 20 05:36:52 2003 +0000
     3.2 +++ b/src/video/quartz/SDL_QuartzWM.m	Sun Apr 20 05:41:16 2003 +0000
     3.3 @@ -72,7 +72,10 @@
     3.4  
     3.5      if ( cursor == NULL) {
     3.6          if ( cursor_visible ) {
     3.7 -            HideCursor ();
     3.8 +            if (!cursor_hidden) {
     3.9 +                HideCursor ();
    3.10 +                cursor_hidden = YES;
    3.11 +            }
    3.12              cursor_visible = NO;
    3.13              QZ_ChangeGrabState (this, QZ_HIDECURSOR);
    3.14          }
    3.15 @@ -80,7 +83,10 @@
    3.16      else {
    3.17          SetCursor(&cursor->curs);
    3.18          if ( ! cursor_visible ) {
    3.19 -            ShowCursor ();
    3.20 +            if (cursor_hidden) {
    3.21 +                ShowCursor ();
    3.22 +                cursor_hidden = NO;
    3.23 +            }
    3.24              cursor_visible = YES;
    3.25              QZ_ChangeGrabState (this, QZ_SHOWCURSOR);
    3.26          }