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/plasmashell.h"
14#include "KWayland/Client/plasmawindowmanagement.h"
15#include "KWayland/Client/pointer.h"
16#include "KWayland/Client/registry.h"
17#include "KWayland/Client/seat.h"
18#include "KWayland/Client/shell.h"
19#include "KWayland/Client/shm_pool.h"
20#include "KWayland/Client/surface.h"
24#include <QGuiApplication>
31#include <linux/input.h>
39 explicit PanelTest(QObject *parent =
nullptr);
45 void setupRegistry(Registry *registry);
47 void showTooltip(
const QPointF &pos);
49 void moveTooltip(
const QPointF &pos);
50 QThread *m_connectionThread;
51 ConnectionThread *m_connectionThreadObject;
52 EventQueue *m_eventQueue =
nullptr;
53 Compositor *m_compositor =
nullptr;
54 Seat *m_seat =
nullptr;
55 Shell *m_shell =
nullptr;
56 ShellSurface *m_shellSurface =
nullptr;
57 ShmPool *m_shm =
nullptr;
58 Surface *m_surface =
nullptr;
59 PlasmaShell *m_plasmaShell =
nullptr;
60 PlasmaShellSurface *m_plasmaShellSurface =
nullptr;
61 PlasmaWindowManagement *m_windowManagement =
nullptr;
73 , m_connectionThread(new QThread(this))
74 , m_connectionThreadObject(new ConnectionThread())
80 m_connectionThread->quit();
81 m_connectionThread->wait();
82 m_connectionThreadObject->deleteLater();
88 m_connectionThreadObject,
89 &ConnectionThread::connected,
92 m_eventQueue =
new EventQueue(
this);
93 m_eventQueue->setup(m_connectionThreadObject);
95 Registry *registry =
new Registry(
this);
96 setupRegistry(registry);
98 Qt::QueuedConnection);
99 m_connectionThreadObject->moveToThread(m_connectionThread);
100 m_connectionThread->start();
102 m_connectionThreadObject->initConnection();
105void PanelTest::showTooltip(
const QPointF &pos)
107 if (!m_tooltip.surface) {
108 m_tooltip.surface = m_compositor->createSurface(
this);
109 m_tooltip.shellSurface = m_shell->createSurface(m_tooltip.surface,
this);
111 m_tooltip.plasmaSurface = m_plasmaShell->createSurface(m_tooltip.surface,
this);
114 m_tooltip.shellSurface->setTransient(m_surface, pos.toPoint());
116 if (!m_tooltip.visible) {
117 const QSize size(100, 50);
118 auto buffer = m_shm->getBuffer(size, size.width() * 4).toStrongRef();
119 buffer->setUsed(
true);
120 QImage image(buffer->address(), size.width(), size.height(), QImage::Format_ARGB32_Premultiplied);
123 m_tooltip.surface->attachBuffer(*buffer);
124 m_tooltip.surface->damage(QRect(QPoint(0, 0), size));
125 m_tooltip.surface->commit(Surface::CommitFlag::None);
126 m_tooltip.visible =
true;
130void PanelTest::hideTooltip()
132 if (!m_tooltip.visible) {
135 m_tooltip.surface->attachBuffer(Buffer::Ptr());
136 m_tooltip.surface->commit(Surface::CommitFlag::None);
137 m_tooltip.visible =
false;
140void PanelTest::moveTooltip(
const QPointF &pos)
142 if (m_tooltip.plasmaSurface) {
143 m_tooltip.plasmaSurface->setPosition(QPoint(10, 0) + pos.toPoint());
147void PanelTest::setupRegistry(Registry *registry)
149 connect(registry, &Registry::compositorAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
152 connect(registry, &Registry::shellAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
155 connect(registry, &Registry::shmAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
158 connect(registry, &Registry::seatAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
160 connect(m_seat, &Seat::hasPointerChanged,
this, [
this](
bool has) {
164 auto p = m_seat->createPointer(
this);
165 connect(p, &Pointer::buttonStateChanged,
this, [
this](quint32 serial, quint32 time, quint32 button, KWayland::Client::Pointer::ButtonState state) {
166 if (!m_windowManagement) {
169 if (state == Pointer::ButtonState::Released) {
172 if (button == BTN_LEFT) {
173 m_windowManagement->showDesktop();
174 }
else if (button == BTN_RIGHT) {
175 m_windowManagement->hideDesktop();
178 connect(p, &Pointer::entered,
this, [
this, p](quint32 serial,
const QPointF &relativeToSurface) {
179 if (p->enteredSurface() == m_surface) {
180 showTooltip(relativeToSurface);
183 connect(p, &Pointer::motion,
this, [
this, p](
const QPointF &relativeToSurface) {
184 if (p->enteredSurface() == m_surface) {
185 moveTooltip(relativeToSurface);
188 connect(p, &Pointer::left,
this, [
this] {
193 connect(registry, &Registry::plasmaShellAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
196 connect(registry, &Registry::plasmaWindowManagementAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
197 m_windowManagement =
registry->createPlasmaWindowManagement(name,
version,
this);
198 connect(m_windowManagement, &PlasmaWindowManagement::showingDesktopChanged,
this, [](
bool set) {
199 qDebug() <<
"Showing desktop changed, new state: " << set;
201 connect(m_windowManagement, &PlasmaWindowManagement::windowCreated,
this, [
this](PlasmaWindow *w) {
202 connect(w, &PlasmaWindow::titleChanged,
this, [w] {
203 qDebug() <<
"Window title changed to: " << w->title();
205 connect(w, &PlasmaWindow::activeChanged,
this, [w] {
206 qDebug() <<
"Window active changed: " << w->isActive();
208 connect(w, &PlasmaWindow::maximizedChanged,
this, [w] {
209 qDebug() <<
"Window maximized changed: " << w->isMaximized();
211 connect(w, &PlasmaWindow::maximizedChanged,
this, [w] {
212 qDebug() <<
"Window minimized changed: " << w->isMinimized();
214 connect(w, &PlasmaWindow::keepAboveChanged,
this, [w] {
215 qDebug() <<
"Window keep above changed: " << w->isKeepAbove();
217 connect(w, &PlasmaWindow::keepBelowChanged,
this, [w] {
218 qDebug() <<
"Window keep below changed: " << w->isKeepBelow();
220 connect(w, &PlasmaWindow::onAllDesktopsChanged,
this, [w] {
221 qDebug() <<
"Window on all desktops changed: " << w->isOnAllDesktops();
223 connect(w, &PlasmaWindow::fullscreenChanged,
this, [w] {
224 qDebug() <<
"Window full screen changed: " << w->isFullscreen();
226 connect(w, &PlasmaWindow::demandsAttentionChanged,
this, [w] {
227 qDebug() <<
"Window demands attention changed: " << w->isDemandingAttention();
229 connect(w, &PlasmaWindow::closeableChanged,
this, [w] {
230 qDebug() <<
"Window is closeable changed: " << w->isCloseable();
232 connect(w, &PlasmaWindow::minimizeableChanged,
this, [w] {
233 qDebug() <<
"Window is minimizeable changed: " << w->isMinimizeable();
235 connect(w, &PlasmaWindow::maximizeableChanged,
this, [w] {
236 qDebug() <<
"Window is maximizeable changed: " << w->isMaximizeable();
238 connect(w, &PlasmaWindow::fullscreenableChanged,
this, [w] {
239 qDebug() <<
"Window is fullscreenable changed: " << w->isFullscreenable();
241 connect(w, &PlasmaWindow::iconChanged,
this, [w] {
242 qDebug() <<
"Window icon changed: " << w->icon().name();
246 connect(registry, &Registry::interfacesAnnounced,
this, [
this] {
247 Q_ASSERT(m_compositor);
251 m_surface = m_compositor->createSurface(
this);
253 m_shellSurface = m_shell->createSurface(m_surface,
this);
254 Q_ASSERT(m_shellSurface);
255 m_shellSurface->setToplevel();
256 connect(m_shellSurface, &ShellSurface::sizeChanged,
this, &PanelTest::render);
258 m_plasmaShellSurface = m_plasmaShell->createSurface(m_surface,
this);
259 m_plasmaShellSurface->setPosition(QPoint(10, 0));
260 m_plasmaShellSurface->setRole(PlasmaShellSurface::Role::Panel);
264 registry->setEventQueue(m_eventQueue);
265 registry->create(m_connectionThreadObject);
269void PanelTest::render()
271 const QSize &size = m_shellSurface->size().isValid() ? m_shellSurface->size() : QSize(300, 20);
272 auto buffer = m_shm->getBuffer(size, size.width() * 4).toStrongRef();
273 buffer->setUsed(
true);
274 QImage image(buffer->address(), size.width(), size.height(), QImage::Format_ARGB32_Premultiplied);
275 image.fill(Qt::blue);
277 m_surface->attachBuffer(*buffer);
278 m_surface->damage(QRect(QPoint(0, 0), size));
279 m_surface->commit(Surface::CommitFlag::None);
280 buffer->setUsed(
false);
285 QGuiApplication app(argc, argv);
292#include "paneltest.moc"
PlasmaShellSurface * plasmaSurface
ShellSurface * shellSurface
PanelTest(QObject *parent=nullptr)
KWayland::Client::Registry * registry