6#include "KWayland/Client/compositor.h"
7#include "KWayland/Client/connection_thread.h"
8#include "KWayland/Client/datadevice.h"
9#include "KWayland/Client/datadevicemanager.h"
10#include "KWayland/Client/dataoffer.h"
11#include "KWayland/Client/event_queue.h"
12#include "KWayland/Client/keyboard.h"
13#include "KWayland/Client/registry.h"
14#include "KWayland/Client/seat.h"
15#include "KWayland/Client/shell.h"
16#include "KWayland/Client/shm_pool.h"
17#include "KWayland/Client/subcompositor.h"
18#include "KWayland/Client/surface.h"
22#include <QGuiApplication>
30#include <linux/input.h>
44 void setupRegistry(Registry *registry);
46 QThread *m_connectionThread;
47 ConnectionThread *m_connectionThreadObject;
48 EventQueue *m_eventQueue =
nullptr;
49 Compositor *m_compositor =
nullptr;
50 Seat *m_seat =
nullptr;
51 Shell *m_shell =
nullptr;
52 ShellSurface *m_shellSurface =
nullptr;
53 ShmPool *m_shm =
nullptr;
54 Surface *m_surface =
nullptr;
55 SubCompositor *m_subCompositor =
nullptr;
60 , m_connectionThread(new QThread(this))
61 , m_connectionThreadObject(new ConnectionThread())
67 m_connectionThread->quit();
68 m_connectionThread->wait();
69 m_connectionThreadObject->deleteLater();
75 m_connectionThreadObject,
76 &ConnectionThread::connected,
79 m_eventQueue =
new EventQueue(
this);
80 m_eventQueue->setup(m_connectionThreadObject);
82 Registry *registry =
new Registry(
this);
83 setupRegistry(registry);
85 Qt::QueuedConnection);
86 m_connectionThreadObject->moveToThread(m_connectionThread);
87 m_connectionThread->start();
89 m_connectionThreadObject->initConnection();
92void SubSurfaceTest::setupRegistry(Registry *registry)
94 connect(registry, &Registry::compositorAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
95 m_compositor = registry->createCompositor(name,
version,
this);
97 connect(registry, &Registry::shellAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
100 connect(registry, &Registry::shmAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
103 connect(registry, &Registry::seatAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
106 connect(registry, &Registry::interfacesAnnounced,
this, [
this, registry] {
107 Q_ASSERT(m_compositor);
111 m_surface = m_compositor->createSurface(
this);
113 m_shellSurface = m_shell->createSurface(m_surface,
this);
114 Q_ASSERT(m_shellSurface);
115 m_shellSurface->setToplevel();
116 connect(m_shellSurface, &ShellSurface::sizeChanged,
this, &SubSurfaceTest::render);
118 auto subInterface =
registry->interface(Registry::Interface::SubCompositor);
119 if (subInterface.name != 0) {
120 m_subCompositor =
registry->createSubCompositor(subInterface.name, subInterface.version,
this);
121 Q_ASSERT(m_subCompositor);
123 auto surface = m_compositor->createSurface(
this);
125 auto subsurface = m_subCompositor->createSubSurface(surface, m_surface,
this);
126 Q_ASSERT(subsurface);
127 QImage image(QSize(100, 100), QImage::Format_ARGB32_Premultiplied);
129 surface->attachBuffer(m_shm->createBuffer(image));
130 surface->damage(QRect(0, 0, 100, 100));
131 surface->commit(Surface::CommitFlag::None);
133 auto surface2 = m_compositor->createSurface(
this);
135 auto subsurface2 = m_subCompositor->createSubSurface(surface2, surface,
this);
136 Q_ASSERT(subsurface2);
137 QImage green(QSize(50, 50), QImage::Format_ARGB32_Premultiplied);
138 green.fill(Qt::green);
139 surface2->attachBuffer(m_shm->createBuffer(green));
140 surface2->damage(QRect(0, 0, 50, 50));
141 surface2->commit(Surface::CommitFlag::None);
142 QTimer *timer =
new QTimer(
this);
143 connect(timer, &QTimer::timeout, surface2, [surface2,
this] {
144 QImage yellow(QSize(50, 50), QImage::Format_ARGB32_Premultiplied);
145 yellow.fill(Qt::yellow);
146 surface2->attachBuffer(m_shm->createBuffer(yellow));
147 surface2->damage(QRect(0, 0, 50, 50));
148 surface2->commit(Surface::CommitFlag::None);
149 m_surface->commit(Surface::CommitFlag::None);
151 timer->setSingleShot(
true);
156 registry->setEventQueue(m_eventQueue);
157 registry->create(m_connectionThreadObject);
161void SubSurfaceTest::render()
163 const QSize &size = m_shellSurface->size().isValid() ? m_shellSurface->size() : QSize(200, 200);
164 auto buffer = m_shm->getBuffer(size, size.width() * 4).toStrongRef();
165 buffer->setUsed(
true);
166 QImage image(buffer->address(), size.width(), size.height(), QImage::Format_ARGB32_Premultiplied);
167 image.fill(Qt::blue);
169 m_surface->attachBuffer(*buffer);
170 m_surface->damage(QRect(QPoint(0, 0), size));
171 m_surface->commit(Surface::CommitFlag::None);
172 buffer->setUsed(
false);
177 QCoreApplication app(argc, argv);
184#include "subsurfacetest.moc"
SubSurfaceTest(QObject *parent=nullptr)
virtual ~SubSurfaceTest()
KWayland::Client::Registry * registry