6#include "KWayland/Client/compositor.h"
7#include "KWayland/Client/connection_thread.h"
8#include "KWayland/Client/event_queue.h"
9#include "KWayland/Client/plasmashell.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 <QCommandLineParser>
16#include <QGuiApplication>
31 void setRole(PlasmaShellSurface::Role role)
46 void setupRegistry(Registry *registry);
48 QThread *m_connectionThread;
49 ConnectionThread *m_connectionThreadObject;
50 EventQueue *m_eventQueue =
nullptr;
51 Compositor *m_compositor =
nullptr;
52 Shell *m_shell =
nullptr;
53 ShellSurface *m_shellSurface =
nullptr;
54 ShmPool *m_shm =
nullptr;
55 Surface *m_surface =
nullptr;
56 PlasmaShell *m_plasmaShell =
nullptr;
57 PlasmaShellSurface *m_plasmaShellSurface =
nullptr;
58 PlasmaShellSurface::Role m_role = PlasmaShellSurface::Role::Normal;
59 bool m_skipTaskbar =
false;
60 bool m_skipSwitcher =
false;
65 , m_connectionThread(new QThread(this))
66 , m_connectionThreadObject(new ConnectionThread())
72 m_connectionThread->quit();
73 m_connectionThread->wait();
74 m_connectionThreadObject->deleteLater();
77void PlasmaSurfaceTest::init()
80 m_connectionThreadObject,
81 &ConnectionThread::connected,
84 m_eventQueue =
new EventQueue(
this);
85 m_eventQueue->setup(m_connectionThreadObject);
87 Registry *registry =
new Registry(
this);
88 setupRegistry(registry);
90 Qt::QueuedConnection);
91 m_connectionThreadObject->moveToThread(m_connectionThread);
92 m_connectionThread->start();
94 m_connectionThreadObject->initConnection();
97void PlasmaSurfaceTest::setupRegistry(Registry *registry)
99 connect(registry, &Registry::compositorAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
102 connect(registry, &Registry::shellAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
105 connect(registry, &Registry::shmAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
108 connect(registry, &Registry::plasmaShellAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
110 m_plasmaShell->setEventQueue(m_eventQueue);
112 connect(registry, &Registry::interfacesAnnounced,
this, [
this] {
113 Q_ASSERT(m_compositor);
116 Q_ASSERT(m_plasmaShell);
117 m_surface = m_compositor->createSurface(
this);
119 m_shellSurface = m_shell->createSurface(m_surface,
this);
120 Q_ASSERT(m_shellSurface);
121 m_shellSurface->setToplevel();
122 connect(m_shellSurface, &ShellSurface::sizeChanged,
this, &PlasmaSurfaceTest::render);
123 m_plasmaShellSurface = m_plasmaShell->createSurface(m_surface,
this);
124 Q_ASSERT(m_plasmaShellSurface);
125 m_plasmaShellSurface->setSkipTaskbar(m_skipTaskbar);
126 m_plasmaShellSurface->setSkipSwitcher(m_skipSwitcher);
127 m_plasmaShellSurface->setRole(m_role);
130 registry->setEventQueue(m_eventQueue);
131 registry->create(m_connectionThreadObject);
135void PlasmaSurfaceTest::render()
137 const QSize &size = m_shellSurface->size().isValid() ? m_shellSurface->size() : QSize(300, 200);
138 auto buffer = m_shm->getBuffer(size, size.width() * 4).toStrongRef();
139 buffer->setUsed(
true);
140 QImage image(buffer->address(), size.width(), size.height(), QImage::Format_ARGB32_Premultiplied);
141 image.fill(QColor(255, 255, 255, 128));
143 m_surface->attachBuffer(*buffer);
144 m_surface->damage(QRect(QPoint(0, 0), size));
145 m_surface->commit(Surface::CommitFlag::None);
146 buffer->setUsed(
false);
151 QCoreApplication app(argc, argv);
152 QCommandLineParser parser;
153 parser.addHelpOption();
154 QCommandLineOption notificationOption(QStringLiteral(
"notification"));
155 parser.addOption(notificationOption);
156 QCommandLineOption criticalNotificationOption(QStringLiteral(
"criticalNotification"));
157 parser.addOption(criticalNotificationOption);
158 QCommandLineOption appletPopupOption(QStringLiteral(
"appletPopup"));
159 parser.addOption(appletPopupOption);
160 QCommandLineOption panelOption(QStringLiteral(
"panel"));
161 parser.addOption(panelOption);
162 QCommandLineOption desktopOption(QStringLiteral(
"desktop"));
163 parser.addOption(desktopOption);
164 QCommandLineOption osdOption(QStringLiteral(
"osd"));
165 parser.addOption(osdOption);
166 QCommandLineOption tooltipOption(QStringLiteral(
"tooltip"));
167 parser.addOption(tooltipOption);
168 QCommandLineOption skipTaskbarOption(QStringLiteral(
"skipTaskbar"));
169 parser.addOption(skipTaskbarOption);
171 QCommandLineOption skipSwitcherOption(QStringLiteral(
"skipSwitcher"));
172 parser.addOption(skipSwitcherOption);
177 if (parser.isSet(notificationOption)) {
178 client.
setRole(PlasmaShellSurface::Role::Notification);
179 }
else if (parser.isSet(criticalNotificationOption)) {
180 client.
setRole(PlasmaShellSurface::Role::CriticalNotification);
181 }
else if (parser.isSet(appletPopupOption)) {
182 client.
setRole(PlasmaShellSurface::Role::AppletPopup);
183 }
else if (parser.isSet(panelOption)) {
184 client.
setRole(PlasmaShellSurface::Role::Panel);
185 }
else if (parser.isSet(desktopOption)) {
186 client.
setRole(PlasmaShellSurface::Role::Desktop);
187 }
else if (parser.isSet(osdOption)) {
188 client.
setRole(PlasmaShellSurface::Role::OnScreenDisplay);
189 }
else if (parser.isSet(tooltipOption)) {
190 client.
setRole(PlasmaShellSurface::Role::ToolTip);
200#include "plasmasurfacetest.moc"
void setRole(PlasmaShellSurface::Role role)
PlasmaSurfaceTest(QObject *parent=nullptr)
void setSkipTaskbar(bool set)
virtual ~PlasmaSurfaceTest()
void setSkipSwitcher(bool set)
KWayland::Client::Registry * registry