diff options
| author | spycrab <spycrab@users.noreply.github.com> | 2018-05-22 21:30:54 +0200 |
|---|---|---|
| committer | spycrab <spycrab@users.noreply.github.com> | 2018-05-28 21:47:46 +0200 |
| commit | 112a174ae1c4ea3bc7d1592e3f6fc0be7e963f34 (patch) | |
| tree | e8c1d67402152d8d4148466f2091aac2de3455a6 /Source/Core/DolphinQt2/MainWindow.cpp | |
| parent | 0e9255c46999865a2d2e8a748ecccdfec7f6d476 (diff) | |
Qt/Unix: Implement signal handler
Diffstat (limited to 'Source/Core/DolphinQt2/MainWindow.cpp')
| -rw-r--r-- | Source/Core/DolphinQt2/MainWindow.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp index 90bf1b2d20..3cf69295ae 100644 --- a/Source/Core/DolphinQt2/MainWindow.cpp +++ b/Source/Core/DolphinQt2/MainWindow.cpp @@ -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); |
