Fixed minimizing fullscreen windows.
authorSam Lantinga <slouken@libsdl.org>
Sun, 27 Feb 2011 21:17:06 -0800
changeset 54046717e01acbe0
parent 5403 424f036f7c68
child 5405 64fa8526e1ce
Fixed minimizing fullscreen windows.
Removed misleading hide/unhide Cocoa notifications.
We have no way of knowing when a Cocoa window is maximized and then restored (right?)
Disabled spamy mouse motion events by default.
src/video/SDL_video.c
src/video/cocoa/SDL_cocoawindow.h
src/video/cocoa/SDL_cocoawindow.m
test/common.c
     1.1 --- a/src/video/SDL_video.c	Sun Feb 27 20:06:45 2011 -0800
     1.2 +++ b/src/video/SDL_video.c	Sun Feb 27 21:17:06 2011 -0800
     1.3 @@ -1018,12 +1018,12 @@
     1.4  }
     1.5  
     1.6  static void
     1.7 -SDL_UpdateFullscreenMode(SDL_Window * window)
     1.8 +SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
     1.9  {
    1.10      SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
    1.11      SDL_Window *other;
    1.12  
    1.13 -    if (FULLSCREEN_VISIBLE(window)) {
    1.14 +    if (fullscreen) {
    1.15          /* Hide any other fullscreen windows */
    1.16          if (display->fullscreen_window &&
    1.17              display->fullscreen_window != window) {
    1.18 @@ -1032,15 +1032,24 @@
    1.19      }
    1.20  
    1.21      /* See if anything needs to be done now */
    1.22 -    if ((display->fullscreen_window == window) == FULLSCREEN_VISIBLE(window)) {
    1.23 +    if ((display->fullscreen_window == window) == fullscreen) {
    1.24          return;
    1.25      }
    1.26  
    1.27      /* See if there are any fullscreen windows */
    1.28      for (other = _this->windows; other; other = other->next) {
    1.29 -        if (FULLSCREEN_VISIBLE(other) &&
    1.30 -            SDL_GetDisplayForWindow(other) == display) {
    1.31 +        SDL_bool setDisplayMode = SDL_FALSE;
    1.32 +
    1.33 +        if (other == window) {
    1.34 +            setDisplayMode = fullscreen;
    1.35 +        } else if (FULLSCREEN_VISIBLE(other) &&
    1.36 +                   SDL_GetDisplayForWindow(other) == display) {
    1.37 +            setDisplayMode = SDL_TRUE;
    1.38 +        }
    1.39 +
    1.40 +        if (setDisplayMode) {
    1.41              SDL_DisplayMode fullscreen_mode;
    1.42 +
    1.43              if (SDL_GetWindowDisplayMode(other, &fullscreen_mode) == 0) {
    1.44                  SDL_bool resized = SDL_TRUE;
    1.45  
    1.46 @@ -1144,7 +1153,7 @@
    1.47  
    1.48          displayIndex = SDL_GetIndexOfDisplay(display);
    1.49          SDL_GetDisplayBounds(displayIndex, &bounds);
    1.50 -        if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
    1.51 +        if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISCENTERED(x)) {
    1.52              window->x = bounds.x + (bounds.w - w) / 2;
    1.53          }
    1.54          if (SDL_WINDOWPOS_ISUNDEFINED(y) || SDL_WINDOWPOS_ISCENTERED(y)) {
    1.55 @@ -1512,6 +1521,8 @@
    1.56          return;
    1.57      }
    1.58  
    1.59 +    SDL_UpdateFullscreenMode(window, SDL_FALSE);
    1.60 +
    1.61      if (_this->HideWindow) {
    1.62          _this->HideWindow(_this, window);
    1.63      }
    1.64 @@ -1528,9 +1539,6 @@
    1.65      }
    1.66      if (_this->RaiseWindow) {
    1.67          _this->RaiseWindow(_this, window);
    1.68 -    } else {
    1.69 -        /* FIXME: What we really want is a way to request focus */
    1.70 -        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
    1.71      }
    1.72  }
    1.73  
    1.74 @@ -1557,6 +1565,8 @@
    1.75          return;
    1.76      }
    1.77  
    1.78 +    SDL_UpdateFullscreenMode(window, SDL_FALSE);
    1.79 +
    1.80      if (_this->MinimizeWindow) {
    1.81          _this->MinimizeWindow(_this, window);
    1.82      }
    1.83 @@ -1574,7 +1584,6 @@
    1.84      if (_this->RestoreWindow) {
    1.85          _this->RestoreWindow(_this, window);
    1.86      }
    1.87 -    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
    1.88  }
    1.89  
    1.90  int
    1.91 @@ -1582,10 +1591,7 @@
    1.92  {
    1.93      CHECK_WINDOW_MAGIC(window, -1);
    1.94  
    1.95 -    if (fullscreen) {
    1.96 -        fullscreen = SDL_WINDOW_FULLSCREEN;
    1.97 -    }
    1.98 -    if ((window->flags & SDL_WINDOW_FULLSCREEN) == fullscreen) {
    1.99 +    if (!!fullscreen == !!(window->flags & SDL_WINDOW_FULLSCREEN)) {
   1.100          return 0;
   1.101      }
   1.102      if (fullscreen) {
   1.103 @@ -1593,7 +1599,7 @@
   1.104      } else {
   1.105          window->flags &= ~SDL_WINDOW_FULLSCREEN;
   1.106      }
   1.107 -    SDL_UpdateFullscreenMode(window);
   1.108 +    SDL_UpdateFullscreenMode(window, FULLSCREEN_VISIBLE(window));
   1.109  
   1.110      return 0;
   1.111  }
   1.112 @@ -1682,7 +1688,7 @@
   1.113  {
   1.114      CHECK_WINDOW_MAGIC(window, );
   1.115  
   1.116 -    if ((!!grabbed == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) {
   1.117 +    if (!!grabbed == !!(window->flags & SDL_WINDOW_INPUT_GRABBED)) {
   1.118          return;
   1.119      }
   1.120      if (grabbed) {
   1.121 @@ -1704,14 +1710,13 @@
   1.122  void
   1.123  SDL_OnWindowShown(SDL_Window * window)
   1.124  {
   1.125 -    SDL_RaiseWindow(window);
   1.126 -    SDL_UpdateFullscreenMode(window);
   1.127 +    SDL_OnWindowRestored(window);
   1.128  }
   1.129  
   1.130  void
   1.131  SDL_OnWindowHidden(SDL_Window * window)
   1.132  {
   1.133 -    SDL_UpdateFullscreenMode(window);
   1.134 +    SDL_UpdateFullscreenMode(window, SDL_FALSE);
   1.135  }
   1.136  
   1.137  void
   1.138 @@ -1724,14 +1729,17 @@
   1.139  void
   1.140  SDL_OnWindowMinimized(SDL_Window * window)
   1.141  {
   1.142 -    SDL_UpdateFullscreenMode(window);
   1.143 +    SDL_UpdateFullscreenMode(window, SDL_FALSE);
   1.144  }
   1.145  
   1.146  void
   1.147  SDL_OnWindowRestored(SDL_Window * window)
   1.148  {
   1.149      SDL_RaiseWindow(window);
   1.150 -    SDL_UpdateFullscreenMode(window);
   1.151 +
   1.152 +    if (FULLSCREEN_VISIBLE(window)) {
   1.153 +        SDL_UpdateFullscreenMode(window, SDL_TRUE);
   1.154 +    }
   1.155  }
   1.156  
   1.157  void
     2.1 --- a/src/video/cocoa/SDL_cocoawindow.h	Sun Feb 27 20:06:45 2011 -0800
     2.2 +++ b/src/video/cocoa/SDL_cocoawindow.h	Sun Feb 27 21:17:06 2011 -0800
     2.3 @@ -49,8 +49,6 @@
     2.4  -(void) windowDidDeminiaturize:(NSNotification *) aNotification;
     2.5  -(void) windowDidBecomeKey:(NSNotification *) aNotification;
     2.6  -(void) windowDidResignKey:(NSNotification *) aNotification;
     2.7 --(void) windowDidHide:(NSNotification *) aNotification;
     2.8 --(void) windowDidUnhide:(NSNotification *) aNotification;
     2.9  
    2.10  /* Window event handling */
    2.11  -(void) mouseDown:(NSEvent *) theEvent;
     3.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Sun Feb 27 20:06:45 2011 -0800
     3.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sun Feb 27 21:17:06 2011 -0800
     3.3 @@ -63,8 +63,6 @@
     3.4      } else {
     3.5          [window setDelegate:self];
     3.6      }
     3.7 -    [center addObserver:self selector:@selector(windowDidHide:) name:NSApplicationDidHideNotification object:NSApp];
     3.8 -    [center addObserver:self selector:@selector(windowDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp];
     3.9  
    3.10      [window setNextResponder:self];
    3.11      [window setAcceptsMouseMovedEvents:YES];
    3.12 @@ -94,8 +92,6 @@
    3.13      } else {
    3.14          [window setDelegate:nil];
    3.15      }
    3.16 -    [center removeObserver:self name:NSApplicationDidHideNotification object:NSApp];
    3.17 -    [center removeObserver:self name:NSApplicationDidUnhideNotification object:NSApp];
    3.18  
    3.19      if ([window nextResponder] == self) {
    3.20          [window setNextResponder:nil];
    3.21 @@ -206,16 +202,6 @@
    3.22      }
    3.23  }
    3.24  
    3.25 -- (void)windowDidHide:(NSNotification *)aNotification
    3.26 -{
    3.27 -    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
    3.28 -}
    3.29 -
    3.30 -- (void)windowDidUnhide:(NSNotification *)aNotification
    3.31 -{
    3.32 -    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
    3.33 -}
    3.34 -
    3.35  - (void)mouseDown:(NSEvent *)theEvent
    3.36  {
    3.37      int button;
     4.1 --- a/test/common.c	Sun Feb 27 20:06:45 2011 -0800
     4.2 +++ b/test/common.c	Sun Feb 27 21:17:06 2011 -0800
     4.3 @@ -810,6 +810,11 @@
     4.4  static void
     4.5  PrintEvent(SDL_Event * event)
     4.6  {
     4.7 +    if (event->type == SDL_MOUSEMOTION) {
     4.8 +        /* Mouse motion is really spammy */
     4.9 +        return;
    4.10 +    }
    4.11 +
    4.12      fprintf(stderr, "SDL EVENT: ");
    4.13      switch (event->type) {
    4.14      case SDL_WINDOWEVENT: