1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/*
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "qwayland-xdg-shell.h"
#include "qwayland-xx-session-management-v1.h"
#include <QtGui/qpa/qplatformnativeinterface.h>
#include <QApplication>
#include <QCommandLineOption>
#include <QCommandLineParser>
#include <QDebug>
#include <QPainter>
#include <QWidget>
#include <QWindow>
#include <QtWaylandClient/QWaylandClientExtensionTemplate>
#include <qpa/qplatformwindow_p.h>
class XdgSessionManagerV1 : public QWaylandClientExtensionTemplate<XdgSessionManagerV1, &QtWayland::xx_session_manager_v1::destroy>, public QtWayland::xx_session_manager_v1
{
public:
XdgSessionManagerV1()
: QWaylandClientExtensionTemplate<XdgSessionManagerV1, &QtWayland::xx_session_manager_v1::destroy>(1)
{
initialize();
}
};
class XdgSessionV1 : public QtWayland::xx_session_v1
{
public:
~XdgSessionV1() override
{
destroy();
}
protected:
void xx_session_v1_created(const QString &id) override
{
qDebug() << "xx_session_v1 created" << id;
}
void xx_session_v1_restored() override
{
qDebug() << "xx_session_v1 restored";
}
};
class XdgToplevelSessionV1 : public QtWayland::xx_toplevel_session_v1
{
public:
~XdgToplevelSessionV1() override
{
destroy();
}
protected:
void xx_toplevel_session_v1_restored(struct ::xdg_toplevel *surface) override
{
qDebug() << "xx_toplevel_session_v1 restored";
}
};
class XdgSessionDemo : public QObject
{
Q_OBJECT
public:
~XdgSessionDemo();
void setSessionId(const QString &sessionId);
void setToplevelId(const QString &toplevelId);
void start();
private:
QString m_sessionId;
QString m_toplevelId;
XdgSessionManagerV1 m_sessionManager;
XdgSessionV1 m_session;
XdgToplevelSessionV1 m_toplevelSession;
};
XdgSessionDemo::~XdgSessionDemo()
{
}
void XdgSessionDemo::setSessionId(const QString &sessionId)
{
m_sessionId = sessionId;
}
void XdgSessionDemo::setToplevelId(const QString &toplevelId)
{
m_toplevelId = toplevelId;
}
void XdgSessionDemo::start()
{
QWidget *window = new QWidget(nullptr);
if (!m_sessionManager.isActive()) {
qCritical() << "No session manager available, this test cannot do nothing useful";
}
if (m_sessionId.isEmpty()) {
m_session.init(m_sessionManager.get_session(XdgSessionManagerV1::reason_launch, QString()));
} else {
m_session.init(m_sessionManager.get_session(XdgSessionManagerV1::reason_session_restore, m_sessionId));
}
window->resize(200, 200);
Q_ASSERT(!m_toplevelId.isEmpty());
window->createWinId();
if (auto waylandWindow = window->windowHandle()->nativeInterface<QNativeInterface::Private::QWaylandWindow>()) {
connect(waylandWindow, &QNativeInterface::Private::QWaylandWindow::surfaceRoleCreated, this, [this, waylandWindow]() {
auto topLevelObject = waylandWindow->surfaceRole<xdg_toplevel>();
Q_ASSERT(topLevelObject);
m_toplevelSession.init(m_session.restore_toplevel(topLevelObject, m_toplevelId));
});
} else {
qCritical() << "No wayland window interface available";
}
window->show();
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QCommandLineParser parser;
parser.addHelpOption();
QCommandLineOption sessionIdOption(QStringLiteral("session-id"),
QStringLiteral("The session id"),
QStringLiteral("session-id"));
parser.addOption(sessionIdOption);
QCommandLineOption toplevelIdOption(QStringLiteral("toplevel-id"),
QStringLiteral("The toplevel id"),
QStringLiteral("toplevel-id"));
toplevelIdOption.setDefaultValue(QStringLiteral("main"));
parser.addOption(toplevelIdOption);
parser.process(app);
XdgSessionDemo client;
client.setSessionId(parser.value(sessionIdOption));
client.setToplevelId(parser.value(toplevelIdOption));
client.start();
return app.exec();
}
#include "xdgsessiontest.moc"
|