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-08-29 07:55:49 +00:00
|
|
|
#include "core/output.h"
|
2024-08-02 09:41:20 +00:00
|
|
|
#include "wayland/display.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/seat.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>
|
2023-07-03 19:28:19 +00:00
|
|
|
#include <QSignalSpy>
|
2016-06-20 09:21:16 +00:00
|
|
|
|
2024-08-02 09:41:20 +00:00
|
|
|
#include <linux/input-event-codes.h>
|
|
|
|
|
2016-06-20 09:21:16 +00:00
|
|
|
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
|
|
|
|
{
|
2022-08-01 21:29:02 +00:00
|
|
|
void operator()(QProcess *pointer)
|
2021-09-08 11:25:48 +00:00
|
|
|
{
|
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);
|
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));
|
2023-05-08 10:16:00 +00:00
|
|
|
Test::setOutputConfig({
|
|
|
|
QRect(0, 0, 1280, 1024),
|
|
|
|
QRect(1280, 0, 1280, 1024),
|
|
|
|
});
|
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));
|
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);
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy clipboardChangedSpy(waylandServer()->seat(), &SeatInterface::selectionChanged);
|
2016-06-20 09:21:16 +00:00
|
|
|
|
|
|
|
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);
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<QProcess, ProcessKillBeforeDeleter> copyProcess(new QProcess());
|
2021-09-08 11:25:48 +00:00
|
|
|
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);
|
2024-08-02 09:41:20 +00:00
|
|
|
// Wait until the window has a surface so we can pass input to it
|
|
|
|
QTRY_VERIFY(copyWindow->surface());
|
|
|
|
Test::keyboardKeyPressed(KEY_C, waylandServer()->display()->nextSerial());
|
|
|
|
Test::keyboardKeyReleased(KEY_C, waylandServer()->display()->nextSerial());
|
2021-09-08 11:25:48 +00:00
|
|
|
clipboardChangedSpy.wait();
|
2016-06-20 09:21:16 +00:00
|
|
|
|
|
|
|
// start the paste process
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<QProcess, ProcessKillBeforeDeleter> pasteProcess(new QProcess());
|
|
|
|
QSignalSpy finishedSpy(pasteProcess.get(), static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished));
|
2016-06-20 09:21:16 +00:00
|
|
|
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);
|
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"
|