From 422eaad4201fe1902f037898e98d8651925b9c13 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 21 Apr 2022 15:59:28 +0200 Subject: [PATCH] handle term and int signals and cleanup --- src/Compositor.cpp | 23 +++++++++++++++++++++++ src/Compositor.hpp | 1 + src/main.cpp | 3 +-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index f4da7caf..2ed12112 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -100,7 +100,12 @@ CCompositor::CCompositor() { } CCompositor::~CCompositor() { + cleanupExit(); +} +void handleCritSignal(int signo) { + g_pCompositor->cleanupExit(); + exit(signo); } void CCompositor::initAllSignals() { @@ -123,6 +128,24 @@ void CCompositor::initAllSignals() { addWLSignal(&m_sWLRInhibitMgr->events.activate, &Events::listen_InhibitActivate, m_sWLRInhibitMgr, "InhibitMgr"); addWLSignal(&m_sWLRInhibitMgr->events.deactivate, &Events::listen_InhibitDeactivate, m_sWLRInhibitMgr, "InhibitMgr"); addWLSignal(&m_sWLRPointerConstraints->events.new_constraint, &Events::listen_newConstraint, m_sWLRPointerConstraints, "PointerConstraints"); + + signal(SIGINT, handleCritSignal); + signal(SIGTERM, handleCritSignal); +} + +void CCompositor::cleanupExit() { + if (!m_sWLDisplay) + return; + + if (g_pXWaylandManager->m_sWLRXWayland) { + wlr_xwayland_destroy(g_pXWaylandManager->m_sWLRXWayland); + g_pXWaylandManager->m_sWLRXWayland = nullptr; + } + + wl_display_destroy_clients(m_sWLDisplay); + wl_display_destroy(m_sWLDisplay); + + m_sWLDisplay = nullptr; } void CCompositor::startCompositor() { diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 0e036079..ebc2abe3 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -66,6 +66,7 @@ public: std::list m_lWindowsFadingOut; void startCompositor(); + void cleanupExit(); wlr_surface* m_pLastFocus = nullptr; CWindow* m_pLastWindow = nullptr; diff --git a/src/main.cpp b/src/main.cpp index 57016425..7cbef959 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,8 +22,7 @@ int main(int argc, char** argv) { // If we are here it means we got yote. Debug::log(LOG, "Hyprland reached the end."); - wl_display_destroy_clients(g_pCompositor->m_sWLDisplay); - wl_display_destroy(g_pCompositor->m_sWLDisplay); + g_pCompositor->cleanupExit(); return EXIT_SUCCESS; }