From 79c49e84a4671952a4996cec5e718d53f19f4af9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 25 Feb 2015 14:46:30 +0100 Subject: [PATCH] [kwin_wayland] Pass socket file descriptor to QtWayland WaylandServer allows to create a ClientConnection which is intended for QtWayland. This allows us to easily identify our "own" surfaces. The created file descriptor is set as env variable WAYLAND_SOCKET prior to creating the Application. Wayland will unset it after connecting, so we don't need to unset it. This removes the hack of setting and resetting the WAYLAND_DISPLAY environment variable. --- main_wayland.cpp | 6 +----- wayland_server.cpp | 11 +++++++++++ wayland_server.h | 6 ++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/main_wayland.cpp b/main_wayland.cpp index d5babeef04..6c4ba11136 100644 --- a/main_wayland.cpp +++ b/main_wayland.cpp @@ -318,12 +318,8 @@ KWIN_EXPORT int kdemain(int argc, char * argv[]) if (signal(SIGHUP, KWin::sighandler) == SIG_IGN) signal(SIGHUP, SIG_IGN); - // we want QtWayland to connect to our Wayland display, but the WaylandBackend to the existing Wayland backend - // so fiddling around with the env variables. - const QByteArray systemDisplay = qgetenv("WAYLAND_DISPLAY"); - qputenv("WAYLAND_DISPLAY", waylandSocket.isEmpty() ? QByteArrayLiteral("wayland-0") : waylandSocket); + qputenv("WAYLAND_SOCKET", QByteArray::number(server->createQtConnection())); KWin::ApplicationWayland a(argc, argv); - qputenv("WAYLAND_DISPLAY", systemDisplay); a.setupTranslator(); server->setParent(&a); diff --git a/wayland_server.cpp b/wayland_server.cpp index 37f1257920..8da86fd3b1 100644 --- a/wayland_server.cpp +++ b/wayland_server.cpp @@ -102,4 +102,15 @@ int WaylandServer::createXWaylandConnection() return sx[1]; } +int WaylandServer::createQtConnection() +{ + int sx[2]; + if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sx) < 0) { + qCWarning(KWIN_CORE) << "Could not create socket"; + return -1; + } + m_qtConnection = m_display->createClient(sx[0]); + return sx[1]; +} + } diff --git a/wayland_server.h b/wayland_server.h index a4e1b14c54..3bc120c657 100644 --- a/wayland_server.h +++ b/wayland_server.h @@ -66,12 +66,18 @@ public: **/ int createXWaylandConnection(); + /** + * @returns file descriptor for QtWayland + **/ + int createQtConnection(); + private: KWayland::Server::Display *m_display = nullptr; KWayland::Server::CompositorInterface *m_compositor = nullptr; KWayland::Server::SeatInterface *m_seat = nullptr; KWayland::Server::ShellInterface *m_shell = nullptr; KWayland::Server::ClientConnection *m_xwaylandConnection = nullptr; + KWayland::Server::ClientConnection *m_qtConnection = nullptr; KWIN_SINGLETON(WaylandServer) };