[kwin_wayland] Add SeatInterface to server module
So far the Seat interface is provided together with pointer and keyboard. As always touch is not yet implemented. The pointer interface is still lacking the set cursor callback. Keyboard on the other hand is complete. Both Keyboard and Pointer have the concept of a focused surface and only to the bound interface belonging to the same client as the focused surface events are sent. The change comes with a set of new auto tests also verifying the client side which wasn't possible before as we couldn't fake events.
This commit is contained in:
parent
0848113845
commit
3c7a59ba9e
1 changed files with 161 additions and 0 deletions
161
src/wayland/test_seat.cpp
Normal file
161
src/wayland/test_seat.cpp
Normal file
|
@ -0,0 +1,161 @@
|
||||||
|
/********************************************************************
|
||||||
|
KWin - the KDE window manager
|
||||||
|
This file is part of the KDE project.
|
||||||
|
|
||||||
|
Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*********************************************************************/
|
||||||
|
// Qt
|
||||||
|
#include <QtTest/QtTest>
|
||||||
|
// WaylandServer
|
||||||
|
#include "../../wayland_server/display.h"
|
||||||
|
#include "../../wayland_server/seat_interface.h"
|
||||||
|
|
||||||
|
using namespace KWin::WaylandServer;
|
||||||
|
|
||||||
|
|
||||||
|
class TestWaylandServerSeat : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
private Q_SLOTS:
|
||||||
|
void testCapabilities();
|
||||||
|
void testName();
|
||||||
|
void testPointerButton();
|
||||||
|
void testPointerPos();
|
||||||
|
};
|
||||||
|
|
||||||
|
static const QString s_socketName = QStringLiteral("kwin-wayland-server-seat-test-0");
|
||||||
|
|
||||||
|
void TestWaylandServerSeat::testCapabilities()
|
||||||
|
{
|
||||||
|
Display display;
|
||||||
|
display.setSocketName(s_socketName);
|
||||||
|
display.start();
|
||||||
|
SeatInterface *seat = display.createSeat();
|
||||||
|
QVERIFY(!seat->hasKeyboard());
|
||||||
|
QVERIFY(!seat->hasPointer());
|
||||||
|
QVERIFY(!seat->hasTouch());
|
||||||
|
|
||||||
|
QSignalSpy keyboardSpy(seat, SIGNAL(hasKeyboardChanged(bool)));
|
||||||
|
QVERIFY(keyboardSpy.isValid());
|
||||||
|
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);
|
||||||
|
|
||||||
|
QSignalSpy pointerSpy(seat, SIGNAL(hasPointerChanged(bool)));
|
||||||
|
QVERIFY(pointerSpy.isValid());
|
||||||
|
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);
|
||||||
|
|
||||||
|
QSignalSpy touchSpy(seat, SIGNAL(hasTouchChanged(bool)));
|
||||||
|
QVERIFY(touchSpy.isValid());
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
Display display;
|
||||||
|
display.setSocketName(s_socketName);
|
||||||
|
display.start();
|
||||||
|
SeatInterface *seat = display.createSeat();
|
||||||
|
QCOMPARE(seat->name(), QString());
|
||||||
|
|
||||||
|
QSignalSpy nameSpy(seat, SIGNAL(nameChanged(QString)));
|
||||||
|
QVERIFY(nameSpy.isValid());
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
Display display;
|
||||||
|
display.setSocketName(s_socketName);
|
||||||
|
display.start();
|
||||||
|
SeatInterface *seat = display.createSeat();
|
||||||
|
PointerInterface *pointer = seat->pointer();
|
||||||
|
|
||||||
|
// no button pressed yet, should be released and no serial
|
||||||
|
QVERIFY(!pointer->isButtonPressed(0));
|
||||||
|
QVERIFY(!pointer->isButtonPressed(1));
|
||||||
|
QCOMPARE(pointer->buttonSerial(0), quint32(0));
|
||||||
|
QCOMPARE(pointer->buttonSerial(1), quint32(0));
|
||||||
|
|
||||||
|
// mark the button as pressed
|
||||||
|
pointer->buttonPressed(0);
|
||||||
|
QVERIFY(pointer->isButtonPressed(0));
|
||||||
|
QCOMPARE(pointer->buttonSerial(0), display.serial());
|
||||||
|
|
||||||
|
// other button should still be unpressed
|
||||||
|
QVERIFY(!pointer->isButtonPressed(1));
|
||||||
|
QCOMPARE(pointer->buttonSerial(1), quint32(0));
|
||||||
|
|
||||||
|
// release it again
|
||||||
|
pointer->buttonReleased(0);
|
||||||
|
QVERIFY(!pointer->isButtonPressed(0));
|
||||||
|
QCOMPARE(pointer->buttonSerial(0), display.serial());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestWaylandServerSeat::testPointerPos()
|
||||||
|
{
|
||||||
|
Display display;
|
||||||
|
display.setSocketName(s_socketName);
|
||||||
|
display.start();
|
||||||
|
SeatInterface *seat = display.createSeat();
|
||||||
|
PointerInterface *pointer = seat->pointer();
|
||||||
|
QSignalSpy posSpy(pointer, SIGNAL(globalPosChanged(QPoint)));
|
||||||
|
QVERIFY(posSpy.isValid());
|
||||||
|
|
||||||
|
QCOMPARE(pointer->globalPos(), QPoint());
|
||||||
|
|
||||||
|
pointer->setGlobalPos(QPoint(10, 15));
|
||||||
|
QCOMPARE(pointer->globalPos(), QPoint(10, 15));
|
||||||
|
QCOMPARE(posSpy.count(), 1);
|
||||||
|
QCOMPARE(posSpy.first().first().toPoint(), QPoint(10, 15));
|
||||||
|
|
||||||
|
pointer->setGlobalPos(QPoint(10, 15));
|
||||||
|
QCOMPARE(posSpy.count(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
QTEST_MAIN(TestWaylandServerSeat)
|
||||||
|
#include "test_seat.moc"
|
Loading…
Reference in a new issue