[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.
icc-effect-5.14.5
Martin Gräßlin 2015-02-25 14:46:30 +01:00
parent 69a13a779d
commit 79c49e84a4
3 changed files with 18 additions and 5 deletions

View File

@ -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);

View File

@ -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];
}
}

View File

@ -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)
};