Handle window close cleanly and show exit popup selection
This commit is contained in:
@ -398,13 +398,14 @@ bool ApplicationManager::initializeManagers() {
|
||||
// Forward all window events to StateManager
|
||||
if (!m_stateManager) return;
|
||||
SDL_Event ev{};
|
||||
ev.type = SDL_EVENT_WINDOW_RESIZED; // generic mapping; handlers can inspect inner fields
|
||||
ev.type = we.type;
|
||||
ev.window = we;
|
||||
m_stateManager->handleEvent(ev);
|
||||
});
|
||||
|
||||
m_inputManager->registerQuitHandler([this](){
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[QUIT] InputManager quit handler invoked - setting running=false");
|
||||
traceFile("ApplicationManager: quit handler -> m_running=false");
|
||||
m_running = false;
|
||||
});
|
||||
}
|
||||
|
||||
@ -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