diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 56bb4e457..428748b65 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -6666,6 +6666,10 @@ bool FurnaceGUI::finish() { return true; } +void FurnaceGUI::requestQuit() { + quit=true; +} + FurnaceGUI::FurnaceGUI(): e(NULL), renderBackend(GUI_BACKEND_SDL), diff --git a/src/gui/gui.h b/src/gui/gui.h index df778e3df..83c5a380a 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -2306,6 +2306,7 @@ class FurnaceGUI { bool loop(); bool finish(); bool init(); + void requestQuit(); FurnaceGUI(); }; diff --git a/src/main.cpp b/src/main.cpp index e58a455ac..78dd2d2ac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,7 +36,10 @@ typedef HRESULT (WINAPI *SPDA)(PROCESS_DPI_AWARENESS); #else +#include #include + +struct sigaction termsa; #endif #include "cli/cli.h" @@ -356,6 +359,14 @@ void reportError(String what) { } #endif +#ifndef _WIN32 +#ifdef HAVE_GUI +static void handleTermGUI(int) { + g.requestQuit(); +} +#endif +#endif + // TODO: CoInitializeEx on Windows? // TODO: add crash log int main(int argc, char** argv) { @@ -646,6 +657,11 @@ int main(int argc, char** argv) { g.setFileName(fileName); } + sigemptyset(&termsa.sa_mask); + termsa.sa_flags=0; + termsa.sa_handler=handleTermGUI; + sigaction(SIGTERM,&termsa,NULL); + g.loop(); logI("closing GUI."); g.finish();