From 494188371b06e5ab6f367877a99650b06187af10 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Wed, 1 Feb 2023 12:48:36 +0100 Subject: [PATCH] Automatically abort ongoing shutdown when interacting with the mouse or the keyboard (closes #2393) --- src/engine/openspaceengine.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 36a9e8e3d5..4570dea0a1 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1362,6 +1362,17 @@ void OpenSpaceEngine::keyboardCallback(Key key, KeyModifier mod, KeyAction actio return; } + // We need to do this check before the callback functions as we would otherwise + // immediately cancel a shutdown if someone pressed the ESC key. Similar argument for + // only checking for the Press action. Since the 'Press' of ESC will trigger the + // shutdown, the 'Release' in some frame later would cancel it immediately again + if (action == KeyAction::Press && _shutdown.inShutdown) { + _shutdown.inShutdown = false; + global::eventEngine->publishEvent( + events::EventApplicationShutdown::State::Aborted + ); + } + using F = global::callback::KeyboardCallback; for (const F& func : *global::callback::keyboard) { const bool isConsumed = func(key, mod, action, isGuiWindow); @@ -1401,6 +1412,13 @@ void OpenSpaceEngine::charCallback(unsigned int codepoint, KeyModifier modifier, global::luaConsole->charCallback(codepoint, modifier); global::interactionMonitor->markInteraction(); + + if (_shutdown.inShutdown) { + _shutdown.inShutdown = false; + global::eventEngine->publishEvent( + events::EventApplicationShutdown::State::Aborted + ); + } } void OpenSpaceEngine::mouseButtonCallback(MouseButton button, MouseAction action, @@ -1441,6 +1459,13 @@ void OpenSpaceEngine::mouseButtonCallback(MouseButton button, MouseAction action global::navigationHandler->mouseButtonCallback(button, action); global::interactionMonitor->markInteraction(); + + if (_shutdown.inShutdown) { + _shutdown.inShutdown = false; + global::eventEngine->publishEvent( + events::EventApplicationShutdown::State::Aborted + ); + } } void OpenSpaceEngine::mousePositionCallback(double x, double y, IsGuiWindow isGuiWindow) {