diff --git a/src/MpvPlayerBackend.cpp b/src/MpvPlayerBackend.cpp index 62f1348..74a7d3c 100644 --- a/src/MpvPlayerBackend.cpp +++ b/src/MpvPlayerBackend.cpp @@ -137,9 +137,11 @@ MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent) MpvPlayerBackend::~MpvPlayerBackend() { + printf("Shutting down...\n"); SetDPMS(true); mpv_render_context_free(mpv_gl); mpv_terminate_destroy(mpv); + printf("MPV terminated.\n"); } void MpvPlayerBackend::on_update(void* ctx) diff --git a/src/main.cpp b/src/main.cpp index 15f23af..93640c1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,10 +16,38 @@ #include "setenv_mingw.hpp" #endif +#ifdef __linux__ +#include +#include +#include +void catchUnixSignals(std::initializer_list 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[]) { setenv("QT_QUICK_CONTROLS_STYLE", "Desktop", 1); QApplication app(argc, argv); +#ifdef __linux__ + catchUnixSignals({SIGQUIT, SIGINT, SIGTERM, SIGHUP}); +#endif app.setOrganizationName("KittehPlayer"); app.setOrganizationDomain("namedkitten.pw"); app.setApplicationName("KittehPlayer");