SDL_WINDOWEVENT_CLOSE
vs SDL_QUIT
What's the difference between SDL_WINDOWEVENT_CLOSE
and SDL_QUIT
?
While SDL_WINDOWEVENT_CLOSE
and SDL_QUIT
are both related to closing windows, they serve different purposes.
SDL_WINDOWEVENT_CLOSE
This event is specific to an individual SDL window. It occurs when the user attempts to close a window (e.g., by clicking the close button). The event contains the windowID
, allowing you to determine which window the action applies to.
if (event.type == SDL_WINDOWEVENT &&
event.window.event == SDL_WINDOWEVENT_CLOSE) {
std::cout << "User attempted to close window ID: "
<< event.window.windowID << '\n';
}
SDL_QUIT
This event is more general and signals the application should terminate. It typically occurs when:
- The last window is closed.
- The user sends a termination signal (e.g., pressing Ctrl+C in the console).
if (event.type == SDL_QUIT) {
std::cout << "Application quit signal received\n";
}
Key Differences
SDL_WINDOWEVENT_CLOSE
is window-specific, whileSDL_QUIT
affects the entire application.- If you close all SDL windows, SDL usually triggers
SDL_QUIT
.
Understanding this distinction helps in multi-window applications where closing one window doesn't necessarily mean quitting the app.
Window Events and Window IDs
Discover how to monitor and respond to window state changes in SDL applications