From b402cb19b208dba0fe9c3c530363f41710195d65 Mon Sep 17 00:00:00 2001 From: Ben Morris Date: Sat, 9 Jan 2021 18:48:40 -0800 Subject: [PATCH] quit on sigint (#934) * quit on sigint * formatting --- src/frontend/qt_sdl/main.cpp | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index d30a6dbc..f0185cc9 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -35,6 +35,12 @@ #include #include #include +#ifndef _WIN32 +#include +#include +#include +#include +#endif #include @@ -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(); }