2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2016-06-17 09:13:31 +00:00
|
|
|
|
2020-03-15 15:19:28 +00:00
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2020-04-29 13:59:23 +00:00
|
|
|
#include "KWayland/Client/compositor.h"
|
|
|
|
#include "KWayland/Client/connection_thread.h"
|
|
|
|
#include "KWayland/Client/event_queue.h"
|
2021-08-29 05:11:06 +00:00
|
|
|
#include "KWayland/Client/plasmashell.h"
|
2020-04-29 13:59:23 +00:00
|
|
|
#include "KWayland/Client/registry.h"
|
|
|
|
#include "KWayland/Client/shell.h"
|
|
|
|
#include "KWayland/Client/shm_pool.h"
|
|
|
|
#include "KWayland/Client/surface.h"
|
2016-06-17 09:13:31 +00:00
|
|
|
// Qt
|
|
|
|
#include <QCommandLineParser>
|
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QThread>
|
|
|
|
|
|
|
|
using namespace KWayland::Client;
|
|
|
|
|
|
|
|
class PlasmaSurfaceTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit PlasmaSurfaceTest(QObject *parent = nullptr);
|
|
|
|
virtual ~PlasmaSurfaceTest();
|
|
|
|
|
|
|
|
void init();
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
void setRole(PlasmaShellSurface::Role role)
|
|
|
|
{
|
2016-06-17 09:13:31 +00:00
|
|
|
m_role = role;
|
|
|
|
}
|
2021-08-29 05:11:06 +00:00
|
|
|
void setSkipTaskbar(bool set)
|
|
|
|
{
|
2016-06-17 09:13:31 +00:00
|
|
|
m_skipTaskbar = set;
|
|
|
|
}
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
void setSkipSwitcher(bool set)
|
|
|
|
{
|
2018-05-22 12:11:22 +00:00
|
|
|
m_skipSwitcher = set;
|
|
|
|
}
|
|
|
|
|
2016-06-17 09:13:31 +00:00
|
|
|
private:
|
|
|
|
void setupRegistry(Registry *registry);
|
|
|
|
void render();
|
|
|
|
QThread *m_connectionThread;
|
|
|
|
ConnectionThread *m_connectionThreadObject;
|
|
|
|
EventQueue *m_eventQueue = nullptr;
|
|
|
|
Compositor *m_compositor = nullptr;
|
|
|
|
Shell *m_shell = nullptr;
|
|
|
|
ShellSurface *m_shellSurface = nullptr;
|
|
|
|
ShmPool *m_shm = nullptr;
|
|
|
|
Surface *m_surface = nullptr;
|
|
|
|
PlasmaShell *m_plasmaShell = nullptr;
|
|
|
|
PlasmaShellSurface *m_plasmaShellSurface = nullptr;
|
|
|
|
PlasmaShellSurface::Role m_role = PlasmaShellSurface::Role::Normal;
|
|
|
|
bool m_skipTaskbar = false;
|
2018-05-22 12:11:22 +00:00
|
|
|
bool m_skipSwitcher = false;
|
2016-06-17 09:13:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PlasmaSurfaceTest::PlasmaSurfaceTest(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_connectionThread(new QThread(this))
|
|
|
|
, m_connectionThreadObject(new ConnectionThread())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PlasmaSurfaceTest::~PlasmaSurfaceTest()
|
|
|
|
{
|
|
|
|
m_connectionThread->quit();
|
|
|
|
m_connectionThread->wait();
|
|
|
|
m_connectionThreadObject->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaSurfaceTest::init()
|
|
|
|
{
|
2021-08-29 05:11:06 +00:00
|
|
|
connect(
|
|
|
|
m_connectionThreadObject,
|
|
|
|
&ConnectionThread::connected,
|
|
|
|
this,
|
2016-06-17 09:13:31 +00:00
|
|
|
[this] {
|
|
|
|
m_eventQueue = new EventQueue(this);
|
|
|
|
m_eventQueue->setup(m_connectionThreadObject);
|
|
|
|
|
|
|
|
Registry *registry = new Registry(this);
|
|
|
|
setupRegistry(registry);
|
|
|
|
},
|
2021-08-29 05:11:06 +00:00
|
|
|
Qt::QueuedConnection);
|
2016-06-17 09:13:31 +00:00
|
|
|
m_connectionThreadObject->moveToThread(m_connectionThread);
|
|
|
|
m_connectionThread->start();
|
|
|
|
|
|
|
|
m_connectionThreadObject->initConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaSurfaceTest::setupRegistry(Registry *registry)
|
|
|
|
{
|
2021-08-29 05:11:06 +00:00
|
|
|
connect(registry, &Registry::compositorAnnounced, this, [this, registry](quint32 name, quint32 version) {
|
|
|
|
m_compositor = registry->createCompositor(name, version, this);
|
|
|
|
});
|
|
|
|
connect(registry, &Registry::shellAnnounced, this, [this, registry](quint32 name, quint32 version) {
|
|
|
|
m_shell = registry->createShell(name, version, this);
|
|
|
|
});
|
|
|
|
connect(registry, &Registry::shmAnnounced, this, [this, registry](quint32 name, quint32 version) {
|
|
|
|
m_shm = registry->createShmPool(name, version, this);
|
|
|
|
});
|
|
|
|
connect(registry, &Registry::plasmaShellAnnounced, this, [this, registry](quint32 name, quint32 version) {
|
|
|
|
m_plasmaShell = registry->createPlasmaShell(name, version, this);
|
|
|
|
m_plasmaShell->setEventQueue(m_eventQueue);
|
|
|
|
});
|
|
|
|
connect(registry, &Registry::interfacesAnnounced, this, [this] {
|
|
|
|
Q_ASSERT(m_compositor);
|
|
|
|
Q_ASSERT(m_shell);
|
|
|
|
Q_ASSERT(m_shm);
|
|
|
|
Q_ASSERT(m_plasmaShell);
|
|
|
|
m_surface = m_compositor->createSurface(this);
|
|
|
|
Q_ASSERT(m_surface);
|
|
|
|
m_shellSurface = m_shell->createSurface(m_surface, this);
|
|
|
|
Q_ASSERT(m_shellSurface);
|
|
|
|
m_shellSurface->setToplevel();
|
|
|
|
connect(m_shellSurface, &ShellSurface::sizeChanged, this, &PlasmaSurfaceTest::render);
|
|
|
|
m_plasmaShellSurface = m_plasmaShell->createSurface(m_surface, this);
|
|
|
|
Q_ASSERT(m_plasmaShellSurface);
|
|
|
|
m_plasmaShellSurface->setSkipTaskbar(m_skipTaskbar);
|
|
|
|
m_plasmaShellSurface->setSkipSwitcher(m_skipSwitcher);
|
|
|
|
m_plasmaShellSurface->setRole(m_role);
|
|
|
|
render();
|
|
|
|
});
|
2016-06-17 09:13:31 +00:00
|
|
|
registry->setEventQueue(m_eventQueue);
|
|
|
|
registry->create(m_connectionThreadObject);
|
|
|
|
registry->setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaSurfaceTest::render()
|
|
|
|
{
|
|
|
|
const QSize &size = m_shellSurface->size().isValid() ? m_shellSurface->size() : QSize(300, 200);
|
|
|
|
auto buffer = m_shm->getBuffer(size, size.width() * 4).toStrongRef();
|
|
|
|
buffer->setUsed(true);
|
|
|
|
QImage image(buffer->address(), size.width(), size.height(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
image.fill(QColor(255, 255, 255, 128));
|
|
|
|
|
|
|
|
m_surface->attachBuffer(*buffer);
|
|
|
|
m_surface->damage(QRect(QPoint(0, 0), size));
|
|
|
|
m_surface->commit(Surface::CommitFlag::None);
|
|
|
|
buffer->setUsed(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
QCoreApplication app(argc, argv);
|
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.addHelpOption();
|
|
|
|
QCommandLineOption notificationOption(QStringLiteral("notification"));
|
|
|
|
parser.addOption(notificationOption);
|
2019-05-02 08:11:40 +00:00
|
|
|
QCommandLineOption criticalNotificationOption(QStringLiteral("criticalNotification"));
|
|
|
|
parser.addOption(criticalNotificationOption);
|
2022-05-27 21:49:37 +00:00
|
|
|
QCommandLineOption appletPopupOption(QStringLiteral("appletPopup"));
|
|
|
|
parser.addOption(appletPopupOption);
|
2016-06-17 09:13:31 +00:00
|
|
|
QCommandLineOption panelOption(QStringLiteral("panel"));
|
|
|
|
parser.addOption(panelOption);
|
|
|
|
QCommandLineOption desktopOption(QStringLiteral("desktop"));
|
|
|
|
parser.addOption(desktopOption);
|
|
|
|
QCommandLineOption osdOption(QStringLiteral("osd"));
|
|
|
|
parser.addOption(osdOption);
|
2016-06-28 10:59:57 +00:00
|
|
|
QCommandLineOption tooltipOption(QStringLiteral("tooltip"));
|
|
|
|
parser.addOption(tooltipOption);
|
2016-06-17 09:13:31 +00:00
|
|
|
QCommandLineOption skipTaskbarOption(QStringLiteral("skipTaskbar"));
|
|
|
|
parser.addOption(skipTaskbarOption);
|
|
|
|
parser.process(app);
|
2018-05-22 12:11:22 +00:00
|
|
|
QCommandLineOption skipSwitcherOption(QStringLiteral("skipSwitcher"));
|
|
|
|
parser.addOption(skipSwitcherOption);
|
|
|
|
parser.process(app);
|
2016-06-17 09:13:31 +00:00
|
|
|
|
|
|
|
PlasmaSurfaceTest client;
|
|
|
|
|
|
|
|
if (parser.isSet(notificationOption)) {
|
|
|
|
client.setRole(PlasmaShellSurface::Role::Notification);
|
2019-05-02 08:11:40 +00:00
|
|
|
} else if (parser.isSet(criticalNotificationOption)) {
|
|
|
|
client.setRole(PlasmaShellSurface::Role::CriticalNotification);
|
2022-05-27 21:49:37 +00:00
|
|
|
} else if (parser.isSet(appletPopupOption)) {
|
|
|
|
client.setRole(PlasmaShellSurface::Role::AppletPopup);
|
2016-06-17 09:13:31 +00:00
|
|
|
} else if (parser.isSet(panelOption)) {
|
|
|
|
client.setRole(PlasmaShellSurface::Role::Panel);
|
|
|
|
} else if (parser.isSet(desktopOption)) {
|
|
|
|
client.setRole(PlasmaShellSurface::Role::Desktop);
|
|
|
|
} else if (parser.isSet(osdOption)) {
|
|
|
|
client.setRole(PlasmaShellSurface::Role::OnScreenDisplay);
|
2016-06-28 10:59:57 +00:00
|
|
|
} else if (parser.isSet(tooltipOption)) {
|
|
|
|
client.setRole(PlasmaShellSurface::Role::ToolTip);
|
2016-06-17 09:13:31 +00:00
|
|
|
}
|
|
|
|
client.setSkipTaskbar(parser.isSet(skipTaskbarOption));
|
2018-05-22 12:11:22 +00:00
|
|
|
client.setSkipSwitcher(parser.isSet(skipSwitcherOption));
|
2016-06-17 09:13:31 +00:00
|
|
|
|
|
|
|
client.init();
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "plasmasurfacetest.moc"
|