2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2020-03-15 15:19:28 +00:00
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2014-09-02 07:34:31 +00:00
|
|
|
// Qt
|
2023-07-03 19:28:19 +00:00
|
|
|
#include <QSignalSpy>
|
|
|
|
#include <QTest>
|
2014-09-02 07:34:31 +00:00
|
|
|
// WaylandServer
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/display.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/keyboard.h"
|
|
|
|
#include "wayland/pointer.h"
|
|
|
|
#include "wayland/seat.h"
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2014-09-02 07:34:31 +00:00
|
|
|
|
|
|
|
class TestWaylandServerSeat : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void testCapabilities();
|
|
|
|
void testName();
|
|
|
|
void testPointerButton();
|
|
|
|
void testPointerPos();
|
2015-09-02 14:00:11 +00:00
|
|
|
void testRepeatInfo();
|
2015-12-15 14:47:19 +00:00
|
|
|
void testMultiple();
|
2014-09-02 07:34:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("kwin-wayland-server-seat-test-0");
|
|
|
|
|
|
|
|
void TestWaylandServerSeat::testCapabilities()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::Display display;
|
2020-10-19 15:52:56 +00:00
|
|
|
display.addSocketName(s_socketName);
|
2014-09-02 07:34:31 +00:00
|
|
|
display.start();
|
2022-07-26 17:08:38 +00:00
|
|
|
SeatInterface *seat = new SeatInterface(&display, &display);
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(!seat->hasKeyboard());
|
|
|
|
QVERIFY(!seat->hasPointer());
|
|
|
|
QVERIFY(!seat->hasTouch());
|
|
|
|
|
2022-09-14 08:28:27 +00:00
|
|
|
QSignalSpy keyboardSpy(seat, &SeatInterface::hasKeyboardChanged);
|
2014-09-02 07:34:31 +00:00
|
|
|
seat->setHasKeyboard(true);
|
|
|
|
QCOMPARE(keyboardSpy.count(), 1);
|
|
|
|
QVERIFY(keyboardSpy.last().first().toBool());
|
|
|
|
QVERIFY(seat->hasKeyboard());
|
|
|
|
seat->setHasKeyboard(false);
|
|
|
|
QCOMPARE(keyboardSpy.count(), 2);
|
|
|
|
QVERIFY(!keyboardSpy.last().first().toBool());
|
|
|
|
QVERIFY(!seat->hasKeyboard());
|
|
|
|
seat->setHasKeyboard(false);
|
|
|
|
QCOMPARE(keyboardSpy.count(), 2);
|
|
|
|
|
2022-09-14 08:28:27 +00:00
|
|
|
QSignalSpy pointerSpy(seat, &SeatInterface::hasPointerChanged);
|
2014-09-02 07:34:31 +00:00
|
|
|
seat->setHasPointer(true);
|
|
|
|
QCOMPARE(pointerSpy.count(), 1);
|
|
|
|
QVERIFY(pointerSpy.last().first().toBool());
|
|
|
|
QVERIFY(seat->hasPointer());
|
|
|
|
seat->setHasPointer(false);
|
|
|
|
QCOMPARE(pointerSpy.count(), 2);
|
|
|
|
QVERIFY(!pointerSpy.last().first().toBool());
|
|
|
|
QVERIFY(!seat->hasPointer());
|
|
|
|
seat->setHasPointer(false);
|
|
|
|
QCOMPARE(pointerSpy.count(), 2);
|
|
|
|
|
2022-09-14 08:28:27 +00:00
|
|
|
QSignalSpy touchSpy(seat, &SeatInterface::hasTouchChanged);
|
2014-09-02 07:34:31 +00:00
|
|
|
seat->setHasTouch(true);
|
|
|
|
QCOMPARE(touchSpy.count(), 1);
|
|
|
|
QVERIFY(touchSpy.last().first().toBool());
|
|
|
|
QVERIFY(seat->hasTouch());
|
|
|
|
seat->setHasTouch(false);
|
|
|
|
QCOMPARE(touchSpy.count(), 2);
|
|
|
|
QVERIFY(!touchSpy.last().first().toBool());
|
|
|
|
QVERIFY(!seat->hasTouch());
|
|
|
|
seat->setHasTouch(false);
|
|
|
|
QCOMPARE(touchSpy.count(), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandServerSeat::testName()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::Display display;
|
2020-10-19 15:52:56 +00:00
|
|
|
display.addSocketName(s_socketName);
|
2014-09-02 07:34:31 +00:00
|
|
|
display.start();
|
2022-07-26 17:08:38 +00:00
|
|
|
SeatInterface *seat = new SeatInterface(&display, &display);
|
2014-09-02 07:34:31 +00:00
|
|
|
QCOMPARE(seat->name(), QString());
|
|
|
|
|
2022-09-14 08:28:27 +00:00
|
|
|
QSignalSpy nameSpy(seat, &SeatInterface::nameChanged);
|
2014-09-02 07:34:31 +00:00
|
|
|
const QString name = QStringLiteral("foobar");
|
|
|
|
seat->setName(name);
|
|
|
|
QCOMPARE(seat->name(), name);
|
|
|
|
QCOMPARE(nameSpy.count(), 1);
|
|
|
|
QCOMPARE(nameSpy.first().first().toString(), name);
|
|
|
|
seat->setName(name);
|
|
|
|
QCOMPARE(nameSpy.count(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandServerSeat::testPointerButton()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::Display display;
|
2020-10-19 15:52:56 +00:00
|
|
|
display.addSocketName(s_socketName);
|
2014-09-02 07:34:31 +00:00
|
|
|
display.start();
|
2022-07-26 17:08:38 +00:00
|
|
|
SeatInterface *seat = new SeatInterface(&display, &display);
|
2021-02-12 22:29:45 +00:00
|
|
|
seat->setHasPointer(true);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
|
|
|
// no button pressed yet, should be released and no serial
|
2014-11-26 10:50:52 +00:00
|
|
|
QVERIFY(!seat->isPointerButtonPressed(0));
|
|
|
|
QVERIFY(!seat->isPointerButtonPressed(1));
|
|
|
|
QCOMPARE(seat->pointerButtonSerial(0), quint32(0));
|
|
|
|
QCOMPARE(seat->pointerButtonSerial(1), quint32(0));
|
2014-09-02 07:34:31 +00:00
|
|
|
|
|
|
|
// mark the button as pressed
|
2021-03-15 17:58:39 +00:00
|
|
|
seat->notifyPointerButton(0, PointerButtonState::Pressed);
|
2021-03-11 08:24:47 +00:00
|
|
|
seat->notifyPointerFrame();
|
2014-11-26 10:50:52 +00:00
|
|
|
QVERIFY(seat->isPointerButtonPressed(0));
|
|
|
|
QCOMPARE(seat->pointerButtonSerial(0), display.serial());
|
2014-09-02 07:34:31 +00:00
|
|
|
|
|
|
|
// other button should still be unpressed
|
2014-11-26 10:50:52 +00:00
|
|
|
QVERIFY(!seat->isPointerButtonPressed(1));
|
|
|
|
QCOMPARE(seat->pointerButtonSerial(1), quint32(0));
|
2014-09-02 07:34:31 +00:00
|
|
|
|
|
|
|
// release it again
|
2021-03-15 17:58:39 +00:00
|
|
|
seat->notifyPointerButton(0, PointerButtonState::Released);
|
2021-03-11 08:24:47 +00:00
|
|
|
seat->notifyPointerFrame();
|
2014-11-26 10:50:52 +00:00
|
|
|
QVERIFY(!seat->isPointerButtonPressed(0));
|
|
|
|
QCOMPARE(seat->pointerButtonSerial(0), display.serial());
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandServerSeat::testPointerPos()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::Display display;
|
2020-10-19 15:52:56 +00:00
|
|
|
display.addSocketName(s_socketName);
|
2014-09-02 07:34:31 +00:00
|
|
|
display.start();
|
2022-07-26 17:08:38 +00:00
|
|
|
SeatInterface *seat = new SeatInterface(&display, &display);
|
2021-02-12 22:29:45 +00:00
|
|
|
seat->setHasPointer(true);
|
2022-09-14 08:28:27 +00:00
|
|
|
QSignalSpy seatPosSpy(seat, &SeatInterface::pointerPosChanged);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2014-11-25 13:24:52 +00:00
|
|
|
QCOMPARE(seat->pointerPos(), QPointF());
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2021-03-11 08:24:47 +00:00
|
|
|
seat->notifyPointerMotion(QPointF(10, 15));
|
|
|
|
seat->notifyPointerFrame();
|
2014-11-25 13:24:52 +00:00
|
|
|
QCOMPARE(seat->pointerPos(), QPointF(10, 15));
|
|
|
|
QCOMPARE(seatPosSpy.count(), 1);
|
|
|
|
QCOMPARE(seatPosSpy.first().first().toPointF(), QPointF(10, 15));
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2021-03-11 08:24:47 +00:00
|
|
|
seat->notifyPointerMotion(QPointF(10, 15));
|
|
|
|
seat->notifyPointerFrame();
|
2014-11-25 13:24:52 +00:00
|
|
|
QCOMPARE(seatPosSpy.count(), 1);
|
|
|
|
|
2021-03-11 08:24:47 +00:00
|
|
|
seat->notifyPointerMotion(QPointF(5, 7));
|
|
|
|
seat->notifyPointerFrame();
|
2014-11-25 13:24:52 +00:00
|
|
|
QCOMPARE(seat->pointerPos(), QPointF(5, 7));
|
|
|
|
QCOMPARE(seatPosSpy.count(), 2);
|
|
|
|
QCOMPARE(seatPosSpy.first().first().toPointF(), QPointF(10, 15));
|
|
|
|
QCOMPARE(seatPosSpy.last().first().toPointF(), QPointF(5, 7));
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
2015-09-02 14:00:11 +00:00
|
|
|
void TestWaylandServerSeat::testRepeatInfo()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::Display display;
|
2020-10-19 15:52:56 +00:00
|
|
|
display.addSocketName(s_socketName);
|
2015-09-02 14:00:11 +00:00
|
|
|
display.start();
|
2022-07-26 17:08:38 +00:00
|
|
|
SeatInterface *seat = new SeatInterface(&display, &display);
|
2020-10-02 14:22:59 +00:00
|
|
|
seat->setHasKeyboard(true);
|
|
|
|
QCOMPARE(seat->keyboard()->keyRepeatRate(), 0);
|
|
|
|
QCOMPARE(seat->keyboard()->keyRepeatDelay(), 0);
|
2020-11-06 04:33:47 +00:00
|
|
|
seat->keyboard()->setRepeatInfo(25, 660);
|
2020-10-02 14:22:59 +00:00
|
|
|
QCOMPARE(seat->keyboard()->keyRepeatRate(), 25);
|
|
|
|
QCOMPARE(seat->keyboard()->keyRepeatDelay(), 660);
|
2015-09-02 14:00:11 +00:00
|
|
|
// setting negative values should result in 0
|
2020-11-06 04:33:47 +00:00
|
|
|
seat->keyboard()->setRepeatInfo(-25, -660);
|
2020-10-02 14:22:59 +00:00
|
|
|
QCOMPARE(seat->keyboard()->keyRepeatRate(), 0);
|
|
|
|
QCOMPARE(seat->keyboard()->keyRepeatDelay(), 0);
|
2015-09-02 14:00:11 +00:00
|
|
|
}
|
|
|
|
|
2015-12-15 14:47:19 +00:00
|
|
|
void TestWaylandServerSeat::testMultiple()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::Display display;
|
2020-10-19 15:52:56 +00:00
|
|
|
display.addSocketName(s_socketName);
|
2015-12-15 14:47:19 +00:00
|
|
|
display.start();
|
|
|
|
QVERIFY(display.seats().isEmpty());
|
2022-07-26 17:08:38 +00:00
|
|
|
SeatInterface *seat1 = new SeatInterface(&display, &display);
|
2015-12-15 14:47:19 +00:00
|
|
|
QCOMPARE(display.seats().count(), 1);
|
|
|
|
QCOMPARE(display.seats().at(0), seat1);
|
2022-07-26 17:08:38 +00:00
|
|
|
SeatInterface *seat2 = new SeatInterface(&display, &display);
|
2015-12-15 14:47:19 +00:00
|
|
|
QCOMPARE(display.seats().count(), 2);
|
|
|
|
QCOMPARE(display.seats().at(0), seat1);
|
|
|
|
QCOMPARE(display.seats().at(1), seat2);
|
2022-07-26 17:08:38 +00:00
|
|
|
SeatInterface *seat3 = new SeatInterface(&display, &display);
|
2015-12-15 14:47:19 +00:00
|
|
|
QCOMPARE(display.seats().count(), 3);
|
|
|
|
QCOMPARE(display.seats().at(0), seat1);
|
|
|
|
QCOMPARE(display.seats().at(1), seat2);
|
|
|
|
QCOMPARE(display.seats().at(2), seat3);
|
|
|
|
|
|
|
|
delete seat3;
|
|
|
|
QCOMPARE(display.seats().count(), 2);
|
|
|
|
QCOMPARE(display.seats().at(0), seat1);
|
|
|
|
QCOMPARE(display.seats().at(1), seat2);
|
|
|
|
|
|
|
|
delete seat2;
|
|
|
|
QCOMPARE(display.seats().count(), 1);
|
|
|
|
QCOMPARE(display.seats().at(0), seat1);
|
|
|
|
|
|
|
|
delete seat1;
|
|
|
|
QCOMPARE(display.seats().count(), 0);
|
|
|
|
}
|
|
|
|
|
2014-09-23 10:00:17 +00:00
|
|
|
QTEST_GUILESS_MAIN(TestWaylandServerSeat)
|
2014-09-02 07:34:31 +00:00
|
|
|
#include "test_seat.moc"
|