src/video/cocoa/SDL_cocoawindow.m
changeset 7963 f06bbd9cd708
parent 7961 c629882e0a81
child 7964 56431f7d8f46
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Mon Nov 11 20:51:19 2013 -0800
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Nov 11 21:21:18 2013 -0800
     1.3 @@ -103,7 +103,7 @@
     1.4      wasVisible = [window isVisible];
     1.5      isFullscreen = NO;
     1.6      inFullscreenTransition = NO;
     1.7 -    pendingFullscreenTransition = PENDING_TRANSITION_NONE;
     1.8 +    pendingWindowOperation = PENDING_OPERATION_NONE;
     1.9  
    1.10      center = [NSNotificationCenter defaultCenter];
    1.11  
    1.12 @@ -199,7 +199,7 @@
    1.13          return NO;
    1.14      }
    1.15  
    1.16 -    pendingFullscreenTransition = PENDING_TRANSITION_NONE;
    1.17 +    pendingWindowOperation = PENDING_OPERATION_NONE;
    1.18  
    1.19      /* We can enter new style fullscreen mode for "fullscreen desktop" */
    1.20      if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
    1.21 @@ -221,9 +221,9 @@
    1.22  
    1.23      if (inFullscreenTransition) {
    1.24          if (state) {
    1.25 -            pendingFullscreenTransition = PENDING_TRANSITION_ENTER_FULLSCREEN;
    1.26 +            [self addPendingWindowOperation:PENDING_OPERATION_ENTER_FULLSCREEN];
    1.27          } else {
    1.28 -            pendingFullscreenTransition = PENDING_TRANSITION_LEAVE_FULLSCREEN;
    1.29 +            [self addPendingWindowOperation:PENDING_OPERATION_LEAVE_FULLSCREEN];
    1.30          }
    1.31          return YES;
    1.32      }
    1.33 @@ -232,6 +232,16 @@
    1.34      return YES;
    1.35  }
    1.36  
    1.37 +-(BOOL) isInFullscreenTransition
    1.38 +{
    1.39 +    return inFullscreenTransition;
    1.40 +}
    1.41 +
    1.42 +-(void) addPendingWindowOperation:(PendingWindowOperation) operation
    1.43 +{
    1.44 +    pendingWindowOperation = operation;
    1.45 +}
    1.46 +
    1.47  - (void)close
    1.48  {
    1.49      NSNotificationCenter *center;
    1.50 @@ -328,8 +338,10 @@
    1.51  
    1.52  - (void)windowDidResize:(NSNotification *)aNotification
    1.53  {
    1.54 +    SDL_Window *window = _data->window;
    1.55 +    NSWindow *nswindow = _data->nswindow;
    1.56      int x, y, w, h;
    1.57 -    NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]];
    1.58 +    NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
    1.59      ConvertNSRect(&rect);
    1.60      x = (int)rect.origin.x;
    1.61      y = (int)rect.origin.y;
    1.62 @@ -341,22 +353,22 @@
    1.63          return;
    1.64      }
    1.65  
    1.66 -    if (SDL_IsShapedWindow(_data->window)) {
    1.67 -        Cocoa_ResizeWindowShape(_data->window);
    1.68 +    if (SDL_IsShapedWindow(window)) {
    1.69 +        Cocoa_ResizeWindowShape(window);
    1.70      }
    1.71  
    1.72      ScheduleContextUpdates(_data);
    1.73  
    1.74      /* The window can move during a resize event, such as when maximizing
    1.75         or resizing from a corner */
    1.76 -    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MOVED, x, y);
    1.77 -    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESIZED, w, h);
    1.78 +    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
    1.79 +    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
    1.80  
    1.81 -    const BOOL zoomed = [_data->nswindow isZoomed];
    1.82 +    const BOOL zoomed = [nswindow isZoomed];
    1.83      if (!zoomed) {
    1.84 -        SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
    1.85 +        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
    1.86      } else if (zoomed) {
    1.87 -        SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
    1.88 +        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
    1.89      }
    1.90  }
    1.91  
    1.92 @@ -429,10 +441,11 @@
    1.93  {
    1.94      inFullscreenTransition = NO;
    1.95  
    1.96 -    if (pendingFullscreenTransition != PENDING_TRANSITION_NONE) {
    1.97 -        pendingFullscreenTransition = PENDING_TRANSITION_NONE;
    1.98 +    if (pendingWindowOperation == PENDING_OPERATION_LEAVE_FULLSCREEN) {
    1.99 +        pendingWindowOperation = PENDING_OPERATION_NONE;
   1.100          [self setFullscreenState:NO];
   1.101      } else {
   1.102 +        pendingWindowOperation = PENDING_OPERATION_NONE;
   1.103          [self windowDidResize:aNotification];
   1.104      }
   1.105  }
   1.106 @@ -453,10 +466,14 @@
   1.107      }
   1.108      inFullscreenTransition = NO;
   1.109  
   1.110 -    if (pendingFullscreenTransition != PENDING_TRANSITION_NONE) {
   1.111 -        pendingFullscreenTransition = PENDING_TRANSITION_NONE;
   1.112 +    if (pendingWindowOperation == PENDING_OPERATION_ENTER_FULLSCREEN) {
   1.113 +        pendingWindowOperation = PENDING_OPERATION_NONE;
   1.114          [self setFullscreenState:YES];
   1.115 +    } else if (pendingWindowOperation == PENDING_OPERATION_MINIMIZE) {
   1.116 +        pendingWindowOperation = PENDING_OPERATION_NONE;
   1.117 +        [nswindow miniaturize:nil];
   1.118      } else {
   1.119 +        pendingWindowOperation = PENDING_OPERATION_NONE;
   1.120          [self windowDidResize:aNotification];
   1.121      }
   1.122  }
   1.123 @@ -1095,9 +1112,14 @@
   1.124  Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
   1.125  {
   1.126      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   1.127 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   1.128 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   1.129 +    NSWindow *nswindow = data->nswindow;
   1.130  
   1.131 -    [nswindow miniaturize:nil];
   1.132 +    if ([data->listener isInFullscreenTransition]) {
   1.133 +        [data->listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
   1.134 +    } else {
   1.135 +        [nswindow miniaturize:nil];
   1.136 +    }
   1.137      [pool release];
   1.138  }
   1.139