src/video/cocoa/SDL_cocoawindow.m
changeset 7961 c629882e0a81
parent 7955 9446f2fbe4f0
child 7963 f06bbd9cd708
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Mon Nov 11 19:17:32 2013 -0300
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Nov 11 20:42:59 2013 -0800
     1.3 @@ -103,6 +103,7 @@
     1.4      wasVisible = [window isVisible];
     1.5      isFullscreen = NO;
     1.6      inFullscreenTransition = NO;
     1.7 +    pendingFullscreenTransition = PENDING_TRANSITION_NONE;
     1.8  
     1.9      center = [NSNotificationCenter defaultCenter];
    1.10  
    1.11 @@ -183,9 +184,52 @@
    1.12      }
    1.13  }
    1.14  
    1.15 -- (BOOL) isToggledFullscreen
    1.16 +-(BOOL) canSetFullscreenState:(BOOL) state;
    1.17  {
    1.18 -    return isFullscreen;
    1.19 +}
    1.20 +
    1.21 +-(BOOL) setFullscreenState:(BOOL) state;
    1.22 +{
    1.23 +    SDL_Window *window = _data->window;
    1.24 +    NSWindow *nswindow = _data->nswindow;
    1.25 +    BOOL canSetState = NO;
    1.26 +
    1.27 +    /* Make sure we can support this fullscreen style */
    1.28 +    if (![nswindow respondsToSelector: @selector(toggleFullScreen:)]) {
    1.29 +        return NO;
    1.30 +    }
    1.31 +
    1.32 +    pendingFullscreenTransition = PENDING_TRANSITION_NONE;
    1.33 +
    1.34 +    /* We can enter new style fullscreen mode for "fullscreen desktop" */
    1.35 +    if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
    1.36 +        canSetState = YES;
    1.37 +    }
    1.38 +
    1.39 +    /* We can always leave new style fullscreen mode */
    1.40 +    if (!state && isFullscreen) {
    1.41 +        canSetState = YES;
    1.42 +    }
    1.43 +
    1.44 +    if (!canSetState) {
    1.45 +        return NO;
    1.46 +    }
    1.47 +
    1.48 +    if (state == isFullscreen) {
    1.49 +        return YES;
    1.50 +    }
    1.51 +
    1.52 +    if (inFullscreenTransition) {
    1.53 +        if (state) {
    1.54 +            pendingFullscreenTransition = PENDING_TRANSITION_ENTER_FULLSCREEN;
    1.55 +        } else {
    1.56 +            pendingFullscreenTransition = PENDING_TRANSITION_LEAVE_FULLSCREEN;
    1.57 +        }
    1.58 +        return YES;
    1.59 +    }
    1.60 +
    1.61 +    [nswindow performSelector: @selector(toggleFullScreen:) withObject:nswindow];
    1.62 +    return YES;
    1.63  }
    1.64  
    1.65  - (void)close
    1.66 @@ -215,8 +259,7 @@
    1.67          [window setDelegate:nil];
    1.68      }
    1.69  
    1.70 -    [window removeObserver:self
    1.71 -                forKeyPath:@"visible"];
    1.72 +    [window removeObserver:self forKeyPath:@"visible"];
    1.73  
    1.74      if ([window nextResponder] == self) {
    1.75          [window setNextResponder:nil];
    1.76 @@ -385,11 +428,18 @@
    1.77  - (void)windowDidEnterFullScreen:(NSNotification *)aNotification
    1.78  {
    1.79      inFullscreenTransition = NO;
    1.80 -    [self windowDidResize:aNotification];
    1.81 +
    1.82 +    if (pendingFullscreenTransition != PENDING_TRANSITION_NONE) {
    1.83 +        pendingFullscreenTransition = PENDING_TRANSITION_NONE;
    1.84 +        [self setFullscreenState:NO];
    1.85 +    } else {
    1.86 +        [self windowDidResize:aNotification];
    1.87 +    }
    1.88  }
    1.89  
    1.90  - (void)windowWillExitFullScreen:(NSNotification *)aNotification
    1.91  {
    1.92 +    isFullscreen = NO;
    1.93      inFullscreenTransition = YES;
    1.94  }
    1.95  
    1.96 @@ -401,9 +451,14 @@
    1.97      if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
    1.98          [nswindow setStyleMask:GetWindowStyle(window)];
    1.99      }
   1.100 -    isFullscreen = NO;
   1.101      inFullscreenTransition = NO;
   1.102 -    [self windowDidResize:aNotification];
   1.103 +
   1.104 +    if (pendingFullscreenTransition != PENDING_TRANSITION_NONE) {
   1.105 +        pendingFullscreenTransition = PENDING_TRANSITION_NONE;
   1.106 +        [self setFullscreenState:YES];
   1.107 +    } else {
   1.108 +        [self windowDidResize:aNotification];
   1.109 +    }
   1.110  }
   1.111  
   1.112  /* We'll respond to key events by doing nothing so we don't beep.
   1.113 @@ -1094,41 +1149,6 @@
   1.114      [pool release];
   1.115  }
   1.116  
   1.117 -static SDL_bool
   1.118 -Cocoa_CanToggleFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
   1.119 -{
   1.120 -    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   1.121 -    NSWindow *nswindow = data->nswindow;
   1.122 -
   1.123 -    if (![nswindow respondsToSelector: @selector(toggleFullScreen:)]) {
   1.124 -        return SDL_FALSE;
   1.125 -    }
   1.126 -
   1.127 -    /* We can enter new style fullscreen mode for "fullscreen desktop" */
   1.128 -    if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
   1.129 -        return SDL_TRUE;
   1.130 -    }
   1.131 -
   1.132 -    /* We can always leave new style fullscreen mode */
   1.133 -    if (!fullscreen && [data->listener isToggledFullscreen]) {
   1.134 -        return SDL_TRUE;
   1.135 -    }
   1.136 -
   1.137 -    /* Requesting a mode switched fullscreen mode */
   1.138 -    return SDL_FALSE;
   1.139 -}
   1.140 -
   1.141 -static void
   1.142 -Cocoa_SetWindowFullscreen_NewStyle(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
   1.143 -{
   1.144 -    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   1.145 -    NSWindow *nswindow = data->nswindow;
   1.146 - 
   1.147 -    if (fullscreen != [data->listener isToggledFullscreen]) {
   1.148 -        [nswindow performSelector: @selector(toggleFullScreen:) withObject:nswindow];
   1.149 -    }
   1.150 -    ScheduleContextUpdates(data);
   1.151 -}
   1.152  
   1.153  static void
   1.154  Cocoa_SetWindowFullscreen_OldStyle(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
   1.155 @@ -1212,10 +1232,9 @@
   1.156  Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
   1.157  {
   1.158      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.159 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   1.160  
   1.161 -    if (Cocoa_CanToggleFullscreen(_this, window, display, fullscreen)) {
   1.162 -        Cocoa_SetWindowFullscreen_NewStyle(_this, window, display, fullscreen);
   1.163 -    } else {
   1.164 +    if (![data->listener setFullscreenState:(fullscreen ? YES : NO)]) {
   1.165          Cocoa_SetWindowFullscreen_OldStyle(_this, window, display, fullscreen);
   1.166      }
   1.167