Window Events and Window IDs

SDL_WINDOWEVENT_CLOSE vs SDL_QUIT

What's the difference between SDL_WINDOWEVENT_CLOSE and SDL_QUIT?

Abstract art representing computer programming

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, while SDL_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.

This Question is from the Lesson:

Window Events and Window IDs

Discover how to monitor and respond to window state changes in SDL applications

Answers to questions are automatically generated and may not have been reviewed.

This Question is from the Lesson:

Window Events and Window IDs

Discover how to monitor and respond to window state changes in SDL applications

sdl2-promo.jpg
Part of the course:

Game Dev with SDL2

Learn C++ and SDL development by creating hands on, practical projects inspired by classic retro games

Free, unlimited access

This course includes:

  • 62 Lessons
  • 100+ Code Samples
  • 91% Positive Reviews
  • Regularly Updated
  • Help and FAQ
Free, Unlimited Access

Professional C++

Comprehensive course covering advanced concepts, and how to use them on large-scale projects.

Screenshot from Warhammer: Total War
Screenshot from Tomb Raider
Screenshot from Jedi: Fallen Order
Contact|Privacy Policy|Terms of Use
Copyright © 2024 - All Rights Reserved