I also ran into this problem, and the documentation is a little sparse on the topic so I ended up here.
The summary of the problem is:
- If you have only one Window, clicking the X button will trigger an
SDL_QUIT
event.
- If you have two or more windows, clicking the X button will trigger an
SDL_WINDOWEVENT
event, with an internal type of SDL_WINDOWEVENT_CLOSE
.
So if your typical code for single-window quit events might look something like this:
SDL_Event e;
while (SDL_PollEvent(&e))
{
if (e.type == SDL_QUIT)
{
// ... Handle close ...
}
}
The multi-window equivalent would be:
SDL_Event e;
while (SDL_PollEvent(&e))
{
if (e.type == SDL_WINDOWEVENT
&& e.window.event == SDL_WINDOWEVENT_CLOSE)
{
// ... Handle window close for each window ...
// Note, you can also check e.window.windowID to check which
// of your windows the event came from.
// e.g.:
if (SDL_GetWindowID(myWindowA) == e.window.windowID)
{
// ... close window A ...
}
}
}
Note that on the last window, you will again receive SDL_QUIT
because it's now the only active window - so best to structure your code in a way that correctly handles both depending on the circumstances.
See docs for more info.