diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 5cf43334..9cf5e272 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -345,15 +345,21 @@ void CCompositor::startCompositor() { initAllSignals(); - m_szWLDisplaySocket = wl_display_add_socket_auto(m_sWLDisplay); + // get socket, avoid using 0 + for (int candidate = 1; candidate <= 32; candidate++) { + if (wl_display_add_socket(m_sWLDisplay, ("wayland-" + std::to_string(candidate)).c_str()) >= 0) { + m_szWLDisplaySocket = "wayland-" + std::to_string(candidate); + break; + } + } - if (!m_szWLDisplaySocket) { + if (m_szWLDisplaySocket.empty()) { Debug::log(CRIT, "m_szWLDisplaySocket NULL!"); wlr_backend_destroy(m_sWLRBackend); throw std::runtime_error("m_szWLDisplaySocket was null! (wl_display_add_socket_auto failed)"); } - setenv("WAYLAND_DISPLAY", m_szWLDisplaySocket, 1); + setenv("WAYLAND_DISPLAY", m_szWLDisplaySocket.c_str(), 1); signal(SIGPIPE, SIG_IGN); diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 9d32692f..125a61eb 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -76,7 +76,7 @@ public: // ------------------------------------------------- // - const char* m_szWLDisplaySocket; + std::string m_szWLDisplaySocket = ""; std::string m_szInstanceSignature = ""; std::string m_szCurrentSplash = "error";