Fixed assertion failure when minimizing a fullscreen window.
authorSam Lantinga <slouken@libsdl.org>
Mon, 11 Nov 2013 21:21:18 -0800
changeset 7963f06bbd9cd708
parent 7962 e4d2f3375868
child 7964 56431f7d8f46
Fixed assertion failure when minimizing a fullscreen window.
src/video/cocoa/SDL_cocoawindow.h
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.h	Mon Nov 11 20:51:19 2013 -0800
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.h	Mon Nov 11 21:21:18 2013 -0800
     1.3 @@ -27,6 +27,14 @@
     1.4  
     1.5  typedef struct SDL_WindowData SDL_WindowData;
     1.6  
     1.7 +typedef enum
     1.8 +{
     1.9 +    PENDING_OPERATION_NONE,
    1.10 +    PENDING_OPERATION_ENTER_FULLSCREEN,
    1.11 +    PENDING_OPERATION_LEAVE_FULLSCREEN,
    1.12 +    PENDING_OPERATION_MINIMIZE
    1.13 +} PendingWindowOperation;
    1.14 +
    1.15  @interface Cocoa_WindowListener : NSResponder <NSWindowDelegate> {
    1.16      SDL_WindowData *_data;
    1.17      BOOL observingVisible;
    1.18 @@ -34,19 +42,15 @@
    1.19      BOOL wasVisible;
    1.20      BOOL isFullscreen;
    1.21      BOOL inFullscreenTransition;
    1.22 -
    1.23 -    enum
    1.24 -    {
    1.25 -        PENDING_TRANSITION_NONE,
    1.26 -        PENDING_TRANSITION_ENTER_FULLSCREEN,
    1.27 -        PENDING_TRANSITION_LEAVE_FULLSCREEN
    1.28 -    } pendingFullscreenTransition;
    1.29 +    PendingWindowOperation pendingWindowOperation;
    1.30  }
    1.31  
    1.32  -(void) listen:(SDL_WindowData *) data;
    1.33  -(void) pauseVisibleObservation;
    1.34  -(void) resumeVisibleObservation;
    1.35  -(BOOL) setFullscreenState:(BOOL) state;
    1.36 +-(BOOL) isInFullscreenTransition;
    1.37 +-(void) addPendingWindowOperation:(PendingWindowOperation) operation;
    1.38  -(void) close;
    1.39  
    1.40  /* Window delegate functionality */
     2.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Mon Nov 11 20:51:19 2013 -0800
     2.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Nov 11 21:21:18 2013 -0800
     2.3 @@ -103,7 +103,7 @@
     2.4      wasVisible = [window isVisible];
     2.5      isFullscreen = NO;
     2.6      inFullscreenTransition = NO;
     2.7 -    pendingFullscreenTransition = PENDING_TRANSITION_NONE;
     2.8 +    pendingWindowOperation = PENDING_OPERATION_NONE;
     2.9  
    2.10      center = [NSNotificationCenter defaultCenter];
    2.11  
    2.12 @@ -199,7 +199,7 @@
    2.13          return NO;
    2.14      }
    2.15  
    2.16 -    pendingFullscreenTransition = PENDING_TRANSITION_NONE;
    2.17 +    pendingWindowOperation = PENDING_OPERATION_NONE;
    2.18  
    2.19      /* We can enter new style fullscreen mode for "fullscreen desktop" */
    2.20      if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
    2.21 @@ -221,9 +221,9 @@
    2.22  
    2.23      if (inFullscreenTransition) {
    2.24          if (state) {
    2.25 -            pendingFullscreenTransition = PENDING_TRANSITION_ENTER_FULLSCREEN;
    2.26 +            [self addPendingWindowOperation:PENDING_OPERATION_ENTER_FULLSCREEN];
    2.27          } else {
    2.28 -            pendingFullscreenTransition = PENDING_TRANSITION_LEAVE_FULLSCREEN;
    2.29 +            [self addPendingWindowOperation:PENDING_OPERATION_LEAVE_FULLSCREEN];
    2.30          }
    2.31          return YES;
    2.32      }
    2.33 @@ -232,6 +232,16 @@
    2.34      return YES;
    2.35  }
    2.36  
    2.37 +-(BOOL) isInFullscreenTransition
    2.38 +{
    2.39 +    return inFullscreenTransition;
    2.40 +}
    2.41 +
    2.42 +-(void) addPendingWindowOperation:(PendingWindowOperation) operation
    2.43 +{
    2.44 +    pendingWindowOperation = operation;
    2.45 +}
    2.46 +
    2.47  - (void)close
    2.48  {
    2.49      NSNotificationCenter *center;
    2.50 @@ -328,8 +338,10 @@
    2.51  
    2.52  - (void)windowDidResize:(NSNotification *)aNotification
    2.53  {
    2.54 +    SDL_Window *window = _data->window;
    2.55 +    NSWindow *nswindow = _data->nswindow;
    2.56      int x, y, w, h;
    2.57 -    NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]];
    2.58 +    NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
    2.59      ConvertNSRect(&rect);
    2.60      x = (int)rect.origin.x;
    2.61      y = (int)rect.origin.y;
    2.62 @@ -341,22 +353,22 @@
    2.63          return;
    2.64      }
    2.65  
    2.66 -    if (SDL_IsShapedWindow(_data->window)) {
    2.67 -        Cocoa_ResizeWindowShape(_data->window);
    2.68 +    if (SDL_IsShapedWindow(window)) {
    2.69 +        Cocoa_ResizeWindowShape(window);
    2.70      }
    2.71  
    2.72      ScheduleContextUpdates(_data);
    2.73  
    2.74      /* The window can move during a resize event, such as when maximizing
    2.75         or resizing from a corner */
    2.76 -    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MOVED, x, y);
    2.77 -    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESIZED, w, h);
    2.78 +    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
    2.79 +    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
    2.80  
    2.81 -    const BOOL zoomed = [_data->nswindow isZoomed];
    2.82 +    const BOOL zoomed = [nswindow isZoomed];
    2.83      if (!zoomed) {
    2.84 -        SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
    2.85 +        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
    2.86      } else if (zoomed) {
    2.87 -        SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
    2.88 +        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
    2.89      }
    2.90  }
    2.91  
    2.92 @@ -429,10 +441,11 @@
    2.93  {
    2.94      inFullscreenTransition = NO;
    2.95  
    2.96 -    if (pendingFullscreenTransition != PENDING_TRANSITION_NONE) {
    2.97 -        pendingFullscreenTransition = PENDING_TRANSITION_NONE;
    2.98 +    if (pendingWindowOperation == PENDING_OPERATION_LEAVE_FULLSCREEN) {
    2.99 +        pendingWindowOperation = PENDING_OPERATION_NONE;
   2.100          [self setFullscreenState:NO];
   2.101      } else {
   2.102 +        pendingWindowOperation = PENDING_OPERATION_NONE;
   2.103          [self windowDidResize:aNotification];
   2.104      }
   2.105  }
   2.106 @@ -453,10 +466,14 @@
   2.107      }
   2.108      inFullscreenTransition = NO;
   2.109  
   2.110 -    if (pendingFullscreenTransition != PENDING_TRANSITION_NONE) {
   2.111 -        pendingFullscreenTransition = PENDING_TRANSITION_NONE;
   2.112 +    if (pendingWindowOperation == PENDING_OPERATION_ENTER_FULLSCREEN) {
   2.113 +        pendingWindowOperation = PENDING_OPERATION_NONE;
   2.114          [self setFullscreenState:YES];
   2.115 +    } else if (pendingWindowOperation == PENDING_OPERATION_MINIMIZE) {
   2.116 +        pendingWindowOperation = PENDING_OPERATION_NONE;
   2.117 +        [nswindow miniaturize:nil];
   2.118      } else {
   2.119 +        pendingWindowOperation = PENDING_OPERATION_NONE;
   2.120          [self windowDidResize:aNotification];
   2.121      }
   2.122  }
   2.123 @@ -1095,9 +1112,14 @@
   2.124  Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
   2.125  {
   2.126      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   2.127 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
   2.128 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   2.129 +    NSWindow *nswindow = data->nswindow;
   2.130  
   2.131 -    [nswindow miniaturize:nil];
   2.132 +    if ([data->listener isInFullscreenTransition]) {
   2.133 +        [data->listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
   2.134 +    } else {
   2.135 +        [nswindow miniaturize:nil];
   2.136 +    }
   2.137      [pool release];
   2.138  }
   2.139