1
0
Fork 0

[Launcher] Handle ^C.

This commit is contained in:
Kitteh 2018-11-11 13:43:18 +00:00
parent 01fba29efd
commit 6c46849ed7
2 changed files with 30 additions and 0 deletions

View file

@ -137,9 +137,11 @@ MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent)
MpvPlayerBackend::~MpvPlayerBackend() MpvPlayerBackend::~MpvPlayerBackend()
{ {
printf("Shutting down...\n");
SetDPMS(true); SetDPMS(true);
mpv_render_context_free(mpv_gl); mpv_render_context_free(mpv_gl);
mpv_terminate_destroy(mpv); mpv_terminate_destroy(mpv);
printf("MPV terminated.\n");
} }
void MpvPlayerBackend::on_update(void* ctx) void MpvPlayerBackend::on_update(void* ctx)

View file

@ -16,10 +16,38 @@
#include "setenv_mingw.hpp" #include "setenv_mingw.hpp"
#endif #endif
#ifdef __linux__
#include <initializer_list>
#include <signal.h>
#include <unistd.h>
void catchUnixSignals(std::initializer_list<int> quitSignals) {
auto handler = [](int sig) -> void {
QCoreApplication::quit();
};
sigset_t blocking_mask;
sigemptyset(&blocking_mask);
for (auto sig : quitSignals)
sigaddset(&blocking_mask, sig);
struct sigaction sa;
sa.sa_handler = handler;
sa.sa_mask = blocking_mask;
sa.sa_flags = 0;
for (auto sig : quitSignals)
sigaction(sig, &sa, nullptr);
}
#endif
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
setenv("QT_QUICK_CONTROLS_STYLE", "Desktop", 1); setenv("QT_QUICK_CONTROLS_STYLE", "Desktop", 1);
QApplication app(argc, argv); QApplication app(argc, argv);
#ifdef __linux__
catchUnixSignals({SIGQUIT, SIGINT, SIGTERM, SIGHUP});
#endif
app.setOrganizationName("KittehPlayer"); app.setOrganizationName("KittehPlayer");
app.setOrganizationDomain("namedkitten.pw"); app.setOrganizationDomain("namedkitten.pw");
app.setApplicationName("KittehPlayer"); app.setApplicationName("KittehPlayer");