Handle window close cleanly and show exit popup selection

This commit is contained in:
2025-11-22 11:43:20 +01:00
parent a257c5cd79
commit 838b5b1836
6 changed files with 39 additions and 15 deletions

View File

@ -22,16 +22,8 @@ void InputManager::processEvents() {
}
switch (event.type) {
case SDL_EVENT_QUIT:
m_shouldQuit = true;
for (auto& handler : m_quitHandlers) {
try {
// Trace quit event handling
FILE* f = fopen("tetris_trace.log", "a"); if (f) { fprintf(f, "InputManager: SDL_EVENT_QUIT polled\n"); fclose(f); }
handler();
} catch (const std::exception& e) {
SDL_LogError(SDL_LOG_CATEGORY_INPUT, "Exception in quit handler: %s", e.what());
}
}
case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
handleQuitEvent();
break;
case SDL_EVENT_KEY_DOWN:
@ -254,6 +246,10 @@ void InputManager::handleMouseMotionEvent(const SDL_MouseMotionEvent& event) {
}
void InputManager::handleWindowEvent(const SDL_WindowEvent& event) {
if (event.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED) {
handleQuitEvent();
}
// Notify handlers
for (auto& handler : m_windowEventHandlers) {
try {
@ -353,6 +349,11 @@ void InputManager::reset() {
}
void InputManager::handleQuitEvent() {
FILE* f = fopen("tetris_trace.log", "a");
if (f) {
fprintf(f, "InputManager::handleQuitEvent invoked\n");
fclose(f);
}
m_shouldQuit = true;
for (auto& handler : m_quitHandlers) {
handler();