diff --git a/include/GuiApplication.h b/include/GuiApplication.h index 3a085149980..e813e4f0b4e 100644 --- a/include/GuiApplication.h +++ b/include/GuiApplication.h @@ -67,11 +67,17 @@ class LMMS_EXPORT GuiApplication : public QObject AutomationEditorWindow* automationEditor() { return m_automationEditor; } ControllerRackView* getControllerRackView() { return m_controllerRackView; } + void sendInterrupt(int signal); + public slots: void displayInitProgress(const QString &msg); private slots: void childDestroyed(QObject *obj); + void processInterrupt(int signal); + +signals: + void interruptOccurred(int signal); private: static GuiApplication* s_instance; diff --git a/src/core/main.cpp b/src/core/main.cpp index 20bebf34954..ad764b27465 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -99,9 +99,14 @@ void fpeHandler( int signum ) { } #endif -void interruptHandler(int unused) { - if(qApp != nullptr) qApp->exit(3); - exit(3); +void interruptHandler(int code) { + using namespace lmms::gui; + + if(getGUI() != nullptr) { + getGUI()->sendInterrupt(code); + } else { + exit(3); + } } static inline QString baseName( const QString & file ) diff --git a/src/gui/GuiApplication.cpp b/src/gui/GuiApplication.cpp index 31b989a92f2..5b22eccbf0d 100644 --- a/src/gui/GuiApplication.cpp +++ b/src/gui/GuiApplication.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #ifdef LMMS_BUILD_WIN32 #include @@ -75,6 +76,9 @@ GuiApplication* GuiApplication::instance() GuiApplication::GuiApplication() { + // Add interrupt handler as early as possible + connect(this, SIGNAL(interruptOccurred(int)), this, SLOT(processInterrupt(int)), Qt::QueuedConnection); + // prompt the user to create the LMMS working directory (e.g. ~/Documents/lmms) if it doesn't exist if ( !ConfigManager::inst()->hasWorkingDir() && QMessageBox::question( nullptr, @@ -240,6 +244,19 @@ void GuiApplication::childDestroyed(QObject *obj) } } +void GuiApplication::sendInterrupt(int signal) { + emit interruptOccurred(signal); +} + +// Slot for handling interrupts from main() +void GuiApplication::processInterrupt(int signal) { + switch(signal) { + case SIGINT: + // add last minute resource clean-up goes here + qApp->exit(3); + } +} + #ifdef LMMS_BUILD_WIN32 /*! * @brief Returns the Windows System font.