aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Morris <ben@bendmorris.com>2021-01-09 18:48:40 -0800
committerGitHub <noreply@github.com>2021-01-10 03:48:40 +0100
commitb402cb19b208dba0fe9c3c530363f41710195d65 (patch)
tree8799776ea7e74b7fb046e0e23df093c747c3dcef
parent30a0569c87faf39d7de7912038c44fcbe05db255 (diff)
quit on sigint (#934)
* quit on sigint * formatting
-rw-r--r--src/frontend/qt_sdl/main.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp
index d30a6db..f0185cc 100644
--- a/src/frontend/qt_sdl/main.cpp
+++ b/src/frontend/qt_sdl/main.cpp
@@ -35,6 +35,12 @@
#include <QKeyEvent>
#include <QMimeData>
#include <QVector>
+#ifndef _WIN32
+#include <QSocketNotifier>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <signal.h>
+#endif
#include <SDL2/SDL.h>
@@ -1014,9 +1020,37 @@ void ScreenPanelGL::onScreenLayoutChanged()
setupScreenLayout();
}
+#ifndef _WIN32
+static int signalFd[2];
+QSocketNotifier *signalSn;
+
+static void signalHandler(int)
+{
+ char a = 1;
+ write(signalFd[0], &a, sizeof(a));
+}
+#endif
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
{
+#ifndef _WIN32
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, signalFd))
+ {
+ qFatal("Couldn't create socketpair");
+ }
+
+ signalSn = new QSocketNotifier(signalFd[1], QSocketNotifier::Read, this);
+ connect(signalSn, SIGNAL(activated(int)), this, SLOT(onQuit()));
+
+ struct sigaction sa;
+
+ sa.sa_handler = signalHandler;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_flags |= SA_RESTART;
+ sigaction(SIGINT, &sa, 0);
+#endif
+
setWindowTitle("melonDS " MELONDS_VERSION);
setAttribute(Qt::WA_DeleteOnClose);
setAcceptDrops(true);
@@ -1792,6 +1826,9 @@ void MainWindow::onImportSavefile()
void MainWindow::onQuit()
{
+#ifndef _WIN32
+ signalSn->setEnabled(false);
+#endif
QApplication::quit();
}