When the last window is closed and the SDL_WINDOWEVENT_CLOSE event is sent, send the SDL_QUIT event.
authorkrogoway
Thu, 27 Jan 2011 15:58:30 -0600
changeset 5113 686d795b1b29
parent 5112 39772ccf7ddd
child 5114 e337f792c6a7
When the last window is closed and the SDL_WINDOWEVENT_CLOSE event is sent, send the SDL_QUIT event. Common.c now destroys the SDL_Window upon a SDL_WINDOWEVENT_CLOSE event to ensure that all windows get closed properly and the new code to handle the last window closes gets executed.
src/events/SDL_windowevents.c
test/common.c
--- a/src/events/SDL_windowevents.c	Thu Jan 27 14:54:20 2011 -0800
+++ b/src/events/SDL_windowevents.c	Thu Jan 27 15:58:30 2011 -0600
@@ -176,6 +176,14 @@
 
         posted = (SDL_PushEvent(&event) > 0);
     }
+	
+	if (windowevent == SDL_WINDOWEVENT_CLOSE) {
+		if ( !window->prev && !window->next ) {
+			// This is the last window in the list so send the SDL_QUIT event
+			SDL_SendQuit();
+		}
+	}
+
     return (posted);
 }
 
--- a/test/common.c	Thu Jan 27 14:54:20 2011 -0800
+++ b/test/common.c	Thu Jan 27 15:58:30 2011 -0600
@@ -1038,7 +1038,12 @@
     case SDL_WINDOWEVENT:
         switch (event->window.event) {
         case SDL_WINDOWEVENT_CLOSE:
-            *done = 1;
+			{
+				SDL_Window *pWindow = SDL_GetWindowFromID(event->window.windowID);
+				if ( pWindow ) {
+					SDL_DestroyWindow( pWindow );
+				}
+			}
             break;
         }
         break;