KWin
Loading...
Searching...
No Matches
screens_test.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#include "kwin_wayland_test.h"
10
11#include "core/output.h"
12#include "pointer_input.h"
13#include "wayland_server.h"
14#include "window.h"
15#include "workspace.h"
16
17#include <KConfigGroup>
18#include <KWayland/Client/surface.h>
19
20namespace KWin
21{
22
23static const QString s_socketName = QStringLiteral("wayland_test_kwin_screens-0");
24
25class ScreensTest : public QObject
26{
27 Q_OBJECT
28
29private Q_SLOTS:
30 void initTestCase();
31 void init();
32 void cleanup();
33 void testCurrent_data();
34 void testCurrent();
35 void testCurrentWithFollowsMouse_data();
36 void testCurrentWithFollowsMouse();
37 void testCurrentPoint_data();
38 void testCurrentPoint();
39};
40
41void ScreensTest::initTestCase()
42{
43 qRegisterMetaType<KWin::Window *>();
44 QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
45 QVERIFY(waylandServer()->init(s_socketName));
47 QRect(0, 0, 1280, 1024),
48 QRect(1280, 0, 1280, 1024),
49 });
50
51 kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig));
52
53 kwinApp()->start();
54 QVERIFY(applicationStartedSpy.wait());
55 const auto outputs = workspace()->outputs();
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));
59}
60
61void ScreensTest::init()
62{
63 workspace()->setActiveOutput(QPoint(640, 512));
64 KWin::input()->pointer()->warp(QPoint(640, 512));
65
67}
68
69static void purge(KConfig *config)
70{
71 const QStringList groups = config->groupList();
72 for (const QString &group : groups) {
73 config->deleteGroup(group);
74 }
75}
76
77void ScreensTest::cleanup()
78{
79 // Destroy the wayland connection of the test window.
81
82 // Wipe the screens config clean.
83 auto config = kwinApp()->config();
84 purge(config.data());
85 config->sync();
87
88 // Reset the screen layout of the test environment.
90 QRect(0, 0, 1280, 1024),
91 QRect(1280, 0, 1280, 1024),
92 });
93}
94
95void ScreensTest::testCurrent_data()
96{
97 QTest::addColumn<int>("currentId");
98
99 QTest::newRow("first") << 0;
100 QTest::newRow("second") << 1;
101}
102
103void ScreensTest::testCurrent()
104{
105 QFETCH(int, currentId);
106 Output *output = workspace()->outputs().at(currentId);
107
108 // Disable "active screen follows mouse"
109 auto group = kwinApp()->config()->group(QStringLiteral("Windows"));
110 group.writeEntry("ActiveMouseScreen", false);
111 group.sync();
113
114 workspace()->setActiveOutput(output);
115 QCOMPARE(workspace()->activeOutput(), output);
116}
117
118void ScreensTest::testCurrentWithFollowsMouse_data()
119{
120 QTest::addColumn<QList<QRect>>("geometries");
121 QTest::addColumn<QPoint>("cursorPos");
122 QTest::addColumn<int>("expectedId");
123
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;
128}
129
130void ScreensTest::testCurrentWithFollowsMouse()
131{
132 // Enable "active screen follows mouse"
133 auto group = kwinApp()->config()->group(QStringLiteral("Windows"));
134 group.writeEntry("ActiveMouseScreen", true);
135 group.sync();
137
138 QFETCH(QList<QRect>, geometries);
139 Test::setOutputConfig(geometries);
140
141 QFETCH(QPoint, cursorPos);
142 KWin::input()->pointer()->warp(cursorPos);
143
144 QFETCH(int, expectedId);
145 Output *expected = workspace()->outputs().at(expectedId);
146 QCOMPARE(workspace()->activeOutput(), expected);
147}
148
149void ScreensTest::testCurrentPoint_data()
150{
151 QTest::addColumn<QList<QRect>>("geometries");
152 QTest::addColumn<QPoint>("cursorPos");
153 QTest::addColumn<int>("expectedId");
154
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;
159}
160
161void ScreensTest::testCurrentPoint()
162{
163 QFETCH(QList<QRect>, geometries);
164 Test::setOutputConfig(geometries);
165
166 // Disable "active screen follows mouse"
167 auto group = kwinApp()->config()->group(QStringLiteral("Windows"));
168 group.writeEntry("ActiveMouseScreen", false);
169 group.sync();
171
172 QFETCH(QPoint, cursorPos);
173 workspace()->setActiveOutput(cursorPos);
174
175 QFETCH(int, expectedId);
176 Output *expected = workspace()->outputs().at(expectedId);
177 QCOMPARE(workspace()->activeOutput(), expected);
178}
179
180} // namespace KWin
181
183#include "screens_test.moc"
PointerInputRedirection * pointer() const
Definition input.h:220
void warp(const QPointF &pos)
QList< Output * > outputs() const
Definition workspace.h:762
void setActiveOutput(Output *output)
void slotReconfigure()
#define WAYLANDTEST_MAIN(TestObject)
void destroyWaylandConnection()
void setOutputConfig(const QList< QRect > &geometries)
bool setupWaylandConnection(AdditionalWaylandInterfaces flags=AdditionalWaylandInterfaces())
WaylandServer * waylandServer()
Workspace * workspace()
Definition workspace.h:830
InputRedirection * input()
Definition input.h:549