2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-06-20 09:21:16 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2019 Roman Gilg <subdiff@gmail.com>
|
2016-06-20 09:21:16 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-06-20 09:21:16 +00:00
|
|
|
#include "kwin_wayland_test.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2022-04-14 12:33:28 +00:00
|
|
|
#include "output.h"
|
2016-06-20 09:21:16 +00:00
|
|
|
#include "platform.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/seat_interface.h"
|
2016-06-20 09:21:16 +00:00
|
|
|
#include "wayland_server.h"
|
2022-04-22 17:39:12 +00:00
|
|
|
#include "window.h"
|
2016-06-20 09:21:16 +00:00
|
|
|
#include "workspace.h"
|
2022-04-22 10:09:02 +00:00
|
|
|
#include "xwayland/databridge.h"
|
2016-06-20 09:21:16 +00:00
|
|
|
|
|
|
|
#include <QProcess>
|
|
|
|
#include <QProcessEnvironment>
|
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
|
2018-08-21 20:06:42 +00:00
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_xwayland_selections-0");
|
2016-06-20 09:21:16 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
struct ProcessKillBeforeDeleter
|
|
|
|
{
|
2021-09-08 11:25:48 +00:00
|
|
|
static inline void cleanup(QProcess *pointer)
|
|
|
|
{
|
2022-03-25 12:20:32 +00:00
|
|
|
if (pointer) {
|
2021-09-08 11:25:48 +00:00
|
|
|
pointer->kill();
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2021-09-08 11:25:48 +00:00
|
|
|
delete pointer;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-21 20:06:42 +00:00
|
|
|
class XwaylandSelectionsTest : public QObject
|
2016-06-20 09:21:16 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void testSync_data();
|
|
|
|
void testSync();
|
|
|
|
};
|
|
|
|
|
2018-08-21 20:06:42 +00:00
|
|
|
void XwaylandSelectionsTest::initTestCase()
|
2016-06-20 09:21:16 +00:00
|
|
|
{
|
2022-03-23 10:13:38 +00:00
|
|
|
// QSKIP("Skipped as it fails for unknown reasons on build.kde.org");
|
2022-04-22 17:39:12 +00:00
|
|
|
qRegisterMetaType<KWin::Window *>();
|
2016-06-20 09:21:16 +00:00
|
|
|
qRegisterMetaType<QProcess::ExitStatus>();
|
2020-07-07 09:32:29 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
|
|
|
QVERIFY(applicationStartedSpy.isValid());
|
2016-06-20 09:21:16 +00:00
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
2022-03-23 10:13:38 +00:00
|
|
|
// QSignalSpy clipboardSyncDevicedCreated{waylandServer(), &WaylandServer::xclipboardSyncDataDeviceCreated};
|
|
|
|
// QVERIFY(clipboardSyncDevicedCreated.isValid());
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2019-08-26 21:16:53 +00:00
|
|
|
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2));
|
2016-06-20 09:21:16 +00:00
|
|
|
|
|
|
|
kwinApp()->start();
|
2020-07-07 09:32:29 +00:00
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2022-07-11 10:41:15 +00:00
|
|
|
const auto outputs = workspace()->outputs();
|
2021-08-31 07:03:05 +00:00
|
|
|
QCOMPARE(outputs.count(), 2);
|
|
|
|
QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1280, 1024));
|
|
|
|
QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 1280, 1024));
|
2021-05-08 00:08:22 +00:00
|
|
|
Test::initWaylandWorkspace();
|
2022-03-23 10:13:38 +00:00
|
|
|
// // wait till the xclipboard sync data device is created
|
|
|
|
// if (clipboardSyncDevicedCreated.empty()) {
|
|
|
|
// QVERIFY(clipboardSyncDevicedCreated.wait());
|
|
|
|
// }
|
2016-06-20 09:21:16 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 20:06:42 +00:00
|
|
|
void XwaylandSelectionsTest::testSync_data()
|
2016-06-20 09:21:16 +00:00
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("copyPlatform");
|
|
|
|
QTest::addColumn<QString>("pastePlatform");
|
|
|
|
|
2018-08-21 20:06:42 +00:00
|
|
|
QTest::newRow("x11->wayland") << QStringLiteral("xcb") << QStringLiteral("wayland");
|
|
|
|
QTest::newRow("wayland->x11") << QStringLiteral("wayland") << QStringLiteral("xcb");
|
2016-06-20 09:21:16 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 20:06:42 +00:00
|
|
|
void XwaylandSelectionsTest::testSync()
|
2016-06-20 09:21:16 +00:00
|
|
|
{
|
|
|
|
// this test verifies the syncing of X11 to Wayland clipboard
|
2017-08-25 16:18:20 +00:00
|
|
|
const QString copy = QFINDTESTDATA(QStringLiteral("copy"));
|
2016-06-20 09:21:16 +00:00
|
|
|
QVERIFY(!copy.isEmpty());
|
2017-08-25 16:18:20 +00:00
|
|
|
const QString paste = QFINDTESTDATA(QStringLiteral("paste"));
|
2016-06-20 09:21:16 +00:00
|
|
|
QVERIFY(!paste.isEmpty());
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
QSignalSpy windowAddedSpy(workspace(), &Workspace::windowAdded);
|
|
|
|
QVERIFY(windowAddedSpy.isValid());
|
2021-09-08 11:25:48 +00:00
|
|
|
QSignalSpy clipboardChangedSpy(waylandServer()->seat(), &KWaylandServer::SeatInterface::selectionChanged);
|
2016-06-20 09:21:16 +00:00
|
|
|
QVERIFY(clipboardChangedSpy.isValid());
|
|
|
|
|
|
|
|
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
|
2018-08-21 20:06:42 +00:00
|
|
|
|
|
|
|
// start the copy process
|
2016-06-20 09:21:16 +00:00
|
|
|
QFETCH(QString, copyPlatform);
|
|
|
|
environment.insert(QStringLiteral("QT_QPA_PLATFORM"), copyPlatform);
|
|
|
|
environment.insert(QStringLiteral("WAYLAND_DISPLAY"), s_socketName);
|
2021-09-08 11:25:48 +00:00
|
|
|
QScopedPointer<QProcess, ProcessKillBeforeDeleter> copyProcess(new QProcess());
|
|
|
|
copyProcess->setProcessEnvironment(environment);
|
|
|
|
copyProcess->setProcessChannelMode(QProcess::ForwardedChannels);
|
|
|
|
copyProcess->setProgram(copy);
|
|
|
|
copyProcess->start();
|
|
|
|
QVERIFY(copyProcess->waitForStarted());
|
2016-06-20 09:21:16 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
Window *copyWindow = nullptr;
|
2022-04-23 08:33:23 +00:00
|
|
|
QVERIFY(windowAddedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
copyWindow = windowAddedSpy.first().first().value<Window *>();
|
|
|
|
QVERIFY(copyWindow);
|
|
|
|
if (workspace()->activeWindow() != copyWindow) {
|
|
|
|
workspace()->activateWindow(copyWindow);
|
2016-06-20 09:21:16 +00:00
|
|
|
}
|
2022-04-23 19:51:16 +00:00
|
|
|
QCOMPARE(workspace()->activeWindow(), copyWindow);
|
2021-09-08 11:25:48 +00:00
|
|
|
clipboardChangedSpy.wait();
|
2016-06-20 09:21:16 +00:00
|
|
|
|
|
|
|
// start the paste process
|
2021-09-08 11:25:48 +00:00
|
|
|
QScopedPointer<QProcess, ProcessKillBeforeDeleter> pasteProcess(new QProcess());
|
2022-03-23 10:13:38 +00:00
|
|
|
QSignalSpy finishedSpy(pasteProcess.data(), static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished));
|
2016-06-20 09:21:16 +00:00
|
|
|
QVERIFY(finishedSpy.isValid());
|
|
|
|
QFETCH(QString, pastePlatform);
|
|
|
|
environment.insert(QStringLiteral("QT_QPA_PLATFORM"), pastePlatform);
|
2021-09-08 11:25:48 +00:00
|
|
|
pasteProcess->setProcessEnvironment(environment);
|
|
|
|
pasteProcess->setProcessChannelMode(QProcess::ForwardedChannels);
|
|
|
|
pasteProcess->setProgram(paste);
|
|
|
|
pasteProcess->start();
|
|
|
|
QVERIFY(pasteProcess->waitForStarted());
|
2016-06-20 09:21:16 +00:00
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
windowAddedSpy.clear();
|
2022-04-23 19:51:16 +00:00
|
|
|
Window *pasteWindow = nullptr;
|
2022-04-23 08:33:23 +00:00
|
|
|
QVERIFY(windowAddedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
pasteWindow = windowAddedSpy.last().first().value<Window *>();
|
2022-04-23 08:33:23 +00:00
|
|
|
QCOMPARE(windowAddedSpy.count(), 1);
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(pasteWindow);
|
2018-08-21 20:06:42 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
if (workspace()->activeWindow() != pasteWindow) {
|
2022-04-23 08:33:23 +00:00
|
|
|
QSignalSpy windowActivatedSpy(workspace(), &Workspace::windowActivated);
|
|
|
|
QVERIFY(windowActivatedSpy.isValid());
|
2022-04-23 19:51:16 +00:00
|
|
|
workspace()->activateWindow(pasteWindow);
|
2022-04-23 08:33:23 +00:00
|
|
|
QVERIFY(windowActivatedSpy.wait());
|
2016-06-20 09:21:16 +00:00
|
|
|
}
|
2022-04-23 19:51:16 +00:00
|
|
|
QTRY_COMPARE(workspace()->activeWindow(), pasteWindow);
|
2016-06-20 09:21:16 +00:00
|
|
|
QVERIFY(finishedSpy.wait());
|
|
|
|
QCOMPARE(finishedSpy.first().first().toInt(), 0);
|
|
|
|
}
|
|
|
|
|
2018-08-21 20:06:42 +00:00
|
|
|
WAYLANDTEST_MAIN(XwaylandSelectionsTest)
|
|
|
|
#include "xwayland_selections_test.moc"
|