From a9e5343eb6e9a69801ef1e19a90c004a0b76c894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 17 Aug 2015 09:42:12 +0200 Subject: [PATCH] [wayland] Use an event thread for the internal Wayland connection --- wayland_server.cpp | 24 ++++++++++++++++++++---- wayland_server.h | 2 ++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/wayland_server.cpp b/wayland_server.cpp index 6124d818d2..644bacbd1a 100644 --- a/wayland_server.cpp +++ b/wayland_server.cpp @@ -27,6 +27,7 @@ along with this program. If not, see . // Client #include +#include #include #include // Server @@ -43,6 +44,7 @@ along with this program. If not, see . #include // Qt +#include #include // system @@ -61,7 +63,14 @@ WaylandServer::WaylandServer(QObject *parent) { } -WaylandServer::~WaylandServer() = default; +WaylandServer::~WaylandServer() +{ + if (m_internalConnection.client) { + m_internalConnection.client->deleteLater(); + m_internalConnection.clientThread->quit(); + m_internalConnection.clientThread->wait(); + } +} void WaylandServer::init(const QByteArray &socketName) { @@ -268,16 +277,23 @@ void WaylandServer::createInternalConnection() } m_internalConnection.server = m_display->createClient(sx[0]); using namespace KWayland::Client; - m_internalConnection.client = new ConnectionThread(this); + m_internalConnection.client = new ConnectionThread(); m_internalConnection.client->setSocketFd(sx[1]); + m_internalConnection.clientThread = new QThread; + m_internalConnection.client->moveToThread(m_internalConnection.clientThread); + m_internalConnection.clientThread->start(); + connect(m_internalConnection.client, &ConnectionThread::connected, this, [this] { - Registry *registry = new Registry(m_internalConnection.client); + Registry *registry = new Registry(this); + EventQueue *eventQueue = new EventQueue(this); + eventQueue->setup(m_internalConnection.client); + registry->setEventQueue(eventQueue); registry->create(m_internalConnection.client); m_internalConnection.registry = registry; connect(registry, &Registry::shmAnnounced, this, [this] (quint32 name, quint32 version) { - m_internalConnection.shm = m_internalConnection.registry->createShmPool(name, version, m_internalConnection.client); + m_internalConnection.shm = m_internalConnection.registry->createShmPool(name, version, this); } ); registry->setup(); diff --git a/wayland_server.h b/wayland_server.h index 5c0126fb94..2ac4dc888b 100644 --- a/wayland_server.h +++ b/wayland_server.h @@ -24,6 +24,7 @@ along with this program. If not, see . #include +class QThread; class QWindow; namespace KWayland @@ -159,6 +160,7 @@ private: struct { KWayland::Server::ClientConnection *server = nullptr; KWayland::Client::ConnectionThread *client = nullptr; + QThread *clientThread = nullptr; KWayland::Client::Registry *registry = nullptr; KWayland::Client::ShmPool *shm = nullptr;