diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 55d8afe72..5259ed374 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -16,6 +16,8 @@ int handleCritSignal(int signo, void* data) { CCompositor::CCompositor() { wlr_log_init(WLR_INFO, NULL); + m_iHyprlandPID = getpid(); + m_szInstanceSignature = GIT_COMMIT_HASH + std::string("_") + std::to_string(time(NULL)); setenv("HYPRLAND_INSTANCE_SIGNATURE", m_szInstanceSignature.c_str(), true); @@ -27,6 +29,8 @@ CCompositor::CCompositor() { Debug::log(LOG, "Instance Signature: %s", m_szInstanceSignature.c_str()); + Debug::log(LOG, "Hyprland PID: %i", m_iHyprlandPID); + Debug::log(LOG, "===== SYSTEM INFO: ====="); logSystemInfo(); @@ -236,6 +240,17 @@ void CCompositor::cleanup() { m_pLastFocus = nullptr; m_pLastWindow = nullptr; + // accumulate all PIDs for killing, also request closing. + for (auto& w : m_vWindows) { + m_dProcessPIDsOnShutdown.push_back(w->getPID()); + + closeWindow(w.get()); + } + + // end threads + g_pEventManager->m_tThread = std::thread(); + HyprCtl::tThread = std::thread(); + m_vWorkspaces.clear(); m_vWindows.clear(); @@ -254,6 +269,9 @@ void CCompositor::cleanup() { wl_display_terminate(m_sWLDisplay); m_bIsShuttingDown = true; + + g_pKeybindManager->spawn("sleep 5 && kill -9 " + std::to_string(m_iHyprlandPID)); // this is to prevent that random "freezing" + // the PID should not be reused. } void CCompositor::startCompositor() { diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 2a8c7fcb7..45d108cf3 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -101,6 +101,7 @@ public: bool m_bDPMSStateON = true; bool m_bUnsafeState = false; // unsafe state is when there is no monitors. bool m_bIsShuttingDown = false; + std::deque m_dProcessPIDsOnShutdown; // stores PIDs of apps to kill later when shutting down // ------------------------------------------------- // @@ -172,7 +173,9 @@ public: private: void initAllSignals(); - void setRandomSplash(); + void setRandomSplash(); + + uint64_t m_iHyprlandPID = 0; }; diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 6b89b3c65..2cf2781ee 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -759,7 +759,7 @@ std::string getRequestFromThread(std::string rq) { } void HyprCtl::startHyprCtlSocket() { - std::thread([&]() { + tThread = std::thread([&]() { const auto SOCKET = socket(AF_UNIX, SOCK_STREAM, 0); if (SOCKET < 0) { @@ -806,5 +806,7 @@ void HyprCtl::startHyprCtlSocket() { } close(SOCKET); - }).detach(); + }); + + tThread.detach(); } diff --git a/src/debug/HyprCtl.hpp b/src/debug/HyprCtl.hpp index 60559e9f1..b717f50fd 100644 --- a/src/debug/HyprCtl.hpp +++ b/src/debug/HyprCtl.hpp @@ -15,6 +15,8 @@ namespace HyprCtl { inline std::ifstream requestStream; + inline std::thread tThread; + enum eHyprCtlOutputFormat { FORMAT_NORMAL = 0, FORMAT_JSON diff --git a/src/main.cpp b/src/main.cpp index b131e59aa..4c61f3807 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -62,6 +62,11 @@ int main(int argc, char** argv) { Debug::log(LOG, "Hyprland reached the end."); wl_display_destroy_clients(g_pCompositor->m_sWLDisplay); + + // kill all clients + for (auto& c : g_pCompositor->m_dProcessPIDsOnShutdown) + kill(c, SIGKILL); + wl_display_destroy(g_pCompositor->m_sWLDisplay); return EXIT_SUCCESS; diff --git a/src/managers/EventManager.cpp b/src/managers/EventManager.cpp index 2b2598e1f..98dd5049d 100644 --- a/src/managers/EventManager.cpp +++ b/src/managers/EventManager.cpp @@ -19,7 +19,7 @@ CEventManager::CEventManager() { } void CEventManager::startThread() { - std::thread([&]() { + m_tThread = std::thread([&]() { const auto SOCKET = socket(AF_UNIX, SOCK_STREAM, 0); if (SOCKET < 0) { @@ -101,13 +101,15 @@ void CEventManager::startThread() { } close(SOCKET); - }).detach(); + }); + + m_tThread.detach(); } void CEventManager::postEvent(const SHyprIPCEvent event, bool force) { - if (m_bIgnoreEvents && !force) { - Debug::log(WARN, "Suppressed (ignoreevents true) event of type %s, content: %s",event.event.c_str(), event.data.c_str()); + if ((m_bIgnoreEvents && !force) || g_pCompositor->m_bIsShuttingDown) { + Debug::log(WARN, "Suppressed (ignoreevents true / shutting down) event of type %s, content: %s",event.event.c_str(), event.data.c_str()); return; } diff --git a/src/managers/EventManager.hpp b/src/managers/EventManager.hpp index b9598bcaf..c386a260a 100644 --- a/src/managers/EventManager.hpp +++ b/src/managers/EventManager.hpp @@ -21,6 +21,8 @@ public: bool m_bIgnoreEvents = false; + std::thread m_tThread; + private: std::mutex eventQueueMutex;