17#include <KConfigGroup>
18#include <KWayland/Client/surface.h>
23static const QString s_socketName = QStringLiteral(
"wayland_test_kwin_screens-0");
33 void testCurrent_data();
35 void testCurrentWithFollowsMouse_data();
36 void testCurrentWithFollowsMouse();
37 void testCurrentPoint_data();
38 void testCurrentPoint();
41void ScreensTest::initTestCase()
43 qRegisterMetaType<KWin::Window *>();
47 QRect(0, 0, 1280, 1024),
48 QRect(1280, 0, 1280, 1024),
51 kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig));
54 QVERIFY(applicationStartedSpy.wait());
56 QCOMPARE(outputs.count(), 2);
57 QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1280, 1024));
58 QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 1280, 1024));
61void ScreensTest::init()
69static void purge(KConfig *config)
71 const QStringList groups = config->groupList();
72 for (
const QString &group : groups) {
73 config->deleteGroup(group);
77void ScreensTest::cleanup()
83 auto config = kwinApp()->config();
90 QRect(0, 0, 1280, 1024),
91 QRect(1280, 0, 1280, 1024),
95void ScreensTest::testCurrent_data()
97 QTest::addColumn<int>(
"currentId");
99 QTest::newRow(
"first") << 0;
100 QTest::newRow(
"second") << 1;
103void ScreensTest::testCurrent()
105 QFETCH(
int, currentId);
109 auto group = kwinApp()->config()->group(QStringLiteral(
"Windows"));
110 group.writeEntry(
"ActiveMouseScreen",
false);
115 QCOMPARE(
workspace()->activeOutput(), output);
118void ScreensTest::testCurrentWithFollowsMouse_data()
120 QTest::addColumn<QList<QRect>>(
"geometries");
121 QTest::addColumn<QPoint>(
"cursorPos");
122 QTest::addColumn<int>(
"expectedId");
124 QTest::newRow(
"cloned") << QList<QRect>{{QRect{0, 0, 200, 100}, QRect{0, 0, 200, 100}}} << QPoint(50, 50) << 0;
125 QTest::newRow(
"adjacent-0") << QList<QRect>{{QRect{0, 0, 200, 100}, QRect{200, 100, 400, 300}}} << QPoint(199, 99) << 0;
126 QTest::newRow(
"adjacent-1") << QList<QRect>{{QRect{0, 0, 200, 100}, QRect{200, 100, 400, 300}}} << QPoint(200, 100) << 1;
127 QTest::newRow(
"gap") << QList<QRect>{{QRect{0, 0, 10, 20}, QRect{20, 40, 10, 20}}} << QPoint(15, 30) << 1;
130void ScreensTest::testCurrentWithFollowsMouse()
133 auto group = kwinApp()->config()->group(QStringLiteral(
"Windows"));
134 group.writeEntry(
"ActiveMouseScreen",
true);
138 QFETCH(QList<QRect>, geometries);
141 QFETCH(QPoint, cursorPos);
144 QFETCH(
int, expectedId);
146 QCOMPARE(
workspace()->activeOutput(), expected);
149void ScreensTest::testCurrentPoint_data()
151 QTest::addColumn<QList<QRect>>(
"geometries");
152 QTest::addColumn<QPoint>(
"cursorPos");
153 QTest::addColumn<int>(
"expectedId");
155 QTest::newRow(
"cloned") << QList<QRect>{{QRect{0, 0, 200, 100}, QRect{0, 0, 200, 100}}} << QPoint(50, 50) << 0;
156 QTest::newRow(
"adjacent-0") << QList<QRect>{{QRect{0, 0, 200, 100}, QRect{200, 100, 400, 300}}} << QPoint(199, 99) << 0;
157 QTest::newRow(
"adjacent-1") << QList<QRect>{{QRect{0, 0, 200, 100}, QRect{200, 100, 400, 300}}} << QPoint(200, 100) << 1;
158 QTest::newRow(
"gap") << QList<QRect>{{QRect{0, 0, 10, 20}, QRect{20, 40, 10, 20}}} << QPoint(15, 30) << 1;
161void ScreensTest::testCurrentPoint()
163 QFETCH(QList<QRect>, geometries);
167 auto group = kwinApp()->config()->group(QStringLiteral(
"Windows"));
168 group.writeEntry(
"ActiveMouseScreen",
false);
172 QFETCH(QPoint, cursorPos);
175 QFETCH(
int, expectedId);
177 QCOMPARE(
workspace()->activeOutput(), expected);
183#include "screens_test.moc"
QList< Output * > outputs() const
void setActiveOutput(Output *output)
#define WAYLANDTEST_MAIN(TestObject)
void destroyWaylandConnection()
void setOutputConfig(const QList< QRect > &geometries)
bool setupWaylandConnection(AdditionalWaylandInterfaces flags=AdditionalWaylandInterfaces())
WaylandServer * waylandServer()
InputRedirection * input()