Qt/Unix: Implement signal handler

This commit is contained in:
spycrab
2018-05-22 21:30:54 +02:00
parent 0e9255c469
commit 112a174ae1
5 changed files with 119 additions and 1 deletions

View File

@ -1,4 +1,3 @@
// Copyright 2015 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
@ -20,6 +19,12 @@
#include <future>
#include <optional>
#if defined(__unix__) || defined(__unix) || defined(__APPLE__)
#include <signal.h>
#include "QtUtils/SignalDaemon.h"
#endif
#include "Common/Version.h"
#include "Core/Boot/Boot.h"
@ -86,6 +91,23 @@
#include "UICommon/X11Utils.h"
#endif
#if defined(__unix__) || defined(__unix) || defined(__APPLE__)
void MainWindow::OnSignal()
{
close();
}
static void InstallSignalHandler()
{
struct sigaction sa;
sa.sa_handler = &SignalDaemon::HandleInterrupt;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESETHAND;
sigaction(SIGINT, &sa, nullptr);
sigaction(SIGTERM, &sa, nullptr);
}
#endif
MainWindow::MainWindow(std::unique_ptr<BootParameters> boot_parameters) : QMainWindow(nullptr)
{
setWindowTitle(QString::fromStdString(Common::scm_rev_str));
@ -109,6 +131,14 @@ MainWindow::MainWindow(std::unique_ptr<BootParameters> boot_parameters) : QMainW
NetPlayInit();
#if defined(__unix__) || defined(__unix) || defined(__APPLE__)
auto* daemon = new SignalDaemon(this);
connect(daemon, &SignalDaemon::InterruptReceived, this, &MainWindow::OnSignal);
InstallSignalHandler();
#endif
if (boot_parameters)
m_pending_boot = std::move(boot_parameters);