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
|
/*
This file is part of the KDE libraries
SPDX-FileCopyrightText: 2023 Nicolas Fella <nicolas.fella@gmx.de>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <kwaylandextras.h>
#include <kwindowsystem.h>
#include <QApplication>
#include <QWidget>
#include "ui_kwaylandextrastest.h"
class Window : public QWidget
{
public:
Window();
private:
void updateSerial();
void requestToken();
void exportWindow();
void unexportWindow();
void setExportedHandle(const QString &handle);
Ui_KWaylandExtrasTest m_ui;
};
Window::Window()
{
m_ui.setupUi(this);
updateSerial();
connect(m_ui.serialButton, &QPushButton::clicked, this, &Window::updateSerial);
connect(m_ui.tokenButton, &QPushButton::clicked, this, &Window::requestToken);
connect(m_ui.exportButton, &QPushButton::clicked, this, &Window::exportWindow);
connect(m_ui.unexportButton, &QPushButton::clicked, this, &Window::unexportWindow);
}
void Window::updateSerial()
{
m_ui.serialLabel->setText(QString::number(KWaylandExtras::self()->lastInputSerial(windowHandle())));
}
void Window::requestToken()
{
KWaylandExtras::xdgActivationToken(windowHandle(), KWaylandExtras::self()->lastInputSerial(windowHandle()), QString())
.then(this, [this](const QString &token) {
m_ui.tokenLabel->setText(token);
});
}
void Window::exportWindow()
{
connect(
KWaylandExtras::self(),
&KWaylandExtras::windowExported,
this,
[this](QWindow *window, const QString &handle) {
Q_UNUSED(window);
setExportedHandle(handle);
},
Qt::SingleShotConnection);
KWaylandExtras::exportWindow(windowHandle());
}
void Window::unexportWindow()
{
KWaylandExtras::unexportWindow(windowHandle());
setExportedHandle(QString());
}
void Window::setExportedHandle(const QString &handle)
{
m_ui.exportedLabel->setText(handle);
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
Window window;
window.show();
return app.exec();
}
|