internal: add lock files and hyprctl instances

This commit is contained in:
vaxerski 2023-08-08 16:16:34 +02:00
parent ad3b8dddf9
commit c748f36939
3 changed files with 116 additions and 2 deletions

View file

@ -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);

View file

@ -28,8 +28,7 @@
#include "hyprerror/HyprError.hpp"
#include "plugins/PluginSystem.hpp"
enum eManagersInitStage
{
enum eManagersInitStage {
STAGE_PRIORITY = 0,
STAGE_LATE
};
@ -107,6 +106,8 @@ class CCompositor {
void initServer();
void startCompositor();
void cleanup();
void createLockFile();
void removeLockFile();
wlr_surface* m_pLastFocus = nullptr;
CWindow* m_pLastWindow = nullptr;