SDL OSX implementation must account for the fact that going fullscreen can fail. improve the logic around retrying, make a few attempts before failing.
authorSam Lantinga <slouken@libsdl.org>
Mon, 09 Nov 2015 08:54:49 -0800
changeset 9904e9b49510e51b
parent 9903 2bbb11de1e60
child 9905 fcf85090f816
SDL OSX implementation must account for the fact that going fullscreen can fail. improve the logic around retrying, make a few attempts before failing.
src/video/SDL_video.c
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/SDL_video.c	Mon Nov 09 08:54:42 2015 -0800
     1.2 +++ b/src/video/SDL_video.c	Mon Nov 09 08:54:49 2015 -0800
     1.3 @@ -1140,7 +1140,9 @@
     1.4  #ifdef __MACOSX__
     1.5      /* If we're switching between a fullscreen Space and "normal" fullscreen, we need to get back to normal first. */
     1.6      if (fullscreen && ((window->last_fullscreen_flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN_DESKTOP) && ((window->flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN)) {
     1.7 -        Cocoa_SetWindowFullscreenSpace(window, SDL_FALSE);
     1.8 +        if (!Cocoa_SetWindowFullscreenSpace(window, SDL_FALSE)) {
     1.9 +            return -1;
    1.10 +        }
    1.11      } else if (fullscreen && ((window->last_fullscreen_flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN) && ((window->flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN_DESKTOP)) {
    1.12          display = SDL_GetDisplayForWindow(window);
    1.13          SDL_SetDisplayModeForDisplay(display, NULL);
    1.14 @@ -1150,6 +1152,9 @@
    1.15      }
    1.16  
    1.17      if (Cocoa_SetWindowFullscreenSpace(window, fullscreen)) {
    1.18 +        if (Cocoa_IsWindowInFullscreenSpace(window) != fullscreen) {
    1.19 +            return -1;
    1.20 +        }
    1.21          window->last_fullscreen_flags = window->flags;
    1.22          return 0;
    1.23      }
     2.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Mon Nov 09 08:54:42 2015 -0800
     2.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Nov 09 08:54:49 2015 -0800
     2.3 @@ -646,9 +646,6 @@
     2.4  
     2.5      isFullscreenSpace = NO;
     2.6      inFullscreenTransition = NO;
     2.7 -
     2.8 -    /* Try again? Not sure what else to do, the application wants to be fullscreen. */
     2.9 -    [self setFullscreenSpace:YES];
    2.10  }
    2.11  
    2.12  - (void)windowDidEnterFullScreen:(NSNotification *)aNotification
    2.13 @@ -693,9 +690,6 @@
    2.14      
    2.15      isFullscreenSpace = YES;
    2.16      inFullscreenTransition = NO;
    2.17 -
    2.18 -    /* Try again? Not sure what else to do, the application wants to be non-fullscreen. */
    2.19 -    [self setFullscreenSpace:NO];
    2.20  }
    2.21  
    2.22  - (void)windowDidExitFullScreen:(NSNotification *)aNotification
    2.23 @@ -1704,21 +1698,30 @@
    2.24      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    2.25  
    2.26      if ([data->listener setFullscreenSpace:(state ? YES : NO)]) {
    2.27 +        const int maxattempts = 3;
    2.28 +        int attempt = 0;
    2.29 +        while (++attempt <= maxattempts) {
    2.30 +            /* Wait for the transition to complete, so application changes
    2.31 +             take effect properly (e.g. setting the window size, etc.)
    2.32 +             */
    2.33 +            const int limit = 10000;
    2.34 +            int count = 0;
    2.35 +            while ([data->listener isInFullscreenSpaceTransition]) {
    2.36 +                if ( ++count == limit ) {
    2.37 +                    /* Uh oh, transition isn't completing. Should we assert? */
    2.38 +                    break;
    2.39 +                }
    2.40 +                SDL_Delay(1);
    2.41 +                SDL_PumpEvents();
    2.42 +            }
    2.43 +            if ([data->listener isInFullscreenSpace] == (state ? YES : NO))
    2.44 +                break;
    2.45 +            /* Try again, the last attempt was interrupted by user gestures */
    2.46 +            if (![data->listener setFullscreenSpace:(state ? YES : NO)])
    2.47 +                break; /* ??? */
    2.48 +        }
    2.49 +        /* Return TRUE to prevent non-space fullscreen logic from running */
    2.50          succeeded = SDL_TRUE;
    2.51 -
    2.52 -        /* Wait for the transition to complete, so application changes
    2.53 -           take effect properly (e.g. setting the window size, etc.)
    2.54 -         */
    2.55 -        const int limit = 10000;
    2.56 -        int count = 0;
    2.57 -        while ([data->listener isInFullscreenSpaceTransition]) {
    2.58 -            if ( ++count == limit ) {
    2.59 -                /* Uh oh, transition isn't completing. Should we assert? */
    2.60 -                break;
    2.61 -            }
    2.62 -            SDL_Delay(1);
    2.63 -            SDL_PumpEvents();
    2.64 -        }
    2.65      }
    2.66  
    2.67      return succeeded;