From 5112056fdbda989191310364444f328240bbf6f1 Mon Sep 17 00:00:00 2001 From: vaxerski Date: Thu, 19 Jan 2023 16:44:23 +0100 Subject: [PATCH] better log wl socket adding and use auto if failed --- src/Compositor.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index f0a6d833..ca7f9b69 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -357,16 +357,28 @@ void CCompositor::startCompositor() { // 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); + const auto CANDIDATESTR = ("wayland-" + std::to_string(candidate)); + const auto RETVAL = wl_display_add_socket(m_sWLDisplay, CANDIDATESTR.c_str()); + if (RETVAL >= 0) { + m_szWLDisplaySocket = CANDIDATESTR; + Debug::log(LOG, "wl_display_add_socket for %s succeeded with %i", CANDIDATESTR.c_str(), RETVAL); break; + } else { + Debug::log(WARN, "wl_display_add_socket for %s returned %i: skipping candidate %i", CANDIDATESTR.c_str(), RETVAL, candidate); } } + if (m_szWLDisplaySocket.empty()) { + Debug::log(WARN, "All candidates failed, trying wl_display_add_socket_auto"); + const auto SOCKETSTR = wl_display_add_socket_auto(m_sWLDisplay); + if (SOCKETSTR) + m_szWLDisplaySocket = SOCKETSTR; + } + 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)"); + throw std::runtime_error("m_szWLDisplaySocket was null! (wl_display_add_socket and wl_display_add_socket_auto failed)"); } setenv("WAYLAND_DISPLAY", m_szWLDisplaySocket.c_str(), 1);