2020-12-21 11:01:38 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
#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"
|
2023-02-09 13:07:56 +00:00
|
|
|
#include "pointer_input.h"
|
2020-12-21 11:01:38 +00:00
|
|
|
#include "wayland_server.h"
|
2022-04-22 17:39:12 +00:00
|
|
|
#include "window.h"
|
2020-12-21 11:01:38 +00:00
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KWayland/Client/surface.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_screens-0");
|
|
|
|
|
|
|
|
class ScreensTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
void testCurrent_data();
|
|
|
|
void testCurrent();
|
|
|
|
void testCurrentWithFollowsMouse_data();
|
|
|
|
void testCurrentWithFollowsMouse();
|
|
|
|
void testCurrentPoint_data();
|
|
|
|
void testCurrentPoint();
|
|
|
|
};
|
|
|
|
|
|
|
|
void ScreensTest::initTestCase()
|
|
|
|
{
|
2022-04-22 17:39:12 +00:00
|
|
|
qRegisterMetaType<KWin::Window *>();
|
2020-12-21 11:01:38 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
|
|
|
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),
|
|
|
|
});
|
2020-12-21 11:01:38 +00:00
|
|
|
|
2021-08-28 18:58:29 +00:00
|
|
|
kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig));
|
|
|
|
|
2020-12-21 11:01:38 +00:00
|
|
|
kwinApp()->start();
|
|
|
|
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));
|
2020-12-21 11:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreensTest::init()
|
|
|
|
{
|
2021-08-28 18:58:29 +00:00
|
|
|
workspace()->setActiveOutput(QPoint(640, 512));
|
2023-02-09 13:07:56 +00:00
|
|
|
KWin::input()->pointer()->warp(QPoint(640, 512));
|
2020-12-21 11:01:38 +00:00
|
|
|
|
|
|
|
QVERIFY(Test::setupWaylandConnection());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void purge(KConfig *config)
|
|
|
|
{
|
|
|
|
const QStringList groups = config->groupList();
|
|
|
|
for (const QString &group : groups) {
|
|
|
|
config->deleteGroup(group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreensTest::cleanup()
|
|
|
|
{
|
2022-04-23 19:51:16 +00:00
|
|
|
// Destroy the wayland connection of the test window.
|
2020-12-21 11:01:38 +00:00
|
|
|
Test::destroyWaylandConnection();
|
|
|
|
|
|
|
|
// Wipe the screens config clean.
|
2021-08-28 18:58:29 +00:00
|
|
|
auto config = kwinApp()->config();
|
2020-12-21 11:01:38 +00:00
|
|
|
purge(config.data());
|
|
|
|
config->sync();
|
2021-08-28 18:58:29 +00:00
|
|
|
workspace()->slotReconfigure();
|
2020-12-21 11:01:38 +00:00
|
|
|
|
|
|
|
// Reset the screen layout of the test environment.
|
2023-05-08 10:16:00 +00:00
|
|
|
Test::setOutputConfig({
|
|
|
|
QRect(0, 0, 1280, 1024),
|
|
|
|
QRect(1280, 0, 1280, 1024),
|
|
|
|
});
|
2020-12-21 11:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreensTest::testCurrent_data()
|
|
|
|
{
|
2021-08-28 18:58:29 +00:00
|
|
|
QTest::addColumn<int>("currentId");
|
2020-12-21 11:01:38 +00:00
|
|
|
|
2021-08-28 18:58:29 +00:00
|
|
|
QTest::newRow("first") << 0;
|
|
|
|
QTest::newRow("second") << 1;
|
2020-12-21 11:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreensTest::testCurrent()
|
|
|
|
{
|
2021-08-28 18:58:29 +00:00
|
|
|
QFETCH(int, currentId);
|
2022-07-21 09:23:43 +00:00
|
|
|
Output *output = workspace()->outputs().at(currentId);
|
2020-12-21 11:01:38 +00:00
|
|
|
|
2021-08-28 18:58:29 +00:00
|
|
|
// Disable "active screen follows mouse"
|
|
|
|
auto group = kwinApp()->config()->group("Windows");
|
|
|
|
group.writeEntry("ActiveMouseScreen", false);
|
|
|
|
group.sync();
|
|
|
|
workspace()->slotReconfigure();
|
2021-08-28 18:40:12 +00:00
|
|
|
|
2021-08-28 18:58:29 +00:00
|
|
|
workspace()->setActiveOutput(output);
|
|
|
|
QCOMPARE(workspace()->activeOutput(), output);
|
2020-12-21 11:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreensTest::testCurrentWithFollowsMouse_data()
|
|
|
|
{
|
2023-10-19 06:50:15 +00:00
|
|
|
QTest::addColumn<QList<QRect>>("geometries");
|
2020-12-21 11:01:38 +00:00
|
|
|
QTest::addColumn<QPoint>("cursorPos");
|
2021-08-28 18:40:12 +00:00
|
|
|
QTest::addColumn<int>("expectedId");
|
2020-12-21 11:01:38 +00:00
|
|
|
|
2023-10-19 06:50:15 +00:00
|
|
|
QTest::newRow("cloned") << QList<QRect>{{QRect{0, 0, 200, 100}, QRect{0, 0, 200, 100}}} << QPoint(50, 50) << 0;
|
|
|
|
QTest::newRow("adjacent-0") << QList<QRect>{{QRect{0, 0, 200, 100}, QRect{200, 100, 400, 300}}} << QPoint(199, 99) << 0;
|
|
|
|
QTest::newRow("adjacent-1") << QList<QRect>{{QRect{0, 0, 200, 100}, QRect{200, 100, 400, 300}}} << QPoint(200, 100) << 1;
|
|
|
|
QTest::newRow("gap") << QList<QRect>{{QRect{0, 0, 10, 20}, QRect{20, 40, 10, 20}}} << QPoint(15, 30) << 1;
|
2020-12-21 11:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreensTest::testCurrentWithFollowsMouse()
|
|
|
|
{
|
2021-08-28 18:58:29 +00:00
|
|
|
// Enable "active screen follows mouse"
|
|
|
|
auto group = kwinApp()->config()->group("Windows");
|
|
|
|
group.writeEntry("ActiveMouseScreen", true);
|
|
|
|
group.sync();
|
|
|
|
workspace()->slotReconfigure();
|
2020-12-21 11:01:38 +00:00
|
|
|
|
2023-10-19 06:50:15 +00:00
|
|
|
QFETCH(QList<QRect>, geometries);
|
2023-05-08 10:16:00 +00:00
|
|
|
Test::setOutputConfig(geometries);
|
2020-12-21 11:01:38 +00:00
|
|
|
|
|
|
|
QFETCH(QPoint, cursorPos);
|
2023-02-09 13:07:56 +00:00
|
|
|
KWin::input()->pointer()->warp(cursorPos);
|
2021-08-28 18:40:12 +00:00
|
|
|
|
|
|
|
QFETCH(int, expectedId);
|
2022-07-21 09:23:43 +00:00
|
|
|
Output *expected = workspace()->outputs().at(expectedId);
|
2021-08-28 18:58:29 +00:00
|
|
|
QCOMPARE(workspace()->activeOutput(), expected);
|
2020-12-21 11:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreensTest::testCurrentPoint_data()
|
|
|
|
{
|
2023-10-19 06:50:15 +00:00
|
|
|
QTest::addColumn<QList<QRect>>("geometries");
|
2020-12-21 11:01:38 +00:00
|
|
|
QTest::addColumn<QPoint>("cursorPos");
|
2021-08-28 18:40:12 +00:00
|
|
|
QTest::addColumn<int>("expectedId");
|
2020-12-21 11:01:38 +00:00
|
|
|
|
2023-10-19 06:50:15 +00:00
|
|
|
QTest::newRow("cloned") << QList<QRect>{{QRect{0, 0, 200, 100}, QRect{0, 0, 200, 100}}} << QPoint(50, 50) << 0;
|
|
|
|
QTest::newRow("adjacent-0") << QList<QRect>{{QRect{0, 0, 200, 100}, QRect{200, 100, 400, 300}}} << QPoint(199, 99) << 0;
|
|
|
|
QTest::newRow("adjacent-1") << QList<QRect>{{QRect{0, 0, 200, 100}, QRect{200, 100, 400, 300}}} << QPoint(200, 100) << 1;
|
|
|
|
QTest::newRow("gap") << QList<QRect>{{QRect{0, 0, 10, 20}, QRect{20, 40, 10, 20}}} << QPoint(15, 30) << 1;
|
2020-12-21 11:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreensTest::testCurrentPoint()
|
|
|
|
{
|
2023-10-19 06:50:15 +00:00
|
|
|
QFETCH(QList<QRect>, geometries);
|
2023-05-08 10:16:00 +00:00
|
|
|
Test::setOutputConfig(geometries);
|
2020-12-21 11:01:38 +00:00
|
|
|
|
2021-08-28 18:58:29 +00:00
|
|
|
// Disable "active screen follows mouse"
|
|
|
|
auto group = kwinApp()->config()->group("Windows");
|
|
|
|
group.writeEntry("ActiveMouseScreen", false);
|
|
|
|
group.sync();
|
|
|
|
workspace()->slotReconfigure();
|
2021-04-26 14:07:58 +00:00
|
|
|
|
2020-12-21 11:01:38 +00:00
|
|
|
QFETCH(QPoint, cursorPos);
|
2021-08-28 18:58:29 +00:00
|
|
|
workspace()->setActiveOutput(cursorPos);
|
2021-08-28 18:40:12 +00:00
|
|
|
|
|
|
|
QFETCH(int, expectedId);
|
2022-07-21 09:23:43 +00:00
|
|
|
Output *expected = workspace()->outputs().at(expectedId);
|
2021-08-28 18:58:29 +00:00
|
|
|
QCOMPARE(workspace()->activeOutput(), expected);
|
2020-12-21 11:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace KWin
|
|
|
|
|
|
|
|
WAYLANDTEST_MAIN(KWin::ScreensTest)
|
|
|
|
#include "screens_test.moc"
|