From 69fdae991ae9c49226b97cb34e7f379d67c8f1ac Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Tue, 23 Sep 2025 10:43:48 +0200 Subject: [PATCH] Added handleCloseRequested() callback to allow applications to intercept close requests. --- private/raid/application.cpp | 14 ++++++++++++++ public/raid/application.hpp | 2 ++ 2 files changed, 16 insertions(+) diff --git a/private/raid/application.cpp b/private/raid/application.cpp index 5840764..9f3682d 100644 --- a/private/raid/application.cpp +++ b/private/raid/application.cpp @@ -339,6 +339,11 @@ void Application::handleSDLEvent(const SDL_Event& event) case SDL_EVENT_QUIT: mRunning = false; return; + case SDL_EVENT_WINDOW_CLOSE_REQUESTED: + if (SDL_GetWindowFromID(event.window.windowID) == mWindow) { + handleCloseRequested(); + } + break; default: ImGui_ImplSDL3_ProcessEvent(&event); break; @@ -350,6 +355,13 @@ void Application::handleSDLError(const char* message) msgError("SDL: {}", message); } +void Application::handleCloseRequested() +{ + SDL_Event quitEvent; + quitEvent.type = SDL_EVENT_QUIT; + SDL_PushEvent(&quitEvent); +} + bool Application::init() { auto addConfigDir = [&](const fs::path& path) @@ -516,6 +528,8 @@ bool Application::initSDL() return false; } + SDL_SetHint(SDL_HINT_QUIT_ON_LAST_WINDOW_CLOSE, "0"); // let us handle ourselves + msgInfo("SDL video driver: {}", SDL_GetCurrentVideoDriver()); SDL_WindowFlags windowFlags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY; diff --git a/public/raid/application.hpp b/public/raid/application.hpp index 4dbd959..3cf67bd 100644 --- a/public/raid/application.hpp +++ b/public/raid/application.hpp @@ -152,6 +152,8 @@ protected: virtual void handleSDLEvent(const SDL_Event& event); virtual void handleSDLError(const char* message); + virtual void handleCloseRequested(); + void msgInfo(const char* text) { handleMessage({