src/video/cocoa/SDL_cocoawindow.m
changeset 9904 e9b49510e51b
parent 9903 2bbb11de1e60
child 9905 fcf85090f816
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Mon Nov 09 08:54:42 2015 -0800
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Nov 09 08:54:49 2015 -0800
     1.3 @@ -646,9 +646,6 @@
     1.4  
     1.5      isFullscreenSpace = NO;
     1.6      inFullscreenTransition = NO;
     1.7 -
     1.8 -    /* Try again? Not sure what else to do, the application wants to be fullscreen. */
     1.9 -    [self setFullscreenSpace:YES];
    1.10  }
    1.11  
    1.12  - (void)windowDidEnterFullScreen:(NSNotification *)aNotification
    1.13 @@ -693,9 +690,6 @@
    1.14      
    1.15      isFullscreenSpace = YES;
    1.16      inFullscreenTransition = NO;
    1.17 -
    1.18 -    /* Try again? Not sure what else to do, the application wants to be non-fullscreen. */
    1.19 -    [self setFullscreenSpace:NO];
    1.20  }
    1.21  
    1.22  - (void)windowDidExitFullScreen:(NSNotification *)aNotification
    1.23 @@ -1704,21 +1698,30 @@
    1.24      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    1.25  
    1.26      if ([data->listener setFullscreenSpace:(state ? YES : NO)]) {
    1.27 +        const int maxattempts = 3;
    1.28 +        int attempt = 0;
    1.29 +        while (++attempt <= maxattempts) {
    1.30 +            /* Wait for the transition to complete, so application changes
    1.31 +             take effect properly (e.g. setting the window size, etc.)
    1.32 +             */
    1.33 +            const int limit = 10000;
    1.34 +            int count = 0;
    1.35 +            while ([data->listener isInFullscreenSpaceTransition]) {
    1.36 +                if ( ++count == limit ) {
    1.37 +                    /* Uh oh, transition isn't completing. Should we assert? */
    1.38 +                    break;
    1.39 +                }
    1.40 +                SDL_Delay(1);
    1.41 +                SDL_PumpEvents();
    1.42 +            }
    1.43 +            if ([data->listener isInFullscreenSpace] == (state ? YES : NO))
    1.44 +                break;
    1.45 +            /* Try again, the last attempt was interrupted by user gestures */
    1.46 +            if (![data->listener setFullscreenSpace:(state ? YES : NO)])
    1.47 +                break; /* ??? */
    1.48 +        }
    1.49 +        /* Return TRUE to prevent non-space fullscreen logic from running */
    1.50          succeeded = SDL_TRUE;
    1.51 -
    1.52 -        /* Wait for the transition to complete, so application changes
    1.53 -           take effect properly (e.g. setting the window size, etc.)
    1.54 -         */
    1.55 -        const int limit = 10000;
    1.56 -        int count = 0;
    1.57 -        while ([data->listener isInFullscreenSpaceTransition]) {
    1.58 -            if ( ++count == limit ) {
    1.59 -                /* Uh oh, transition isn't completing. Should we assert? */
    1.60 -                break;
    1.61 -            }
    1.62 -            SDL_Delay(1);
    1.63 -            SDL_PumpEvents();
    1.64 -        }
    1.65      }
    1.66  
    1.67      return succeeded;