7#include "KWayland/Client/xdgforeign.h"
8#include "KWayland/Client/compositor.h"
9#include "KWayland/Client/connection_thread.h"
10#include "KWayland/Client/event_queue.h"
11#include "KWayland/Client/registry.h"
12#include "KWayland/Client/shell.h"
13#include "KWayland/Client/shm_pool.h"
14#include "KWayland/Client/xdgshell.h"
16#include <QCommandLineParser>
18#include <QGuiApplication>
33 void setupRegistry(Registry *registry);
35 QThread *m_connectionThread;
36 ConnectionThread *m_connectionThreadObject;
37 EventQueue *m_eventQueue =
nullptr;
38 Compositor *m_compositor =
nullptr;
40 XdgShellSurface *m_shellSurface =
nullptr;
41 ShmPool *m_shm =
nullptr;
42 Surface *m_surface =
nullptr;
44 XdgShellSurface *m_childShellSurface =
nullptr;
45 Surface *m_childSurface =
nullptr;
47 KWayland::Client::XdgExporter *m_exporter =
nullptr;
48 KWayland::Client::XdgImporter *m_importer =
nullptr;
49 KWayland::Client::XdgExported *m_exported =
nullptr;
50 KWayland::Client::XdgImported *m_imported =
nullptr;
55 , m_connectionThread(new QThread(this))
56 , m_connectionThreadObject(new ConnectionThread())
62 m_connectionThread->quit();
63 m_connectionThread->wait();
64 m_connectionThreadObject->deleteLater();
70 m_connectionThreadObject,
71 &ConnectionThread::connected,
74 m_eventQueue =
new EventQueue(
this);
75 m_eventQueue->setup(m_connectionThreadObject);
77 Registry *registry =
new Registry(
this);
78 setupRegistry(registry);
80 Qt::QueuedConnection);
81 m_connectionThreadObject->moveToThread(m_connectionThread);
82 m_connectionThread->start();
84 m_connectionThreadObject->initConnection();
87void XdgForeignTest::setupRegistry(Registry *registry)
89 connect(registry, &Registry::compositorAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
90 m_compositor = registry->createCompositor(name,
version,
this);
92 connect(registry, &Registry::xdgShellUnstableV5Announced,
this, [
this, registry](quint32 name, quint32
version) {
95 connect(registry, &Registry::shmAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
98 connect(registry, &Registry::exporterUnstableV2Announced,
this, [
this, registry](quint32 name, quint32
version) {
100 m_exporter->setEventQueue(m_eventQueue);
102 connect(registry, &Registry::importerUnstableV2Announced,
this, [
this, registry](quint32 name, quint32
version) {
104 m_importer->setEventQueue(m_eventQueue);
106 connect(registry, &Registry::interfacesAnnounced,
this, [
this] {
107 Q_ASSERT(m_compositor);
110 Q_ASSERT(m_exporter);
111 Q_ASSERT(m_importer);
112 m_surface = m_compositor->createSurface(
this);
114 m_shellSurface = m_shell->createSurface(m_surface,
this);
115 Q_ASSERT(m_shellSurface);
116 connect(m_shellSurface, &XdgShellSurface::sizeChanged,
this, &XdgForeignTest::render);
118 m_childSurface = m_compositor->createSurface(
this);
119 Q_ASSERT(m_childSurface);
120 m_childShellSurface = m_shell->createSurface(m_childSurface,
this);
121 Q_ASSERT(m_childShellSurface);
122 connect(m_childShellSurface, &XdgShellSurface::sizeChanged,
this, &XdgForeignTest::render);
124 m_exported = m_exporter->exportTopLevel(m_surface,
this);
125 connect(m_exported, &XdgExported::done,
this, [
this]() {
126 m_imported = m_importer->importTopLevel(m_exported->handle(),
this);
127 m_imported->setParentOf(m_childSurface);
131 registry->setEventQueue(m_eventQueue);
132 registry->create(m_connectionThreadObject);
136void XdgForeignTest::render()
138 QSize size = m_shellSurface->size().isValid() ? m_shellSurface->size() : QSize(500, 500);
139 auto buffer = m_shm->getBuffer(size, size.width() * 4).toStrongRef();
140 buffer->setUsed(
true);
141 QImage image(buffer->address(), size.width(), size.height(), QImage::Format_ARGB32_Premultiplied);
142 image.fill(QColor(255, 255, 255, 255));
144 m_surface->attachBuffer(*buffer);
145 m_surface->damage(QRect(QPoint(0, 0), size));
146 m_surface->commit(Surface::CommitFlag::None);
147 buffer->setUsed(
false);
149 size = m_childShellSurface->size().isValid() ? m_childShellSurface->size() : QSize(200, 200);
150 buffer = m_shm->getBuffer(size, size.width() * 4).toStrongRef();
151 buffer->setUsed(
true);
152 image = QImage(buffer->address(), size.width(), size.height(), QImage::Format_ARGB32_Premultiplied);
153 image.fill(QColor(255, 0, 0, 255));
155 m_childSurface->attachBuffer(*buffer);
156 m_childSurface->damage(QRect(QPoint(0, 0), size));
157 m_childSurface->commit(Surface::CommitFlag::None);
158 buffer->setUsed(
false);
163 QCoreApplication app(argc, argv);
172#include "xdgforeigntest.moc"
virtual ~XdgForeignTest()
XdgForeignTest(QObject *parent=nullptr)
KWayland::Client::Registry * registry