From c748f36939cdac74332dde3afb866ad35bea1825 Mon Sep 17 00:00:00 2001 From: vaxerski Date: Tue, 8 Aug 2023 16:16:34 +0200 Subject: internal: add lock files and hyprctl instances --- src/Compositor.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/Compositor.cpp') diff --git a/src/Compositor.cpp b/src/Compositor.cpp index d1124bc1..ec70bb68 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -312,6 +312,8 @@ void CCompositor::cleanup() { if (!m_sWLDisplay || m_bIsShuttingDown) return; + removeLockFile(); + m_bIsShuttingDown = true; #ifdef USES_SYSTEMD @@ -416,6 +418,23 @@ void CCompositor::initManagers(eManagersInitStage stage) { } } +void CCompositor::createLockFile() { + const auto PATH = "/tmp/hypr/" + m_szInstanceSignature + ".lock"; + + std::ofstream ofs(PATH, std::ios::trunc); + + ofs << m_iHyprlandPID << "\n" << m_szWLDisplaySocket << "\n"; + + ofs.close(); +} + +void CCompositor::removeLockFile() { + const auto PATH = "/tmp/hypr/" + m_szInstanceSignature + ".lock"; + + if (std::filesystem::exists(PATH)) + std::filesystem::remove(PATH); +} + void CCompositor::startCompositor() { initAllSignals(); @@ -477,6 +496,8 @@ void CCompositor::startCompositor() { Debug::log(LOG, "systemd integration is baked in but system itself is not booted à la systemd!"); #endif + createLockFile(); + // This blocks until we are done. Debug::log(LOG, "Hyprland is ready, running the event loop!"); wl_display_run(m_sWLDisplay); -- cgit v1.2.3