diff options
| author | Ferdinand Bachmann <ferdinand.bachmann@yrlf.at> | 2024-07-20 00:37:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-20 00:37:20 +0200 |
| commit | efccf25fcc72b416c63ff540703d9f061f39a7f2 (patch) | |
| tree | ea08e70802dbf4f94d3d7c7bf7e90b03e97b3a84 /src/Compositor.cpp | |
| parent | 8e15f91c2417c8f05d69a93f1294185ccc5f8f3e (diff) | |
compositor: implement wayland socket handover (#6930)
* compositor: implement wayland socket handover
This commit implements the compositor side of the Wayland socket
handover protocol as described in the [KDE Wiki]. The CLI options are
chosen so that they are compatible with Kwin.
[KDE Wiki]: https://invent.kde.org/plasma/kwin/-/wikis/Restarting
* main: verify that --wayland-fd is a valid file descriptor
* main: fail if only one of --socket and --wayland-fd is passed
Diffstat (limited to 'src/Compositor.cpp')
| -rw-r--r-- | src/Compositor.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp index d1c51075..7ffccf36 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -27,6 +27,7 @@ #include <hyprutils/string/String.hpp> using namespace Hyprutils::String; +#include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/resource.h> @@ -533,19 +534,28 @@ void CCompositor::prepareFallbackOutput() { wlr_headless_add_output(headless, 1920, 1080); } -void CCompositor::startCompositor() { +void CCompositor::startCompositor(std::string socketName, int socketFd) { initAllSignals(); - // get socket, avoid using 0 - for (int candidate = 1; candidate <= 32; candidate++) { - const auto CANDIDATESTR = ("wayland-" + std::to_string(candidate)); - const auto RETVAL = wl_display_add_socket(m_sWLDisplay, CANDIDATESTR.c_str()); + if (!socketName.empty() && socketFd != -1) { + fcntl(socketFd, F_SETFD, FD_CLOEXEC); + const auto RETVAL = wl_display_add_socket_fd(m_sWLDisplay, socketFd); if (RETVAL >= 0) { - m_szWLDisplaySocket = CANDIDATESTR; - Debug::log(LOG, "wl_display_add_socket for {} succeeded with {}", CANDIDATESTR, RETVAL); - break; - } else { - Debug::log(WARN, "wl_display_add_socket for {} returned {}: skipping candidate {}", CANDIDATESTR, RETVAL, candidate); + m_szWLDisplaySocket = socketName; + Debug::log(LOG, "wl_display_add_socket_fd for {} succeeded with {}", socketName, RETVAL); + } else + Debug::log(WARN, "wl_display_add_socket_fd for {} returned {}: skipping", socketName, RETVAL); + } else { + // get socket, avoid using 0 + for (int candidate = 1; candidate <= 32; 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 {} succeeded with {}", CANDIDATESTR, RETVAL); + break; + } else + Debug::log(WARN, "wl_display_add_socket for {} returned {}: skipping candidate {}", CANDIDATESTR, RETVAL, candidate); } } |
