6#include "KWayland/Client/shadow.h"
7#include "KWayland/Client/compositor.h"
8#include "KWayland/Client/connection_thread.h"
9#include "KWayland/Client/event_queue.h"
10#include "KWayland/Client/registry.h"
11#include "KWayland/Client/shell.h"
12#include "KWayland/Client/shm_pool.h"
13#include "KWayland/Client/surface.h"
15#include <QGuiApplication>
25 explicit ShadowTest(QObject *parent =
nullptr);
31 void setupRegistry(Registry *registry);
34 QThread *m_connectionThread;
35 ConnectionThread *m_connectionThreadObject;
36 EventQueue *m_eventQueue =
nullptr;
37 Compositor *m_compositor =
nullptr;
38 Shell *m_shell =
nullptr;
39 ShellSurface *m_shellSurface =
nullptr;
40 ShmPool *m_shm =
nullptr;
41 Surface *m_surface =
nullptr;
42 ShadowManager *m_shadowManager =
nullptr;
47 , m_connectionThread(new QThread(this))
48 , m_connectionThreadObject(new ConnectionThread())
54 m_connectionThread->quit();
55 m_connectionThread->wait();
56 m_connectionThreadObject->deleteLater();
59void ShadowTest::init()
62 m_connectionThreadObject,
63 &ConnectionThread::connected,
66 m_eventQueue =
new EventQueue(
this);
67 m_eventQueue->setup(m_connectionThreadObject);
69 Registry *registry =
new Registry(
this);
70 setupRegistry(registry);
72 Qt::QueuedConnection);
73 m_connectionThreadObject->moveToThread(m_connectionThread);
74 m_connectionThread->start();
76 m_connectionThreadObject->initConnection();
79void ShadowTest::setupRegistry(Registry *registry)
81 connect(registry, &Registry::compositorAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
84 connect(registry, &Registry::shellAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
87 connect(registry, &Registry::shmAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
90 connect(registry, &Registry::shadowAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
92 m_shadowManager->setEventQueue(m_eventQueue);
94 connect(registry, &Registry::interfacesAnnounced,
this, [
this] {
95 Q_ASSERT(m_compositor);
98 m_surface = m_compositor->createSurface(
this);
101 m_shellSurface = m_shell->createSurface(m_surface,
this);
102 Q_ASSERT(m_shellSurface);
103 m_shellSurface->setToplevel();
104 connect(m_shellSurface, &ShellSurface::sizeChanged,
this, &ShadowTest::render);
107 registry->setEventQueue(m_eventQueue);
108 registry->create(m_connectionThreadObject);
112void ShadowTest::setupShadow()
114 Q_ASSERT(m_shadowManager);
115 Shadow *shadow = m_shadowManager->createShadow(m_surface,
this);
118 auto addElement = [
this](
const QColor color) {
119 const QSize size = QSize(10, 10);
120 auto buffer = m_shm->getBuffer(size, size.width() * 4).toStrongRef();
121 buffer->setUsed(
true);
122 QImage image(buffer->address(), size.width(), size.height(), QImage::Format_ARGB32_Premultiplied);
126 shadow->attachTopLeft(addElement(Qt::red));
127 shadow->attachTop(addElement(Qt::darkRed));
128 shadow->attachTopRight(addElement(Qt::green));
129 shadow->attachRight(addElement(Qt::darkGreen));
130 shadow->attachBottomRight(addElement(Qt::darkBlue));
131 shadow->attachBottom(addElement(Qt::cyan));
132 shadow->attachBottomLeft(addElement(Qt::darkCyan));
133 shadow->attachLeft(addElement(Qt::magenta));
134 shadow->setOffsets(QMarginsF(5, 5, 5, 5));
138void ShadowTest::render()
140 const QSize &size = m_shellSurface->size().isValid() ? m_shellSurface->size() : QSize(300, 200);
141 auto buffer = m_shm->getBuffer(size, size.width() * 4).toStrongRef();
142 buffer->setUsed(
true);
143 QImage image(buffer->address(), size.width(), size.height(), QImage::Format_ARGB32_Premultiplied);
144 image.fill(QColor(255, 255, 255, 128));
146 m_surface->attachBuffer(*buffer);
147 m_surface->damage(QRect(QPoint(0, 0), size));
148 m_surface->commit(Surface::CommitFlag::None);
149 buffer->setUsed(
false);
154 QCoreApplication app(argc, argv);
161#include "shadowtest.moc"
ShadowTest(QObject *parent=nullptr)
KWayland::Client::Registry * registry