Added handleCloseRequested() callback to allow applications to intercept close requests.
This commit is contained in:
parent
da8d1589b3
commit
69fdae991a
@ -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;
|
||||
|
@ -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({
|
||||
|
Loading…
x
Reference in New Issue
Block a user