2021-12-10 10:22:19 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kwin_wayland_test.h"
|
|
|
|
|
|
|
|
#include "cursor.h"
|
2022-04-14 12:33:28 +00:00
|
|
|
#include "output.h"
|
2022-04-14 10:51:20 +00:00
|
|
|
#include "outputconfiguration.h"
|
2021-12-10 10:22:19 +00:00
|
|
|
#include "platform.h"
|
|
|
|
#include "wayland_server.h"
|
2022-04-22 17:39:12 +00:00
|
|
|
#include "window.h"
|
2021-12-10 10:22:19 +00:00
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
#include <KWayland/Client/surface.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_output_changes-0");
|
|
|
|
|
|
|
|
class OutputChangesTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testWindowSticksToOutputAfterOutputIsDisabled();
|
|
|
|
void testWindowSticksToOutputAfterAnotherOutputIsDisabled();
|
|
|
|
void testWindowSticksToOutputAfterOutputIsMoved();
|
|
|
|
};
|
|
|
|
|
|
|
|
void OutputChangesTest::initTestCase()
|
|
|
|
{
|
2022-04-22 17:39:12 +00:00
|
|
|
qRegisterMetaType<Window *>();
|
2021-12-10 10:22:19 +00:00
|
|
|
|
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
|
|
|
QVERIFY(applicationStartedSpy.isValid());
|
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
|
|
|
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2));
|
|
|
|
|
|
|
|
kwinApp()->start();
|
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
|
|
|
const auto outputs = kwinApp()->platform()->enabledOutputs();
|
|
|
|
QCOMPARE(outputs.count(), 2);
|
|
|
|
QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1280, 1024));
|
|
|
|
QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 1280, 1024));
|
|
|
|
Test::initWaylandWorkspace();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OutputChangesTest::init()
|
|
|
|
{
|
|
|
|
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2));
|
|
|
|
QVERIFY(Test::setupWaylandConnection());
|
|
|
|
|
|
|
|
workspace()->setActiveOutput(QPoint(640, 512));
|
|
|
|
Cursors::self()->mouse()->setPos(QPoint(640, 512));
|
|
|
|
}
|
|
|
|
|
|
|
|
void OutputChangesTest::cleanup()
|
|
|
|
{
|
|
|
|
Test::destroyWaylandConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OutputChangesTest::testWindowSticksToOutputAfterOutputIsDisabled()
|
|
|
|
{
|
|
|
|
auto outputs = kwinApp()->platform()->outputs();
|
|
|
|
|
|
|
|
// Create a window.
|
|
|
|
QScopedPointer<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.data()));
|
|
|
|
auto client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue);
|
|
|
|
QVERIFY(client);
|
|
|
|
|
|
|
|
// Move the window to some predefined position so the test is more robust.
|
|
|
|
client->move(QPoint(42, 67));
|
|
|
|
QCOMPARE(client->frameGeometry(), QRect(42, 67, 100, 50));
|
|
|
|
|
|
|
|
// Disable the output where the window is on.
|
2022-04-14 10:51:20 +00:00
|
|
|
OutputConfiguration config;
|
2021-12-10 10:22:19 +00:00
|
|
|
{
|
2022-04-14 08:32:51 +00:00
|
|
|
auto changeSet = config.changeSet(outputs[0]);
|
2021-12-10 10:22:19 +00:00
|
|
|
changeSet->enabled = false;
|
|
|
|
}
|
|
|
|
kwinApp()->platform()->applyOutputChanges(config);
|
|
|
|
|
|
|
|
// The window will be sent to the second output, which is at (1280, 0).
|
|
|
|
QCOMPARE(client->frameGeometry(), QRect(1280 + 42, 0 + 67, 100, 50));
|
|
|
|
}
|
|
|
|
|
|
|
|
void OutputChangesTest::testWindowSticksToOutputAfterAnotherOutputIsDisabled()
|
|
|
|
{
|
|
|
|
auto outputs = kwinApp()->platform()->outputs();
|
|
|
|
|
|
|
|
// Create a window.
|
|
|
|
QScopedPointer<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.data()));
|
|
|
|
auto client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue);
|
|
|
|
QVERIFY(client);
|
|
|
|
|
|
|
|
// Move the window to the second output.
|
|
|
|
client->move(QPoint(1280 + 42, 67));
|
|
|
|
QCOMPARE(client->frameGeometry(), QRect(1280 + 42, 67, 100, 50));
|
|
|
|
|
|
|
|
// Disable the first output.
|
2022-04-14 10:51:20 +00:00
|
|
|
OutputConfiguration config;
|
2021-12-10 10:22:19 +00:00
|
|
|
{
|
2022-04-14 08:32:51 +00:00
|
|
|
auto changeSet = config.changeSet(outputs[0]);
|
2021-12-10 10:22:19 +00:00
|
|
|
changeSet->enabled = false;
|
|
|
|
}
|
|
|
|
{
|
2022-04-14 08:32:51 +00:00
|
|
|
auto changeSet = config.changeSet(outputs[1]);
|
2021-12-10 10:22:19 +00:00
|
|
|
changeSet->pos = QPoint(0, 0);
|
|
|
|
}
|
|
|
|
kwinApp()->platform()->applyOutputChanges(config);
|
|
|
|
|
|
|
|
// The position of the window relative to its output should remain the same.
|
|
|
|
QCOMPARE(client->frameGeometry(), QRect(42, 67, 100, 50));
|
|
|
|
}
|
|
|
|
|
|
|
|
void OutputChangesTest::testWindowSticksToOutputAfterOutputIsMoved()
|
|
|
|
{
|
|
|
|
auto outputs = kwinApp()->platform()->outputs();
|
|
|
|
|
|
|
|
// Create a window.
|
|
|
|
QScopedPointer<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.data()));
|
|
|
|
auto client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue);
|
|
|
|
QVERIFY(client);
|
|
|
|
|
|
|
|
// Move the window to some predefined position so the test is more robust.
|
|
|
|
client->move(QPoint(42, 67));
|
|
|
|
QCOMPARE(client->frameGeometry(), QRect(42, 67, 100, 50));
|
|
|
|
|
|
|
|
// Disable the first output.
|
2022-04-14 10:51:20 +00:00
|
|
|
OutputConfiguration config;
|
2021-12-10 10:22:19 +00:00
|
|
|
{
|
2022-04-14 08:32:51 +00:00
|
|
|
auto changeSet = config.changeSet(outputs[0]);
|
2021-12-10 10:22:19 +00:00
|
|
|
changeSet->pos = QPoint(-10, 20);
|
|
|
|
}
|
|
|
|
kwinApp()->platform()->applyOutputChanges(config);
|
|
|
|
|
|
|
|
// The position of the window relative to its output should remain the same.
|
|
|
|
QCOMPARE(client->frameGeometry(), QRect(-10 + 42, 20 + 67, 100, 50));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
WAYLANDTEST_MAIN(KWin::OutputChangesTest)
|
|
|
|
#include "outputchanges_test.moc"
|