Handle window close cleanly and show exit popup selection
This commit is contained in:
@ -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();
|
||||
|
||||
Reference in New Issue
Block a user