Fixed minimizing fullscreen windows.
authorSam Lantinga <slouken@libsdl.org>
Sun, 27 Feb 2011 21:17:06 -0800
changeset 5404 6717e01acbe0
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
--- a/src/video/SDL_video.c	Sun Feb 27 20:06:45 2011 -0800
+++ b/src/video/SDL_video.c	Sun Feb 27 21:17:06 2011 -0800
@@ -1018,12 +1018,12 @@
 }
 
 static void
-SDL_UpdateFullscreenMode(SDL_Window * window)
+SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
 {
     SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     SDL_Window *other;
 
-    if (FULLSCREEN_VISIBLE(window)) {
+    if (fullscreen) {
         /* Hide any other fullscreen windows */
         if (display->fullscreen_window &&
             display->fullscreen_window != window) {
@@ -1032,15 +1032,24 @@
     }
 
     /* See if anything needs to be done now */
-    if ((display->fullscreen_window == window) == FULLSCREEN_VISIBLE(window)) {
+    if ((display->fullscreen_window == window) == fullscreen) {
         return;
     }
 
     /* See if there are any fullscreen windows */
     for (other = _this->windows; other; other = other->next) {
-        if (FULLSCREEN_VISIBLE(other) &&
-            SDL_GetDisplayForWindow(other) == display) {
+        SDL_bool setDisplayMode = SDL_FALSE;
+
+        if (other == window) {
+            setDisplayMode = fullscreen;
+        } else if (FULLSCREEN_VISIBLE(other) &&
+                   SDL_GetDisplayForWindow(other) == display) {
+            setDisplayMode = SDL_TRUE;
+        }
+
+        if (setDisplayMode) {
             SDL_DisplayMode fullscreen_mode;
+
             if (SDL_GetWindowDisplayMode(other, &fullscreen_mode) == 0) {
                 SDL_bool resized = SDL_TRUE;
 
@@ -1144,7 +1153,7 @@
 
         displayIndex = SDL_GetIndexOfDisplay(display);
         SDL_GetDisplayBounds(displayIndex, &bounds);
-        if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
+        if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISCENTERED(x)) {
             window->x = bounds.x + (bounds.w - w) / 2;
         }
         if (SDL_WINDOWPOS_ISUNDEFINED(y) || SDL_WINDOWPOS_ISCENTERED(y)) {
@@ -1512,6 +1521,8 @@
         return;
     }
 
+    SDL_UpdateFullscreenMode(window, SDL_FALSE);
+
     if (_this->HideWindow) {
         _this->HideWindow(_this, window);
     }
@@ -1528,9 +1539,6 @@
     }
     if (_this->RaiseWindow) {
         _this->RaiseWindow(_this, window);
-    } else {
-        /* FIXME: What we really want is a way to request focus */
-        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
     }
 }
 
@@ -1557,6 +1565,8 @@
         return;
     }
 
+    SDL_UpdateFullscreenMode(window, SDL_FALSE);
+
     if (_this->MinimizeWindow) {
         _this->MinimizeWindow(_this, window);
     }
@@ -1574,7 +1584,6 @@
     if (_this->RestoreWindow) {
         _this->RestoreWindow(_this, window);
     }
-    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
 }
 
 int
@@ -1582,10 +1591,7 @@
 {
     CHECK_WINDOW_MAGIC(window, -1);
 
-    if (fullscreen) {
-        fullscreen = SDL_WINDOW_FULLSCREEN;
-    }
-    if ((window->flags & SDL_WINDOW_FULLSCREEN) == fullscreen) {
+    if (!!fullscreen == !!(window->flags & SDL_WINDOW_FULLSCREEN)) {
         return 0;
     }
     if (fullscreen) {
@@ -1593,7 +1599,7 @@
     } else {
         window->flags &= ~SDL_WINDOW_FULLSCREEN;
     }
-    SDL_UpdateFullscreenMode(window);
+    SDL_UpdateFullscreenMode(window, FULLSCREEN_VISIBLE(window));
 
     return 0;
 }
@@ -1682,7 +1688,7 @@
 {
     CHECK_WINDOW_MAGIC(window, );
 
-    if ((!!grabbed == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) {
+    if (!!grabbed == !!(window->flags & SDL_WINDOW_INPUT_GRABBED)) {
         return;
     }
     if (grabbed) {
@@ -1704,14 +1710,13 @@
 void
 SDL_OnWindowShown(SDL_Window * window)
 {
-    SDL_RaiseWindow(window);
-    SDL_UpdateFullscreenMode(window);
+    SDL_OnWindowRestored(window);
 }
 
 void
 SDL_OnWindowHidden(SDL_Window * window)
 {
-    SDL_UpdateFullscreenMode(window);
+    SDL_UpdateFullscreenMode(window, SDL_FALSE);
 }
 
 void
@@ -1724,14 +1729,17 @@
 void
 SDL_OnWindowMinimized(SDL_Window * window)
 {
-    SDL_UpdateFullscreenMode(window);
+    SDL_UpdateFullscreenMode(window, SDL_FALSE);
 }
 
 void
 SDL_OnWindowRestored(SDL_Window * window)
 {
     SDL_RaiseWindow(window);
-    SDL_UpdateFullscreenMode(window);
+
+    if (FULLSCREEN_VISIBLE(window)) {
+        SDL_UpdateFullscreenMode(window, SDL_TRUE);
+    }
 }
 
 void
--- a/src/video/cocoa/SDL_cocoawindow.h	Sun Feb 27 20:06:45 2011 -0800
+++ b/src/video/cocoa/SDL_cocoawindow.h	Sun Feb 27 21:17:06 2011 -0800
@@ -49,8 +49,6 @@
 -(void) windowDidDeminiaturize:(NSNotification *) aNotification;
 -(void) windowDidBecomeKey:(NSNotification *) aNotification;
 -(void) windowDidResignKey:(NSNotification *) aNotification;
--(void) windowDidHide:(NSNotification *) aNotification;
--(void) windowDidUnhide:(NSNotification *) aNotification;
 
 /* Window event handling */
 -(void) mouseDown:(NSEvent *) theEvent;
--- a/src/video/cocoa/SDL_cocoawindow.m	Sun Feb 27 20:06:45 2011 -0800
+++ b/src/video/cocoa/SDL_cocoawindow.m	Sun Feb 27 21:17:06 2011 -0800
@@ -63,8 +63,6 @@
     } else {
         [window setDelegate:self];
     }
-    [center addObserver:self selector:@selector(windowDidHide:) name:NSApplicationDidHideNotification object:NSApp];
-    [center addObserver:self selector:@selector(windowDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp];
 
     [window setNextResponder:self];
     [window setAcceptsMouseMovedEvents:YES];
@@ -94,8 +92,6 @@
     } else {
         [window setDelegate:nil];
     }
-    [center removeObserver:self name:NSApplicationDidHideNotification object:NSApp];
-    [center removeObserver:self name:NSApplicationDidUnhideNotification object:NSApp];
 
     if ([window nextResponder] == self) {
         [window setNextResponder:nil];
@@ -206,16 +202,6 @@
     }
 }
 
-- (void)windowDidHide:(NSNotification *)aNotification
-{
-    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
-}
-
-- (void)windowDidUnhide:(NSNotification *)aNotification
-{
-    SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
-}
-
 - (void)mouseDown:(NSEvent *)theEvent
 {
     int button;
--- a/test/common.c	Sun Feb 27 20:06:45 2011 -0800
+++ b/test/common.c	Sun Feb 27 21:17:06 2011 -0800
@@ -810,6 +810,11 @@
 static void
 PrintEvent(SDL_Event * event)
 {
+    if (event->type == SDL_MOUSEMOTION) {
+        /* Mouse motion is really spammy */
+        return;
+    }
+
     fprintf(stderr, "SDL EVENT: ");
     switch (event->type) {
     case SDL_WINDOWEVENT: