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/datasource.h"
11#include "KWayland/Client/event_queue.h"
12#include "KWayland/Client/keyboard.h"
13#include "KWayland/Client/pointer.h"
14#include "KWayland/Client/registry.h"
15#include "KWayland/Client/seat.h"
16#include "KWayland/Client/shell.h"
17#include "KWayland/Client/shm_pool.h"
18#include "KWayland/Client/surface.h"
20#include <QCoreApplication>
32 explicit CopyClient(QObject *parent =
nullptr);
38 void setupRegistry(Registry *registry);
40 void copy(
const QString &mimeType, qint32 fd);
41 QThread *m_connectionThread;
42 ConnectionThread *m_connectionThreadObject;
43 EventQueue *m_eventQueue =
nullptr;
44 Compositor *m_compositor =
nullptr;
45 DataDeviceManager *m_dataDeviceManager =
nullptr;
46 DataDevice *m_dataDevice =
nullptr;
47 DataSource *m_copySource =
nullptr;
48 Seat *m_seat =
nullptr;
49 Shell *m_shell =
nullptr;
50 ShellSurface *m_shellSurface =
nullptr;
51 ShmPool *m_shm =
nullptr;
52 Surface *m_surface =
nullptr;
57 , m_connectionThread(new QThread(this))
58 , m_connectionThreadObject(new ConnectionThread())
64 m_connectionThread->quit();
65 m_connectionThread->wait();
66 m_connectionThreadObject->deleteLater();
72 m_connectionThreadObject,
73 &ConnectionThread::connected,
76 m_eventQueue =
new EventQueue(
this);
77 m_eventQueue->setup(m_connectionThreadObject);
79 Registry *registry =
new Registry(
this);
80 setupRegistry(registry);
82 Qt::QueuedConnection);
83 m_connectionThreadObject->moveToThread(m_connectionThread);
84 m_connectionThread->start();
86 m_connectionThreadObject->initConnection();
89void CopyClient::setupRegistry(Registry *registry)
91 connect(registry, &Registry::compositorAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
92 m_compositor = registry->createCompositor(name,
version,
this);
94 connect(registry, &Registry::shellAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
97 connect(registry, &Registry::shmAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
100 connect(registry, &Registry::seatAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
102 connect(m_seat, &Seat::hasPointerChanged,
this, [
this] {
103 auto p = m_seat->createPointer(
this);
104 connect(p, &Pointer::entered,
this, [
this](quint32 serial) {
106 m_dataDevice->setSelection(serial, m_copySource);
111 connect(registry, &Registry::dataDeviceManagerAnnounced,
this, [
this, registry](quint32 name, quint32
version) {
112 m_dataDeviceManager =
registry->createDataDeviceManager(name,
version,
this);
114 connect(registry, &Registry::interfacesAnnounced,
this, [
this] {
115 Q_ASSERT(m_compositor);
116 Q_ASSERT(m_dataDeviceManager);
120 m_surface = m_compositor->createSurface(
this);
122 m_shellSurface = m_shell->createSurface(m_surface,
this);
123 Q_ASSERT(m_shellSurface);
124 m_shellSurface->setFullscreen();
125 connect(m_shellSurface, &ShellSurface::sizeChanged,
this, &CopyClient::render);
127 m_dataDevice = m_dataDeviceManager->getDataDevice(m_seat,
this);
128 m_copySource = m_dataDeviceManager->createDataSource(
this);
129 m_copySource->offer(QStringLiteral(
"text/plain"));
130 connect(m_copySource, &DataSource::sendDataRequested,
this, &CopyClient::copy);
132 registry->setEventQueue(m_eventQueue);
133 registry->create(m_connectionThreadObject);
137void CopyClient::render()
139 const QSize &size = m_shellSurface->size();
140 auto buffer = m_shm->getBuffer(size, size.width() * 4).toStrongRef();
141 buffer->setUsed(
true);
142 QImage image(buffer->address(), size.width(), size.height(), QImage::Format_ARGB32_Premultiplied);
143 image.fill(Qt::green);
145 m_surface->attachBuffer(*buffer);
146 m_surface->damage(QRect(QPoint(0, 0), size));
147 m_surface->commit(Surface::CommitFlag::None);
148 buffer->setUsed(
false);
151void CopyClient::copy(
const QString &mimeType, qint32 fd)
153 qDebug() <<
"Requested to copy for mimeType" << mimeType;
155 if (c.open(fd, QFile::WriteOnly, QFile::AutoCloseHandle)) {
156 c.write(QByteArrayLiteral(
"foo"));
158 qDebug() <<
"Copied foo";
164 QCoreApplication app(argc, argv);
171#include "copyclient.moc"
CopyClient(QObject *parent=nullptr)
KWayland::Client::Registry * registry