KWin
Loading...
Searching...
No Matches
test_seat.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6// Qt
7#include <QSignalSpy>
8#include <QTest>
9// WaylandServer
10#include "wayland/display.h"
11#include "wayland/keyboard.h"
12#include "wayland/pointer.h"
13#include "wayland/seat.h"
14
15using namespace KWin;
16
17class TestWaylandServerSeat : public QObject
18{
19 Q_OBJECT
20private Q_SLOTS:
21 void testCapabilities();
22 void testName();
23 void testPointerButton();
24 void testPointerPos();
25 void testRepeatInfo();
26 void testMultiple();
27};
28
29static const QString s_socketName = QStringLiteral("kwin-wayland-server-seat-test-0");
30
31void TestWaylandServerSeat::testCapabilities()
32{
33 KWin::Display display;
34 display.addSocketName(s_socketName);
35 display.start();
36 SeatInterface *seat = new SeatInterface(&display, &display);
37 QVERIFY(!seat->hasKeyboard());
38 QVERIFY(!seat->hasPointer());
39 QVERIFY(!seat->hasTouch());
40
41 QSignalSpy keyboardSpy(seat, &SeatInterface::hasKeyboardChanged);
42 seat->setHasKeyboard(true);
43 QCOMPARE(keyboardSpy.count(), 1);
44 QVERIFY(keyboardSpy.last().first().toBool());
45 QVERIFY(seat->hasKeyboard());
46 seat->setHasKeyboard(false);
47 QCOMPARE(keyboardSpy.count(), 2);
48 QVERIFY(!keyboardSpy.last().first().toBool());
49 QVERIFY(!seat->hasKeyboard());
50 seat->setHasKeyboard(false);
51 QCOMPARE(keyboardSpy.count(), 2);
52
53 QSignalSpy pointerSpy(seat, &SeatInterface::hasPointerChanged);
54 seat->setHasPointer(true);
55 QCOMPARE(pointerSpy.count(), 1);
56 QVERIFY(pointerSpy.last().first().toBool());
57 QVERIFY(seat->hasPointer());
58 seat->setHasPointer(false);
59 QCOMPARE(pointerSpy.count(), 2);
60 QVERIFY(!pointerSpy.last().first().toBool());
61 QVERIFY(!seat->hasPointer());
62 seat->setHasPointer(false);
63 QCOMPARE(pointerSpy.count(), 2);
64
65 QSignalSpy touchSpy(seat, &SeatInterface::hasTouchChanged);
66 seat->setHasTouch(true);
67 QCOMPARE(touchSpy.count(), 1);
68 QVERIFY(touchSpy.last().first().toBool());
69 QVERIFY(seat->hasTouch());
70 seat->setHasTouch(false);
71 QCOMPARE(touchSpy.count(), 2);
72 QVERIFY(!touchSpy.last().first().toBool());
73 QVERIFY(!seat->hasTouch());
74 seat->setHasTouch(false);
75 QCOMPARE(touchSpy.count(), 2);
76}
77
78void TestWaylandServerSeat::testName()
79{
80 KWin::Display display;
81 display.addSocketName(s_socketName);
82 display.start();
83 SeatInterface *seat = new SeatInterface(&display, &display);
84 QCOMPARE(seat->name(), QString());
85
86 QSignalSpy nameSpy(seat, &SeatInterface::nameChanged);
87 const QString name = QStringLiteral("foobar");
88 seat->setName(name);
89 QCOMPARE(seat->name(), name);
90 QCOMPARE(nameSpy.count(), 1);
91 QCOMPARE(nameSpy.first().first().toString(), name);
92 seat->setName(name);
93 QCOMPARE(nameSpy.count(), 1);
94}
95
96void TestWaylandServerSeat::testPointerButton()
97{
98 KWin::Display display;
99 display.addSocketName(s_socketName);
100 display.start();
101 SeatInterface *seat = new SeatInterface(&display, &display);
102 seat->setHasPointer(true);
103
104 // no button pressed yet, should be released and no serial
105 QVERIFY(!seat->isPointerButtonPressed(0));
106 QVERIFY(!seat->isPointerButtonPressed(1));
107 QCOMPARE(seat->pointerButtonSerial(0), quint32(0));
108 QCOMPARE(seat->pointerButtonSerial(1), quint32(0));
109
110 // mark the button as pressed
111 seat->notifyPointerButton(0, PointerButtonState::Pressed);
112 seat->notifyPointerFrame();
113 QVERIFY(seat->isPointerButtonPressed(0));
114 QCOMPARE(seat->pointerButtonSerial(0), display.serial());
115
116 // other button should still be unpressed
117 QVERIFY(!seat->isPointerButtonPressed(1));
118 QCOMPARE(seat->pointerButtonSerial(1), quint32(0));
119
120 // release it again
121 seat->notifyPointerButton(0, PointerButtonState::Released);
122 seat->notifyPointerFrame();
123 QVERIFY(!seat->isPointerButtonPressed(0));
124 QCOMPARE(seat->pointerButtonSerial(0), display.serial());
125}
126
127void TestWaylandServerSeat::testPointerPos()
128{
129 KWin::Display display;
130 display.addSocketName(s_socketName);
131 display.start();
132 SeatInterface *seat = new SeatInterface(&display, &display);
133 seat->setHasPointer(true);
134 QSignalSpy seatPosSpy(seat, &SeatInterface::pointerPosChanged);
135
136 QCOMPARE(seat->pointerPos(), QPointF());
137
138 seat->notifyPointerMotion(QPointF(10, 15));
139 seat->notifyPointerFrame();
140 QCOMPARE(seat->pointerPos(), QPointF(10, 15));
141 QCOMPARE(seatPosSpy.count(), 1);
142 QCOMPARE(seatPosSpy.first().first().toPointF(), QPointF(10, 15));
143
144 seat->notifyPointerMotion(QPointF(10, 15));
145 seat->notifyPointerFrame();
146 QCOMPARE(seatPosSpy.count(), 1);
147
148 seat->notifyPointerMotion(QPointF(5, 7));
149 seat->notifyPointerFrame();
150 QCOMPARE(seat->pointerPos(), QPointF(5, 7));
151 QCOMPARE(seatPosSpy.count(), 2);
152 QCOMPARE(seatPosSpy.first().first().toPointF(), QPointF(10, 15));
153 QCOMPARE(seatPosSpy.last().first().toPointF(), QPointF(5, 7));
154}
155
156void TestWaylandServerSeat::testRepeatInfo()
157{
158 KWin::Display display;
159 display.addSocketName(s_socketName);
160 display.start();
161 SeatInterface *seat = new SeatInterface(&display, &display);
162 seat->setHasKeyboard(true);
163 QCOMPARE(seat->keyboard()->keyRepeatRate(), 0);
164 QCOMPARE(seat->keyboard()->keyRepeatDelay(), 0);
165 seat->keyboard()->setRepeatInfo(25, 660);
166 QCOMPARE(seat->keyboard()->keyRepeatRate(), 25);
167 QCOMPARE(seat->keyboard()->keyRepeatDelay(), 660);
168 // setting negative values should result in 0
169 seat->keyboard()->setRepeatInfo(-25, -660);
170 QCOMPARE(seat->keyboard()->keyRepeatRate(), 0);
171 QCOMPARE(seat->keyboard()->keyRepeatDelay(), 0);
172}
173
174void TestWaylandServerSeat::testMultiple()
175{
176 KWin::Display display;
177 display.addSocketName(s_socketName);
178 display.start();
179 QVERIFY(display.seats().isEmpty());
180 SeatInterface *seat1 = new SeatInterface(&display, &display);
181 QCOMPARE(display.seats().count(), 1);
182 QCOMPARE(display.seats().at(0), seat1);
183 SeatInterface *seat2 = new SeatInterface(&display, &display);
184 QCOMPARE(display.seats().count(), 2);
185 QCOMPARE(display.seats().at(0), seat1);
186 QCOMPARE(display.seats().at(1), seat2);
187 SeatInterface *seat3 = new SeatInterface(&display, &display);
188 QCOMPARE(display.seats().count(), 3);
189 QCOMPARE(display.seats().at(0), seat1);
190 QCOMPARE(display.seats().at(1), seat2);
191 QCOMPARE(display.seats().at(2), seat3);
192
193 delete seat3;
194 QCOMPARE(display.seats().count(), 2);
195 QCOMPARE(display.seats().at(0), seat1);
196 QCOMPARE(display.seats().at(1), seat2);
197
198 delete seat2;
199 QCOMPARE(display.seats().count(), 1);
200 QCOMPARE(display.seats().at(0), seat1);
201
202 delete seat1;
203 QCOMPARE(display.seats().count(), 0);
204}
205
206QTEST_GUILESS_MAIN(TestWaylandServerSeat)
207#include "test_seat.moc"
Class holding the Wayland server display loop.
Definition display.h:34
quint32 serial()
Definition display.cpp:139
bool addSocketName(const QString &name=QString())
Definition display.cpp:68
QList< SeatInterface * > seats() const
Definition display.cpp:195
bool start()
Definition display.cpp:92
Represents a Seat on the Wayland Display.
Definition seat.h:134
void hasTouchChanged(bool)
void hasKeyboardChanged(bool)
void pointerPosChanged(const QPointF &pos)
void nameChanged(const QString &)
void hasPointerChanged(bool)
KWayland::Client::Seat * seat