Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
When the last window is closed and the SDL_WINDOWEVENT_CLOSE event is…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
krogoway committed Jan 27, 2011
1 parent 9d141fa commit 0a78a09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/events/SDL_windowevents.c
Expand Up @@ -176,6 +176,14 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,

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);
}

Expand Down
7 changes: 6 additions & 1 deletion test/common.c
Expand Up @@ -1038,7 +1038,12 @@ CommonEvent(CommonState * state, SDL_Event * event, int *done)
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;
Expand Down

0 comments on commit 0a78a09

Please sign in to comment.