diff --git a/src/helpers/wayland_wrapper/kwin_wrapper.cpp b/src/helpers/wayland_wrapper/kwin_wrapper.cpp index c3dafb711e..74778e8258 100644 --- a/src/helpers/wayland_wrapper/kwin_wrapper.cpp +++ b/src/helpers/wayland_wrapper/kwin_wrapper.cpp @@ -99,8 +99,10 @@ void KWinWrapper::run() args << "--socket" << QString::fromUtf8(wl_socket_get_display_name(m_socket)); if (m_xwlSocket) { - args << "--xwayland-fd" << QString::number(m_xwlSocket->abstractFileDescriptor()); - args << "--xwayland-fd" << QString::number(m_xwlSocket->unixFileDescriptor()); + const auto xwaylandFileDescriptors = m_xwlSocket->fileDescriptors(); + for (const int &fileDescriptor : xwaylandFileDescriptors) { + args << "--xwayland-fd" << QString::number(fileDescriptor); + } args << "--xwayland-display" << m_xwlSocket->name(); if (m_xauthorityFile.open()) { args << "--xwayland-xauthority" << m_xauthorityFile.fileName(); diff --git a/src/xwl/lib/xwaylandsocket.cpp b/src/xwl/lib/xwaylandsocket.cpp index 7cf9310584..1642e55c34 100644 --- a/src/xwl/lib/xwaylandsocket.cpp +++ b/src/xwl/lib/xwaylandsocket.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -176,24 +177,35 @@ XwaylandSocket::XwaylandSocket(OperationMode mode) continue; } + QVector fileDescriptors; + auto socketCleanup = qScopeGuard([&fileDescriptors]() { + for (const int &fileDescriptor : qAsConst(fileDescriptors)) { + close(fileDescriptor); + } + }); + const int unixFileDescriptor = listen_helper(socketFilePath, UnixSocketAddress::Type::Unix, mode); if (unixFileDescriptor == -1) { QFile::remove(lockFilePath); continue; } + fileDescriptors << unixFileDescriptor; +#if defined(Q_OS_LINUX) const int abstractFileDescriptor = listen_helper(socketFilePath, UnixSocketAddress::Type::Abstract, mode); if (abstractFileDescriptor == -1) { QFile::remove(lockFilePath); QFile::remove(socketFilePath); - close(unixFileDescriptor); continue; } + fileDescriptors << abstractFileDescriptor; +#endif + + m_fileDescriptors = fileDescriptors; + socketCleanup.dismiss(); m_socketFilePath = socketFilePath; m_lockFilePath = lockFilePath; - m_unixFileDescriptor = unixFileDescriptor; - m_abstractFileDescriptor = abstractFileDescriptor; m_display = display; return; } @@ -203,11 +215,8 @@ XwaylandSocket::XwaylandSocket(OperationMode mode) XwaylandSocket::~XwaylandSocket() { - if (m_unixFileDescriptor != -1) { - close(m_unixFileDescriptor); - } - if (m_abstractFileDescriptor != -1) { - close(m_abstractFileDescriptor); + for (const int &fileDescriptor : qAsConst(m_fileDescriptors)) { + close(fileDescriptor); } if (!m_socketFilePath.isEmpty()) { QFile::remove(m_socketFilePath); @@ -222,14 +231,9 @@ bool XwaylandSocket::isValid() const return m_display != -1; } -int XwaylandSocket::unixFileDescriptor() const +QVector XwaylandSocket::fileDescriptors() const { - return m_unixFileDescriptor; -} - -int XwaylandSocket::abstractFileDescriptor() const -{ - return m_abstractFileDescriptor; + return m_fileDescriptors; } int XwaylandSocket::display() const diff --git a/src/xwl/lib/xwaylandsocket.h b/src/xwl/lib/xwaylandsocket.h index 0552d077db..80bad35094 100644 --- a/src/xwl/lib/xwaylandsocket.h +++ b/src/xwl/lib/xwaylandsocket.h @@ -8,6 +8,7 @@ #include #include +#include namespace KWin { @@ -27,12 +28,10 @@ public: int display() const; QString name() const; - int unixFileDescriptor() const; - int abstractFileDescriptor() const; + QVector fileDescriptors() const; private: - int m_unixFileDescriptor = -1; - int m_abstractFileDescriptor = -1; + QVector m_fileDescriptors; int m_display = -1; QString m_socketFilePath; QString m_lockFilePath; diff --git a/src/xwl/xwayland.cpp b/src/xwl/xwayland.cpp index 80fd3fb0d2..28183bc8f9 100644 --- a/src/xwl/xwayland.cpp +++ b/src/xwl/xwayland.cpp @@ -87,8 +87,8 @@ void Xwayland::start() if (!m_socket->isValid()) { qFatal("Failed to establish X11 socket"); } - setListenFDs({m_socket->unixFileDescriptor(), m_socket->abstractFileDescriptor()}); m_displayName = m_socket->name(); + m_listenFds = m_socket->fileDescriptors(); } startInternal();