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 <QMimeType>
|
|
|
|
#include <QSignalSpy>
|
|
|
|
#include <QTest>
|
2014-09-02 07:34:31 +00:00
|
|
|
// KWin
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/compositor.h"
|
|
|
|
#include "wayland/datadevicemanager.h"
|
|
|
|
#include "wayland/datasource.h"
|
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/pointergestures_v1.h"
|
|
|
|
#include "wayland/relativepointer_v1.h"
|
|
|
|
#include "wayland/seat.h"
|
|
|
|
#include "wayland/subcompositor.h"
|
|
|
|
#include "wayland/surface.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
|
2020-04-29 13:59:23 +00:00
|
|
|
#include "KWayland/Client/compositor.h"
|
|
|
|
#include "KWayland/Client/connection_thread.h"
|
|
|
|
#include "KWayland/Client/datadevice.h"
|
|
|
|
#include "KWayland/Client/datadevicemanager.h"
|
|
|
|
#include "KWayland/Client/datasource.h"
|
|
|
|
#include "KWayland/Client/event_queue.h"
|
|
|
|
#include "KWayland/Client/keyboard.h"
|
|
|
|
#include "KWayland/Client/pointer.h"
|
|
|
|
#include "KWayland/Client/pointergestures.h"
|
|
|
|
#include "KWayland/Client/registry.h"
|
|
|
|
#include "KWayland/Client/relativepointer.h"
|
|
|
|
#include "KWayland/Client/seat.h"
|
|
|
|
#include "KWayland/Client/shm_pool.h"
|
|
|
|
#include "KWayland/Client/subcompositor.h"
|
|
|
|
#include "KWayland/Client/subsurface.h"
|
2021-08-29 05:11:06 +00:00
|
|
|
#include "KWayland/Client/surface.h"
|
2020-04-29 13:59:23 +00:00
|
|
|
#include "KWayland/Client/touch.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
|
2014-09-02 07:34:31 +00:00
|
|
|
// Wayland
|
2021-08-05 08:21:29 +00:00
|
|
|
#include "qwayland-pointer-gestures-unstable-v1.h"
|
2014-09-02 07:34:31 +00:00
|
|
|
#include <wayland-client-protocol.h>
|
|
|
|
|
|
|
|
#include <linux/input.h>
|
2016-06-28 15:02:22 +00:00
|
|
|
// System
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2022-12-21 00:55:20 +00:00
|
|
|
using namespace std::literals;
|
|
|
|
|
2023-04-21 14:30:58 +00:00
|
|
|
class WaylandSyncPoint : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2023-04-23 20:06:04 +00:00
|
|
|
explicit WaylandSyncPoint(KWayland::Client::ConnectionThread *connection, KWayland::Client::EventQueue *eventQueue)
|
2023-04-21 14:30:58 +00:00
|
|
|
{
|
|
|
|
static const wl_callback_listener listener = {
|
|
|
|
.done = [](void *data, wl_callback *callback, uint32_t callback_data) {
|
|
|
|
auto syncPoint = static_cast<WaylandSyncPoint *>(data);
|
|
|
|
Q_EMIT syncPoint->done();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-04-23 20:06:04 +00:00
|
|
|
m_callback = wl_display_sync(connection->display());
|
|
|
|
eventQueue->addProxy(m_callback);
|
2023-04-21 14:30:58 +00:00
|
|
|
wl_callback_add_listener(m_callback, &listener, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
~WaylandSyncPoint() override
|
|
|
|
{
|
|
|
|
wl_callback_destroy(m_callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void done();
|
|
|
|
|
|
|
|
private:
|
|
|
|
wl_callback *m_callback;
|
|
|
|
};
|
|
|
|
|
2014-09-02 07:34:31 +00:00
|
|
|
class TestWaylandSeat : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit TestWaylandSeat(QObject *parent = nullptr);
|
|
|
|
private Q_SLOTS:
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testName();
|
|
|
|
void testCapabilities_data();
|
|
|
|
void testCapabilities();
|
|
|
|
void testPointer();
|
2015-12-07 10:45:34 +00:00
|
|
|
void testPointerTransformation_data();
|
|
|
|
void testPointerTransformation();
|
2014-11-10 13:51:09 +00:00
|
|
|
void testPointerButton_data();
|
|
|
|
void testPointerButton();
|
2016-04-06 07:52:13 +00:00
|
|
|
void testPointerSubSurfaceTree();
|
2016-10-26 08:27:14 +00:00
|
|
|
void testPointerSwipeGesture_data();
|
|
|
|
void testPointerSwipeGesture();
|
|
|
|
void testPointerPinchGesture_data();
|
|
|
|
void testPointerPinchGesture();
|
2021-08-05 08:21:29 +00:00
|
|
|
void testPointerHoldGesture_data();
|
|
|
|
void testPointerHoldGesture();
|
2019-02-11 16:35:23 +00:00
|
|
|
void testPointerAxis();
|
2015-02-27 16:36:43 +00:00
|
|
|
void testCursor();
|
2014-09-02 07:34:31 +00:00
|
|
|
void testKeyboard();
|
2014-11-27 12:38:24 +00:00
|
|
|
void testSelection();
|
2016-10-24 09:05:04 +00:00
|
|
|
void testDataDeviceForKeyboardSurface();
|
2015-03-25 12:31:38 +00:00
|
|
|
void testTouch();
|
2020-03-19 13:58:52 +00:00
|
|
|
void testKeymap();
|
2014-09-02 07:34:31 +00:00
|
|
|
|
|
|
|
private:
|
2023-04-21 14:30:58 +00:00
|
|
|
bool sync();
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::Display *m_display;
|
|
|
|
KWin::CompositorInterface *m_compositorInterface;
|
|
|
|
KWin::SeatInterface *m_seatInterface;
|
|
|
|
KWin::SubCompositorInterface *m_subCompositorInterface;
|
|
|
|
KWin::RelativePointerManagerV1Interface *m_relativePointerManagerV1Interface;
|
|
|
|
KWin::PointerGesturesV1Interface *m_pointerGesturesV1Interface;
|
2014-09-17 14:17:26 +00:00
|
|
|
KWayland::Client::ConnectionThread *m_connection;
|
|
|
|
KWayland::Client::Compositor *m_compositor;
|
|
|
|
KWayland::Client::Seat *m_seat;
|
2015-02-27 16:36:43 +00:00
|
|
|
KWayland::Client::ShmPool *m_shm;
|
2021-08-29 05:11:06 +00:00
|
|
|
KWayland::Client::SubCompositor *m_subCompositor;
|
2016-10-07 07:07:34 +00:00
|
|
|
KWayland::Client::RelativePointerManager *m_relativePointerManager;
|
2016-10-26 08:27:14 +00:00
|
|
|
KWayland::Client::PointerGestures *m_pointerGestures;
|
2014-09-23 09:55:07 +00:00
|
|
|
KWayland::Client::EventQueue *m_queue;
|
2014-09-02 07:34:31 +00:00
|
|
|
QThread *m_thread;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("kwin-test-wayland-seat-0");
|
|
|
|
|
|
|
|
TestWaylandSeat::TestWaylandSeat(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_display(nullptr)
|
|
|
|
, m_compositorInterface(nullptr)
|
|
|
|
, m_seatInterface(nullptr)
|
2016-04-06 07:52:13 +00:00
|
|
|
, m_subCompositorInterface(nullptr)
|
2020-11-03 16:24:03 +00:00
|
|
|
, m_relativePointerManagerV1Interface(nullptr)
|
2020-11-03 17:24:57 +00:00
|
|
|
, m_pointerGesturesV1Interface(nullptr)
|
2014-09-02 07:34:31 +00:00
|
|
|
, m_connection(nullptr)
|
|
|
|
, m_compositor(nullptr)
|
|
|
|
, m_seat(nullptr)
|
2015-02-27 16:36:43 +00:00
|
|
|
, m_shm(nullptr)
|
2016-04-06 07:52:13 +00:00
|
|
|
, m_subCompositor(nullptr)
|
2016-10-07 07:07:34 +00:00
|
|
|
, m_relativePointerManager(nullptr)
|
2016-10-26 08:27:14 +00:00
|
|
|
, m_pointerGestures(nullptr)
|
2014-09-23 09:55:07 +00:00
|
|
|
, m_queue(nullptr)
|
2014-09-02 07:34:31 +00:00
|
|
|
, m_thread(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSeat::init()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2014-09-02 07:34:31 +00:00
|
|
|
delete m_display;
|
2023-09-13 17:59:29 +00:00
|
|
|
m_display = new KWin::Display(this);
|
2020-10-19 15:52:56 +00:00
|
|
|
m_display->addSocketName(s_socketName);
|
2014-09-02 07:34:31 +00:00
|
|
|
m_display->start();
|
|
|
|
QVERIFY(m_display->isRunning());
|
2015-02-27 16:36:43 +00:00
|
|
|
m_display->createShm();
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2020-12-09 20:13:19 +00:00
|
|
|
m_compositorInterface = new CompositorInterface(m_display, m_display);
|
|
|
|
m_subCompositorInterface = new SubCompositorInterface(m_display, m_display);
|
2016-04-06 07:52:13 +00:00
|
|
|
QVERIFY(m_subCompositorInterface);
|
|
|
|
|
2020-12-09 20:13:19 +00:00
|
|
|
m_relativePointerManagerV1Interface = new RelativePointerManagerV1Interface(m_display, m_display);
|
|
|
|
m_pointerGesturesV1Interface = new PointerGesturesV1Interface(m_display, m_display);
|
2016-10-26 08:27:14 +00:00
|
|
|
|
2014-09-02 07:34:31 +00:00
|
|
|
// setup connection
|
2014-09-17 14:17:26 +00:00
|
|
|
m_connection = new KWayland::Client::ConnectionThread;
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
|
2014-09-02 07:34:31 +00:00
|
|
|
m_connection->setSocketName(s_socketName);
|
|
|
|
|
|
|
|
m_thread = new QThread(this);
|
|
|
|
m_connection->moveToThread(m_thread);
|
|
|
|
m_thread->start();
|
|
|
|
|
|
|
|
m_connection->initConnection();
|
|
|
|
QVERIFY(connectedSpy.wait());
|
2014-09-23 09:55:07 +00:00
|
|
|
|
|
|
|
m_queue = new KWayland::Client::EventQueue(this);
|
|
|
|
m_queue->setup(m_connection);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2014-09-17 14:17:26 +00:00
|
|
|
KWayland::Client::Registry registry;
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy compositorSpy(®istry, &KWayland::Client::Registry::compositorAnnounced);
|
|
|
|
QSignalSpy seatSpy(®istry, &KWayland::Client::Registry::seatAnnounced);
|
|
|
|
QSignalSpy shmSpy(®istry, &KWayland::Client::Registry::shmAnnounced);
|
2014-09-23 09:55:07 +00:00
|
|
|
registry.setEventQueue(m_queue);
|
2014-09-02 07:34:31 +00:00
|
|
|
registry.create(m_connection->display());
|
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
|
|
|
QVERIFY(compositorSpy.wait());
|
|
|
|
|
2022-07-26 16:46:55 +00:00
|
|
|
m_seatInterface = new SeatInterface(m_display, m_display);
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(m_seatInterface);
|
|
|
|
m_seatInterface->setName(QStringLiteral("seat0"));
|
|
|
|
QVERIFY(seatSpy.wait());
|
|
|
|
|
2014-09-17 14:17:26 +00:00
|
|
|
m_compositor = new KWayland::Client::Compositor(this);
|
2014-09-02 07:34:31 +00:00
|
|
|
m_compositor->setup(registry.bindCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>()));
|
|
|
|
QVERIFY(m_compositor->isValid());
|
|
|
|
|
2014-09-19 08:42:44 +00:00
|
|
|
m_seat = registry.createSeat(seatSpy.first().first().value<quint32>(), seatSpy.first().last().value<quint32>(), this);
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy nameSpy(m_seat, &KWayland::Client::Seat::nameChanged);
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(nameSpy.wait());
|
2015-02-27 16:36:43 +00:00
|
|
|
|
|
|
|
m_shm = new KWayland::Client::ShmPool(this);
|
|
|
|
m_shm->setup(registry.bindShm(shmSpy.first().first().value<quint32>(), shmSpy.first().last().value<quint32>()));
|
|
|
|
QVERIFY(m_shm->isValid());
|
2016-04-06 07:52:13 +00:00
|
|
|
|
|
|
|
m_subCompositor = registry.createSubCompositor(registry.interface(KWayland::Client::Registry::Interface::SubCompositor).name,
|
|
|
|
registry.interface(KWayland::Client::Registry::Interface::SubCompositor).version,
|
|
|
|
this);
|
|
|
|
QVERIFY(m_subCompositor->isValid());
|
2016-10-07 07:07:34 +00:00
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
m_relativePointerManager =
|
|
|
|
registry.createRelativePointerManager(registry.interface(KWayland::Client::Registry::Interface::RelativePointerManagerUnstableV1).name,
|
|
|
|
registry.interface(KWayland::Client::Registry::Interface::RelativePointerManagerUnstableV1).version,
|
|
|
|
this);
|
2016-10-07 07:07:34 +00:00
|
|
|
QVERIFY(m_relativePointerManager->isValid());
|
2016-10-26 08:27:14 +00:00
|
|
|
|
|
|
|
m_pointerGestures = registry.createPointerGestures(registry.interface(KWayland::Client::Registry::Interface::PointerGesturesUnstableV1).name,
|
|
|
|
registry.interface(KWayland::Client::Registry::Interface::PointerGesturesUnstableV1).version,
|
|
|
|
this);
|
|
|
|
QVERIFY(m_pointerGestures->isValid());
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSeat::cleanup()
|
|
|
|
{
|
2016-10-26 08:27:14 +00:00
|
|
|
if (m_pointerGestures) {
|
|
|
|
delete m_pointerGestures;
|
|
|
|
m_pointerGestures = nullptr;
|
|
|
|
}
|
2016-10-07 07:07:34 +00:00
|
|
|
if (m_relativePointerManager) {
|
|
|
|
delete m_relativePointerManager;
|
|
|
|
m_relativePointerManager = nullptr;
|
|
|
|
}
|
2016-04-06 07:52:13 +00:00
|
|
|
if (m_subCompositor) {
|
|
|
|
delete m_subCompositor;
|
|
|
|
m_subCompositor = nullptr;
|
|
|
|
}
|
2015-02-27 16:36:43 +00:00
|
|
|
if (m_shm) {
|
|
|
|
delete m_shm;
|
|
|
|
m_shm = nullptr;
|
|
|
|
}
|
2014-09-02 07:34:31 +00:00
|
|
|
if (m_seat) {
|
|
|
|
delete m_seat;
|
|
|
|
m_seat = nullptr;
|
|
|
|
}
|
|
|
|
if (m_compositor) {
|
|
|
|
delete m_compositor;
|
|
|
|
m_compositor = nullptr;
|
|
|
|
}
|
2014-09-23 09:55:07 +00:00
|
|
|
if (m_queue) {
|
|
|
|
delete m_queue;
|
|
|
|
m_queue = nullptr;
|
|
|
|
}
|
|
|
|
if (m_connection) {
|
|
|
|
m_connection->deleteLater();
|
|
|
|
m_connection = nullptr;
|
|
|
|
}
|
2014-09-02 07:34:31 +00:00
|
|
|
if (m_thread) {
|
|
|
|
m_thread->quit();
|
|
|
|
m_thread->wait();
|
|
|
|
delete m_thread;
|
|
|
|
m_thread = nullptr;
|
|
|
|
}
|
|
|
|
|
2020-10-30 13:36:24 +00:00
|
|
|
delete m_display;
|
|
|
|
m_display = nullptr;
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2020-10-30 13:36:24 +00:00
|
|
|
// these are the children of the display
|
|
|
|
m_compositorInterface = nullptr;
|
2014-09-02 07:34:31 +00:00
|
|
|
m_seatInterface = nullptr;
|
2016-04-06 07:52:13 +00:00
|
|
|
m_subCompositorInterface = nullptr;
|
2020-11-03 16:24:03 +00:00
|
|
|
m_relativePointerManagerV1Interface = nullptr;
|
2020-11-03 17:24:57 +00:00
|
|
|
m_pointerGesturesV1Interface = nullptr;
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
2023-04-21 14:30:58 +00:00
|
|
|
bool TestWaylandSeat::sync()
|
|
|
|
{
|
2023-04-23 20:06:04 +00:00
|
|
|
WaylandSyncPoint syncPoint(m_connection, m_queue);
|
2023-04-21 14:30:58 +00:00
|
|
|
QSignalSpy doneSpy(&syncPoint, &WaylandSyncPoint::done);
|
|
|
|
return doneSpy.wait();
|
|
|
|
}
|
|
|
|
|
2014-09-02 07:34:31 +00:00
|
|
|
void TestWaylandSeat::testName()
|
|
|
|
{
|
|
|
|
// no name set yet
|
|
|
|
QCOMPARE(m_seat->name(), QStringLiteral("seat0"));
|
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy spy(m_seat, &KWayland::Client::Seat::nameChanged);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
|
|
|
const QString name = QStringLiteral("foobar");
|
|
|
|
m_seatInterface->setName(name);
|
|
|
|
QVERIFY(spy.wait());
|
|
|
|
QCOMPARE(m_seat->name(), name);
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
QCOMPARE(spy.first().first().toString(), name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSeat::testCapabilities_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("pointer");
|
|
|
|
QTest::addColumn<bool>("keyboard");
|
|
|
|
QTest::addColumn<bool>("touch");
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
QTest::newRow("none") << false << false << false;
|
|
|
|
QTest::newRow("pointer") << true << false << false;
|
|
|
|
QTest::newRow("keyboard") << false << true << false;
|
|
|
|
QTest::newRow("touch") << false << false << true;
|
|
|
|
QTest::newRow("pointer/keyboard") << true << true << false;
|
|
|
|
QTest::newRow("pointer/touch") << true << false << true;
|
|
|
|
QTest::newRow("keyboard/touch") << false << true << true;
|
|
|
|
QTest::newRow("all") << true << true << true;
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSeat::testCapabilities()
|
|
|
|
{
|
|
|
|
QVERIFY(!m_seat->hasPointer());
|
|
|
|
QVERIFY(!m_seat->hasKeyboard());
|
|
|
|
QVERIFY(!m_seat->hasTouch());
|
|
|
|
|
|
|
|
QFETCH(bool, pointer);
|
|
|
|
QFETCH(bool, keyboard);
|
|
|
|
QFETCH(bool, touch);
|
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy pointerSpy(m_seat, &KWayland::Client::Seat::hasPointerChanged);
|
|
|
|
QSignalSpy keyboardSpy(m_seat, &KWayland::Client::Seat::hasKeyboardChanged);
|
|
|
|
QSignalSpy touchSpy(m_seat, &KWayland::Client::Seat::hasTouchChanged);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
|
|
|
m_seatInterface->setHasPointer(pointer);
|
|
|
|
m_seatInterface->setHasKeyboard(keyboard);
|
|
|
|
m_seatInterface->setHasTouch(touch);
|
|
|
|
|
2023-04-21 14:30:58 +00:00
|
|
|
QVERIFY(sync());
|
|
|
|
|
2014-09-02 07:34:31 +00:00
|
|
|
// do processing
|
|
|
|
QCOMPARE(pointerSpy.isEmpty(), !pointer);
|
|
|
|
if (!pointerSpy.isEmpty()) {
|
|
|
|
QCOMPARE(pointerSpy.first().first().toBool(), pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
QCOMPARE(keyboardSpy.isEmpty(), !keyboard);
|
|
|
|
if (!keyboardSpy.isEmpty()) {
|
|
|
|
QCOMPARE(keyboardSpy.first().first().toBool(), keyboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
QCOMPARE(touchSpy.isEmpty(), !touch);
|
|
|
|
if (!touchSpy.isEmpty()) {
|
|
|
|
QCOMPARE(touchSpy.first().first().toBool(), touch);
|
|
|
|
}
|
|
|
|
|
|
|
|
QCOMPARE(m_seat->hasPointer(), pointer);
|
|
|
|
QCOMPARE(m_seat->hasKeyboard(), keyboard);
|
|
|
|
QCOMPARE(m_seat->hasTouch(), touch);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSeat::testPointer()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy pointerSpy(m_seat, &KWayland::Client::Seat::hasPointerChanged);
|
2014-09-02 07:34:31 +00:00
|
|
|
m_seatInterface->setHasPointer(true);
|
|
|
|
QVERIFY(pointerSpy.wait());
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &KWin::CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Surface *s = m_compositor->createSurface(m_compositor);
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value<KWin::SurfaceInterface *>();
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
QImage image(QSize(100, 100), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
image.fill(Qt::black);
|
|
|
|
s->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
s->damage(image.rect());
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy committedSpy(serverSurface, &KWin::SurfaceInterface::committed);
|
2021-02-12 22:29:45 +00:00
|
|
|
QVERIFY(committedSpy.wait());
|
2016-02-22 13:55:19 +00:00
|
|
|
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerEnter(serverSurface, QPointF(20, 18), QPointF(10, 15));
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Pointer *p = m_seat->createPointer(m_seat);
|
|
|
|
QSignalSpy frameSpy(p, &KWayland::Client::Pointer::frame);
|
|
|
|
const KWayland::Client::Pointer &cp = *p;
|
2014-09-22 09:02:16 +00:00
|
|
|
QVERIFY(p->isValid());
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::RelativePointer> relativePointer(m_relativePointerManager->createRelativePointer(p));
|
2016-10-07 07:07:34 +00:00
|
|
|
QVERIFY(relativePointer->isValid());
|
2018-02-01 16:46:53 +00:00
|
|
|
QVERIFY(frameSpy.wait());
|
|
|
|
QCOMPARE(frameSpy.count(), 1);
|
2014-11-26 09:34:23 +00:00
|
|
|
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerLeave();
|
2014-11-26 09:34:23 +00:00
|
|
|
serverSurface->client()->flush();
|
2018-02-01 16:46:53 +00:00
|
|
|
QVERIFY(frameSpy.wait());
|
|
|
|
QCOMPARE(frameSpy.count(), 2);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy enteredSpy(p, &KWayland::Client::Pointer::entered);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy leftSpy(p, &KWayland::Client::Pointer::left);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy motionSpy(p, &KWayland::Client::Pointer::motion);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy axisSpy(p, &KWayland::Client::Pointer::axisChanged);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy buttonSpy(p, &KWayland::Client::Pointer::buttonStateChanged);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy relativeMotionSpy(relativePointer.get(), &KWayland::Client::RelativePointer::relativeMotion);
|
2016-10-07 07:07:34 +00:00
|
|
|
|
2014-12-03 07:41:00 +00:00
|
|
|
QVERIFY(!p->enteredSurface());
|
|
|
|
QVERIFY(!cp.enteredSurface());
|
2023-04-19 12:16:23 +00:00
|
|
|
uint32_t serial = m_display->serial();
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerEnter(serverSurface, QPointF(20, 18), QPointF(10, 15));
|
2014-11-25 14:54:28 +00:00
|
|
|
QCOMPARE(m_seatInterface->focusedPointerSurface(), serverSurface);
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(enteredSpy.wait());
|
2023-04-19 12:16:23 +00:00
|
|
|
QCOMPARE_GT(enteredSpy.first().first().value<quint32>(), serial);
|
2014-09-02 07:34:31 +00:00
|
|
|
QCOMPARE(enteredSpy.first().last().toPoint(), QPoint(10, 3));
|
2018-02-01 16:46:53 +00:00
|
|
|
QCOMPARE(frameSpy.count(), 3);
|
2014-12-03 07:41:00 +00:00
|
|
|
QCOMPARE(p->enteredSurface(), s);
|
|
|
|
QCOMPARE(cp.enteredSurface(), s);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2022-12-21 00:55:20 +00:00
|
|
|
auto timestamp = 1ms;
|
2014-09-02 07:34:31 +00:00
|
|
|
// test motion
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerMotion(QPoint(10, 16));
|
|
|
|
m_seatInterface->notifyPointerFrame();
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(motionSpy.wait());
|
2018-02-01 16:46:53 +00:00
|
|
|
QCOMPARE(frameSpy.count(), 4);
|
2014-09-02 07:34:31 +00:00
|
|
|
QCOMPARE(motionSpy.first().first().toPoint(), QPoint(0, 1));
|
|
|
|
QCOMPARE(motionSpy.first().last().value<quint32>(), quint32(1));
|
|
|
|
|
2016-10-07 07:07:34 +00:00
|
|
|
// test relative motion
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->relativePointerMotion(QPointF(1, 2), QPointF(3, 4), 1234us);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerFrame();
|
2016-10-07 07:07:34 +00:00
|
|
|
QVERIFY(relativeMotionSpy.wait());
|
|
|
|
QCOMPARE(relativeMotionSpy.count(), 1);
|
2018-07-17 10:38:57 +00:00
|
|
|
QCOMPARE(frameSpy.count(), 5);
|
2016-10-07 07:07:34 +00:00
|
|
|
QCOMPARE(relativeMotionSpy.first().at(0).toSizeF(), QSizeF(1, 2));
|
|
|
|
QCOMPARE(relativeMotionSpy.first().at(1).toSizeF(), QSizeF(3, 4));
|
2022-12-21 00:55:20 +00:00
|
|
|
QCOMPARE(relativeMotionSpy.first().at(2).value<quint64>(), 1234);
|
2016-10-07 07:07:34 +00:00
|
|
|
|
2014-09-02 07:34:31 +00:00
|
|
|
// test axis
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2022-10-11 10:33:04 +00:00
|
|
|
m_seatInterface->notifyPointerAxis(Qt::Horizontal, 10, 120, PointerAxisSource::Wheel);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerFrame();
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(axisSpy.wait());
|
2018-07-17 10:38:57 +00:00
|
|
|
QCOMPARE(frameSpy.count(), 6);
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2022-10-11 10:33:04 +00:00
|
|
|
m_seatInterface->notifyPointerAxis(Qt::Vertical, 20, 240, PointerAxisSource::Wheel);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerFrame();
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(axisSpy.wait());
|
2018-07-17 10:38:57 +00:00
|
|
|
QCOMPARE(frameSpy.count(), 7);
|
2014-09-02 07:34:31 +00:00
|
|
|
QCOMPARE(axisSpy.first().at(0).value<quint32>(), quint32(2));
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(axisSpy.first().at(1).value<KWayland::Client::Pointer::Axis>(), KWayland::Client::Pointer::Axis::Horizontal);
|
2014-09-02 07:34:31 +00:00
|
|
|
QCOMPARE(axisSpy.first().at(2).value<qreal>(), qreal(10));
|
|
|
|
|
|
|
|
QCOMPARE(axisSpy.last().at(0).value<quint32>(), quint32(3));
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(axisSpy.last().at(1).value<KWayland::Client::Pointer::Axis>(), KWayland::Client::Pointer::Axis::Vertical);
|
2014-09-02 07:34:31 +00:00
|
|
|
QCOMPARE(axisSpy.last().at(2).value<qreal>(), qreal(20));
|
|
|
|
|
|
|
|
// test button
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2021-03-15 17:58:39 +00:00
|
|
|
m_seatInterface->notifyPointerButton(1, PointerButtonState::Pressed);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerFrame();
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(buttonSpy.wait());
|
2018-07-17 10:38:57 +00:00
|
|
|
QCOMPARE(frameSpy.count(), 8);
|
2014-09-02 07:34:31 +00:00
|
|
|
QCOMPARE(buttonSpy.at(0).at(0).value<quint32>(), m_display->serial());
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2021-03-15 17:58:39 +00:00
|
|
|
m_seatInterface->notifyPointerButton(2, PointerButtonState::Pressed);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerFrame();
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(buttonSpy.wait());
|
2018-07-17 10:38:57 +00:00
|
|
|
QCOMPARE(frameSpy.count(), 9);
|
2014-09-02 07:34:31 +00:00
|
|
|
QCOMPARE(buttonSpy.at(1).at(0).value<quint32>(), m_display->serial());
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2021-03-15 17:58:39 +00:00
|
|
|
m_seatInterface->notifyPointerButton(2, PointerButtonState::Released);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerFrame();
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(buttonSpy.wait());
|
2018-07-17 10:38:57 +00:00
|
|
|
QCOMPARE(frameSpy.count(), 10);
|
2014-09-02 07:34:31 +00:00
|
|
|
QCOMPARE(buttonSpy.at(2).at(0).value<quint32>(), m_display->serial());
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2021-03-15 17:58:39 +00:00
|
|
|
m_seatInterface->notifyPointerButton(1, PointerButtonState::Released);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerFrame();
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(buttonSpy.wait());
|
2018-07-17 10:38:57 +00:00
|
|
|
QCOMPARE(frameSpy.count(), 11);
|
2014-09-02 07:34:31 +00:00
|
|
|
QCOMPARE(buttonSpy.count(), 4);
|
|
|
|
|
|
|
|
// timestamp
|
|
|
|
QCOMPARE(buttonSpy.at(0).at(1).value<quint32>(), quint32(4));
|
|
|
|
// button
|
|
|
|
QCOMPARE(buttonSpy.at(0).at(2).value<quint32>(), quint32(1));
|
2014-09-17 14:17:26 +00:00
|
|
|
QCOMPARE(buttonSpy.at(0).at(3).value<KWayland::Client::Pointer::ButtonState>(), KWayland::Client::Pointer::ButtonState::Pressed);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
|
|
|
// timestamp
|
|
|
|
QCOMPARE(buttonSpy.at(1).at(1).value<quint32>(), quint32(5));
|
|
|
|
// button
|
|
|
|
QCOMPARE(buttonSpy.at(1).at(2).value<quint32>(), quint32(2));
|
2014-09-17 14:17:26 +00:00
|
|
|
QCOMPARE(buttonSpy.at(1).at(3).value<KWayland::Client::Pointer::ButtonState>(), KWayland::Client::Pointer::ButtonState::Pressed);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2014-11-26 10:50:52 +00:00
|
|
|
QCOMPARE(buttonSpy.at(2).at(0).value<quint32>(), m_seatInterface->pointerButtonSerial(2));
|
2014-09-02 07:34:31 +00:00
|
|
|
// timestamp
|
|
|
|
QCOMPARE(buttonSpy.at(2).at(1).value<quint32>(), quint32(6));
|
|
|
|
// button
|
|
|
|
QCOMPARE(buttonSpy.at(2).at(2).value<quint32>(), quint32(2));
|
2014-09-17 14:17:26 +00:00
|
|
|
QCOMPARE(buttonSpy.at(2).at(3).value<KWayland::Client::Pointer::ButtonState>(), KWayland::Client::Pointer::ButtonState::Released);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2014-11-26 10:50:52 +00:00
|
|
|
QCOMPARE(buttonSpy.at(3).at(0).value<quint32>(), m_seatInterface->pointerButtonSerial(1));
|
2014-09-02 07:34:31 +00:00
|
|
|
// timestamp
|
|
|
|
QCOMPARE(buttonSpy.at(3).at(1).value<quint32>(), quint32(7));
|
|
|
|
// button
|
|
|
|
QCOMPARE(buttonSpy.at(3).at(2).value<quint32>(), quint32(1));
|
2014-09-17 14:17:26 +00:00
|
|
|
QCOMPARE(buttonSpy.at(3).at(3).value<KWayland::Client::Pointer::ButtonState>(), KWayland::Client::Pointer::ButtonState::Released);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
|
|
|
// leave the surface
|
2023-04-19 12:16:23 +00:00
|
|
|
serial = m_display->serial();
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerLeave();
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(leftSpy.wait());
|
2018-07-17 10:38:57 +00:00
|
|
|
QCOMPARE(frameSpy.count(), 12);
|
2023-04-19 12:16:23 +00:00
|
|
|
QCOMPARE_GT(leftSpy.first().first().value<quint32>(), serial);
|
2014-12-03 07:41:00 +00:00
|
|
|
QVERIFY(!p->enteredSurface());
|
|
|
|
QVERIFY(!cp.enteredSurface());
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2016-10-07 07:07:34 +00:00
|
|
|
// now a relative motion should not be sent to the relative pointer
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->relativePointerMotion(QPointF(1, 2), QPointF(3, 4), std::chrono::milliseconds::zero());
|
2023-04-21 14:30:58 +00:00
|
|
|
QVERIFY(sync());
|
|
|
|
QCOMPARE(relativeMotionSpy.count(), 1);
|
2016-10-07 07:07:34 +00:00
|
|
|
|
2014-09-02 07:34:31 +00:00
|
|
|
// enter it again
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerEnter(serverSurface, QPointF(10, 16), QPointF(0, 0));
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(enteredSpy.wait());
|
2018-07-17 10:38:57 +00:00
|
|
|
QCOMPARE(frameSpy.count(), 13);
|
2014-12-03 07:41:00 +00:00
|
|
|
QCOMPARE(p->enteredSurface(), s);
|
|
|
|
QCOMPARE(cp.enteredSurface(), s);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2016-10-07 07:07:34 +00:00
|
|
|
// send another relative motion event
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->relativePointerMotion(QPointF(4, 5), QPointF(6, 7), 1234us);
|
2016-10-07 07:07:34 +00:00
|
|
|
QVERIFY(relativeMotionSpy.wait());
|
|
|
|
QCOMPARE(relativeMotionSpy.count(), 2);
|
|
|
|
QCOMPARE(relativeMotionSpy.last().at(0).toSizeF(), QSizeF(4, 5));
|
|
|
|
QCOMPARE(relativeMotionSpy.last().at(1).toSizeF(), QSizeF(6, 7));
|
2022-12-21 00:55:20 +00:00
|
|
|
QCOMPARE(relativeMotionSpy.last().at(2).value<quint64>(), 1234);
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
2015-12-07 10:45:34 +00:00
|
|
|
void TestWaylandSeat::testPointerTransformation_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QMatrix4x4>("enterTransformation");
|
|
|
|
// global position at 20/18
|
|
|
|
QTest::addColumn<QPointF>("expectedEnterPoint");
|
|
|
|
// global position at 10/16
|
|
|
|
QTest::addColumn<QPointF>("expectedMovePoint");
|
|
|
|
|
|
|
|
QMatrix4x4 tm;
|
|
|
|
tm.translate(-10, -15);
|
|
|
|
QTest::newRow("translation") << tm << QPointF(10, 3) << QPointF(0, 1);
|
|
|
|
QMatrix4x4 sm;
|
|
|
|
sm.scale(2, 2);
|
|
|
|
QTest::newRow("scale") << sm << QPointF(40, 36) << QPointF(20, 32);
|
|
|
|
QMatrix4x4 rotate;
|
|
|
|
rotate.rotate(90, 0, 0, 1);
|
|
|
|
QTest::newRow("rotate") << rotate << QPointF(-18, 20) << QPointF(-16, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSeat::testPointerTransformation()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2015-12-07 10:45:34 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy pointerSpy(m_seat, &KWayland::Client::Seat::hasPointerChanged);
|
2015-12-07 10:45:34 +00:00
|
|
|
m_seatInterface->setHasPointer(true);
|
|
|
|
QVERIFY(pointerSpy.wait());
|
|
|
|
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Surface *s = m_compositor->createSurface(m_compositor);
|
2015-12-07 10:45:34 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value<KWin::SurfaceInterface *>();
|
2015-12-07 10:45:34 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
QImage image(QSize(100, 100), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
image.fill(Qt::black);
|
|
|
|
s->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
s->damage(image.rect());
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy committedSpy(serverSurface, &KWin::SurfaceInterface::committed);
|
2021-02-12 22:29:45 +00:00
|
|
|
QVERIFY(committedSpy.wait());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Pointer *p = m_seat->createPointer(m_seat);
|
2015-12-07 10:45:34 +00:00
|
|
|
QVERIFY(p->isValid());
|
2022-11-08 21:15:17 +00:00
|
|
|
const KWayland::Client::Pointer &cp = *p;
|
2015-12-07 10:45:34 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy enteredSpy(p, &KWayland::Client::Pointer::entered);
|
|
|
|
QSignalSpy leftSpy(p, &KWayland::Client::Pointer::left);
|
|
|
|
QSignalSpy motionSpy(p, &KWayland::Client::Pointer::motion);
|
2015-12-07 10:45:34 +00:00
|
|
|
|
|
|
|
QVERIFY(!p->enteredSurface());
|
|
|
|
QVERIFY(!cp.enteredSurface());
|
2023-04-19 12:16:23 +00:00
|
|
|
uint32_t serial = m_display->serial();
|
2023-04-21 14:30:58 +00:00
|
|
|
QFETCH(QMatrix4x4, enterTransformation);
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerEnter(serverSurface, QPointF(20, 18), enterTransformation);
|
2015-12-07 10:45:34 +00:00
|
|
|
QCOMPARE(m_seatInterface->focusedPointerSurface(), serverSurface);
|
|
|
|
QVERIFY(enteredSpy.wait());
|
2023-04-19 12:16:23 +00:00
|
|
|
QCOMPARE_GT(enteredSpy.first().first().value<quint32>(), serial);
|
2015-12-07 10:45:34 +00:00
|
|
|
QTEST(enteredSpy.first().last().toPointF(), "expectedEnterPoint");
|
|
|
|
QCOMPARE(p->enteredSurface(), s);
|
|
|
|
QCOMPARE(cp.enteredSurface(), s);
|
|
|
|
|
|
|
|
// test motion
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(std::chrono::milliseconds(1));
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerMotion(QPoint(10, 16));
|
|
|
|
m_seatInterface->notifyPointerFrame();
|
2015-12-07 10:45:34 +00:00
|
|
|
QVERIFY(motionSpy.wait());
|
|
|
|
QTEST(motionSpy.first().first().toPointF(), "expectedMovePoint");
|
|
|
|
QCOMPARE(motionSpy.first().last().value<quint32>(), quint32(1));
|
|
|
|
|
|
|
|
// leave the surface
|
2023-04-19 12:16:23 +00:00
|
|
|
serial = m_display->serial();
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerLeave();
|
2015-12-07 10:45:34 +00:00
|
|
|
QVERIFY(leftSpy.wait());
|
2023-04-19 12:16:23 +00:00
|
|
|
QCOMPARE_GT(leftSpy.first().first().value<quint32>(), serial);
|
2015-12-07 10:45:34 +00:00
|
|
|
QVERIFY(!p->enteredSurface());
|
|
|
|
QVERIFY(!cp.enteredSurface());
|
|
|
|
|
|
|
|
// enter it again
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerEnter(serverSurface, QPointF(10, 16));
|
2015-12-07 10:45:34 +00:00
|
|
|
QVERIFY(enteredSpy.wait());
|
|
|
|
QCOMPARE(p->enteredSurface(), s);
|
|
|
|
QCOMPARE(cp.enteredSurface(), s);
|
|
|
|
|
2023-04-21 14:30:58 +00:00
|
|
|
QSignalSpy serverSurfaceDestroyedSpy(serverSurface, &QObject::destroyed);
|
2015-12-07 10:45:34 +00:00
|
|
|
delete s;
|
2023-04-21 14:30:58 +00:00
|
|
|
QVERIFY(serverSurfaceDestroyedSpy.wait());
|
2015-12-07 10:45:34 +00:00
|
|
|
QVERIFY(!m_seatInterface->focusedPointerSurface());
|
|
|
|
}
|
|
|
|
|
2014-11-10 13:51:09 +00:00
|
|
|
Q_DECLARE_METATYPE(Qt::MouseButton)
|
|
|
|
|
|
|
|
void TestWaylandSeat::testPointerButton_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<Qt::MouseButton>("qtButton");
|
|
|
|
QTest::addColumn<quint32>("waylandButton");
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
QTest::newRow("left") << Qt::LeftButton << quint32(BTN_LEFT);
|
|
|
|
QTest::newRow("right") << Qt::RightButton << quint32(BTN_RIGHT);
|
|
|
|
QTest::newRow("middle") << Qt::MiddleButton << quint32(BTN_MIDDLE);
|
|
|
|
QTest::newRow("back") << Qt::BackButton << quint32(BTN_BACK);
|
|
|
|
QTest::newRow("x1") << Qt::XButton1 << quint32(BTN_BACK);
|
|
|
|
QTest::newRow("extra1") << Qt::ExtraButton1 << quint32(BTN_BACK);
|
2014-11-10 13:51:09 +00:00
|
|
|
QTest::newRow("forward") << Qt::ForwardButton << quint32(BTN_FORWARD);
|
2021-08-29 05:11:06 +00:00
|
|
|
QTest::newRow("x2") << Qt::XButton2 << quint32(BTN_FORWARD);
|
|
|
|
QTest::newRow("extra2") << Qt::ExtraButton2 << quint32(BTN_FORWARD);
|
|
|
|
QTest::newRow("task") << Qt::TaskButton << quint32(BTN_TASK);
|
|
|
|
QTest::newRow("extra3") << Qt::ExtraButton3 << quint32(BTN_TASK);
|
|
|
|
QTest::newRow("extra4") << Qt::ExtraButton4 << quint32(BTN_EXTRA);
|
|
|
|
QTest::newRow("extra5") << Qt::ExtraButton5 << quint32(BTN_SIDE);
|
|
|
|
QTest::newRow("extra6") << Qt::ExtraButton6 << quint32(0x118);
|
|
|
|
QTest::newRow("extra7") << Qt::ExtraButton7 << quint32(0x119);
|
|
|
|
QTest::newRow("extra8") << Qt::ExtraButton8 << quint32(0x11a);
|
|
|
|
QTest::newRow("extra9") << Qt::ExtraButton9 << quint32(0x11b);
|
2014-11-10 13:51:09 +00:00
|
|
|
QTest::newRow("extra10") << Qt::ExtraButton10 << quint32(0x11c);
|
|
|
|
QTest::newRow("extra11") << Qt::ExtraButton11 << quint32(0x11d);
|
|
|
|
QTest::newRow("extra12") << Qt::ExtraButton12 << quint32(0x11e);
|
|
|
|
QTest::newRow("extra13") << Qt::ExtraButton13 << quint32(0x11f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSeat::testPointerButton()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2014-11-10 13:51:09 +00:00
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy pointerSpy(m_seat, &KWayland::Client::Seat::hasPointerChanged);
|
2014-11-10 13:51:09 +00:00
|
|
|
m_seatInterface->setHasPointer(true);
|
|
|
|
QVERIFY(pointerSpy.wait());
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &KWin::CompositorInterface::surfaceCreated);
|
2021-02-12 22:29:45 +00:00
|
|
|
KWayland::Client::Surface *s = m_compositor->createSurface(m_compositor);
|
2014-11-10 13:51:09 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value<KWin::SurfaceInterface *>();
|
2014-11-10 13:51:09 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
QImage image(QSize(100, 100), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
image.fill(Qt::black);
|
|
|
|
s->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
s->damage(image.rect());
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy committedSpy(serverSurface, &KWin::SurfaceInterface::committed);
|
2021-02-12 22:29:45 +00:00
|
|
|
QVERIFY(committedSpy.wait());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Pointer> p(m_seat->createPointer());
|
2014-11-10 13:51:09 +00:00
|
|
|
QVERIFY(p->isValid());
|
2022-08-01 21:29:02 +00:00
|
|
|
QSignalSpy buttonChangedSpy(p.get(), &KWayland::Client::Pointer::buttonStateChanged);
|
2014-11-10 13:51:09 +00:00
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerEnter(serverSurface, QPointF(20, 18), QPointF(10, 15));
|
2014-11-25 14:54:28 +00:00
|
|
|
QVERIFY(m_seatInterface->focusedPointerSurface());
|
2014-11-26 09:34:23 +00:00
|
|
|
|
|
|
|
QCoreApplication::processEvents();
|
2014-11-10 13:51:09 +00:00
|
|
|
|
|
|
|
QFETCH(Qt::MouseButton, qtButton);
|
|
|
|
QFETCH(quint32, waylandButton);
|
2022-12-21 00:55:20 +00:00
|
|
|
std::chrono::milliseconds timestamp(1);
|
2014-11-26 10:50:52 +00:00
|
|
|
QCOMPARE(m_seatInterface->isPointerButtonPressed(waylandButton), false);
|
|
|
|
QCOMPARE(m_seatInterface->isPointerButtonPressed(qtButton), false);
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp);
|
2021-03-15 17:58:39 +00:00
|
|
|
m_seatInterface->notifyPointerButton(qtButton, PointerButtonState::Pressed);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerFrame();
|
2014-11-26 10:50:52 +00:00
|
|
|
QCOMPARE(m_seatInterface->isPointerButtonPressed(waylandButton), true);
|
|
|
|
QCOMPARE(m_seatInterface->isPointerButtonPressed(qtButton), true);
|
2014-11-10 13:51:09 +00:00
|
|
|
QVERIFY(buttonChangedSpy.wait());
|
|
|
|
QCOMPARE(buttonChangedSpy.count(), 1);
|
2014-11-26 10:50:52 +00:00
|
|
|
QCOMPARE(buttonChangedSpy.last().at(0).value<quint32>(), m_seatInterface->pointerButtonSerial(waylandButton));
|
|
|
|
QCOMPARE(buttonChangedSpy.last().at(0).value<quint32>(), m_seatInterface->pointerButtonSerial(qtButton));
|
2022-12-21 00:55:20 +00:00
|
|
|
QCOMPARE(buttonChangedSpy.last().at(1).value<quint32>(), timestamp.count());
|
2014-11-10 13:51:09 +00:00
|
|
|
QCOMPARE(buttonChangedSpy.last().at(2).value<quint32>(), waylandButton);
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(buttonChangedSpy.last().at(3).value<KWayland::Client::Pointer::ButtonState>(), KWayland::Client::Pointer::ButtonState::Pressed);
|
2022-12-21 00:55:20 +00:00
|
|
|
timestamp++;
|
|
|
|
m_seatInterface->setTimestamp(timestamp);
|
2021-03-15 17:58:39 +00:00
|
|
|
m_seatInterface->notifyPointerButton(qtButton, PointerButtonState::Released);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerFrame();
|
2014-11-26 10:50:52 +00:00
|
|
|
QCOMPARE(m_seatInterface->isPointerButtonPressed(waylandButton), false);
|
|
|
|
QCOMPARE(m_seatInterface->isPointerButtonPressed(qtButton), false);
|
2014-11-10 13:51:09 +00:00
|
|
|
QVERIFY(buttonChangedSpy.wait());
|
|
|
|
QCOMPARE(buttonChangedSpy.count(), 2);
|
2014-11-26 10:50:52 +00:00
|
|
|
QCOMPARE(buttonChangedSpy.last().at(0).value<quint32>(), m_seatInterface->pointerButtonSerial(waylandButton));
|
|
|
|
QCOMPARE(buttonChangedSpy.last().at(0).value<quint32>(), m_seatInterface->pointerButtonSerial(qtButton));
|
2022-12-21 00:55:20 +00:00
|
|
|
QCOMPARE(buttonChangedSpy.last().at(1).value<quint32>(), timestamp.count());
|
2014-11-10 13:51:09 +00:00
|
|
|
QCOMPARE(buttonChangedSpy.last().at(2).value<quint32>(), waylandButton);
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(buttonChangedSpy.last().at(3).value<KWayland::Client::Pointer::ButtonState>(), KWayland::Client::Pointer::ButtonState::Released);
|
2014-11-10 13:51:09 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 07:52:13 +00:00
|
|
|
void TestWaylandSeat::testPointerSubSurfaceTree()
|
|
|
|
{
|
|
|
|
// this test verifies that pointer motion on a surface with sub-surfaces sends motion enter/leave to the sub-surface
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2016-04-06 07:52:13 +00:00
|
|
|
|
|
|
|
// first create the pointer
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy hasPointerChangedSpy(m_seat, &KWayland::Client::Seat::hasPointerChanged);
|
2016-04-06 07:52:13 +00:00
|
|
|
m_seatInterface->setHasPointer(true);
|
|
|
|
QVERIFY(hasPointerChangedSpy.wait());
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Pointer> pointer(m_seat->createPointer());
|
2016-04-06 07:52:13 +00:00
|
|
|
|
|
|
|
// create a sub surface tree
|
|
|
|
// parent surface (100, 100) with one sub surface taking the half of it's size (50, 100)
|
|
|
|
// which has two further children (50, 50) which are overlapping
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> parentSurface(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> childSurface(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> grandChild1Surface(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> grandChild2Surface(m_compositor->createSurface());
|
|
|
|
std::unique_ptr<KWayland::Client::SubSurface> childSubSurface(m_subCompositor->createSubSurface(childSurface.get(), parentSurface.get()));
|
|
|
|
std::unique_ptr<KWayland::Client::SubSurface> grandChild1SubSurface(m_subCompositor->createSubSurface(grandChild1Surface.get(), childSurface.get()));
|
|
|
|
std::unique_ptr<KWayland::Client::SubSurface> grandChild2SubSurface(m_subCompositor->createSubSurface(grandChild2Surface.get(), childSurface.get()));
|
2016-04-06 07:52:13 +00:00
|
|
|
grandChild2SubSurface->setPosition(QPoint(0, 25));
|
|
|
|
|
|
|
|
// let's map the surfaces
|
2022-11-08 21:15:17 +00:00
|
|
|
auto render = [this](KWayland::Client::Surface *s, const QSize &size) {
|
2017-08-30 08:57:41 +00:00
|
|
|
QImage image(size, QImage::Format_ARGB32_Premultiplied);
|
2016-04-06 07:52:13 +00:00
|
|
|
image.fill(Qt::black);
|
|
|
|
s->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
s->damage(QRect(QPoint(0, 0), size));
|
2022-11-08 21:15:17 +00:00
|
|
|
s->commit(KWayland::Client::Surface::CommitFlag::None);
|
2016-04-06 07:52:13 +00:00
|
|
|
};
|
2022-08-01 21:29:02 +00:00
|
|
|
render(grandChild2Surface.get(), QSize(50, 50));
|
|
|
|
render(grandChild1Surface.get(), QSize(50, 50));
|
|
|
|
render(childSurface.get(), QSize(50, 100));
|
|
|
|
render(parentSurface.get(), QSize(100, 100));
|
2016-04-06 07:52:13 +00:00
|
|
|
|
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto serverSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface *>();
|
2016-04-06 07:52:13 +00:00
|
|
|
QVERIFY(serverSurface->isMapped());
|
|
|
|
|
|
|
|
// send in pointer events
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy enteredSpy(pointer.get(), &KWayland::Client::Pointer::entered);
|
|
|
|
QSignalSpy leftSpy(pointer.get(), &KWayland::Client::Pointer::left);
|
|
|
|
QSignalSpy motionSpy(pointer.get(), &KWayland::Client::Pointer::motion);
|
2016-04-06 07:52:13 +00:00
|
|
|
// first to the grandChild2 in the overlapped area
|
2022-12-21 00:55:20 +00:00
|
|
|
std::chrono::milliseconds timestamp(1);
|
2016-04-06 07:52:13 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerEnter(serverSurface, QPointF(25, 50));
|
2016-04-06 07:52:13 +00:00
|
|
|
QVERIFY(enteredSpy.wait());
|
|
|
|
QCOMPARE(enteredSpy.count(), 1);
|
|
|
|
QCOMPARE(leftSpy.count(), 0);
|
|
|
|
QCOMPARE(motionSpy.count(), 0);
|
|
|
|
QCOMPARE(enteredSpy.last().last().toPointF(), QPointF(25, 25));
|
2022-08-01 21:29:02 +00:00
|
|
|
QCOMPARE(pointer->enteredSurface(), grandChild2Surface.get());
|
2016-04-06 07:52:13 +00:00
|
|
|
// a motion on grandchild2
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerMotion(QPointF(25, 60));
|
|
|
|
m_seatInterface->notifyPointerFrame();
|
2016-04-06 07:52:13 +00:00
|
|
|
QVERIFY(motionSpy.wait());
|
|
|
|
QCOMPARE(enteredSpy.count(), 1);
|
|
|
|
QCOMPARE(leftSpy.count(), 0);
|
|
|
|
QCOMPARE(motionSpy.count(), 1);
|
|
|
|
QCOMPARE(motionSpy.last().first().toPointF(), QPointF(25, 35));
|
|
|
|
// motion which changes to childSurface
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerMotion(QPointF(25, 80));
|
|
|
|
m_seatInterface->notifyPointerFrame();
|
2016-04-06 07:52:13 +00:00
|
|
|
QVERIFY(enteredSpy.wait());
|
|
|
|
QCOMPARE(enteredSpy.count(), 2);
|
|
|
|
QCOMPARE(leftSpy.count(), 1);
|
2021-02-12 22:29:45 +00:00
|
|
|
QCOMPARE(motionSpy.count(), 2);
|
2016-04-06 07:52:13 +00:00
|
|
|
QCOMPARE(enteredSpy.last().last().toPointF(), QPointF(25, 80));
|
2022-08-01 21:29:02 +00:00
|
|
|
QCOMPARE(pointer->enteredSurface(), childSurface.get());
|
2016-04-06 07:52:13 +00:00
|
|
|
// a leave for the whole surface
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerLeave();
|
2016-04-06 07:52:13 +00:00
|
|
|
QVERIFY(leftSpy.wait());
|
|
|
|
QCOMPARE(enteredSpy.count(), 2);
|
|
|
|
QCOMPARE(leftSpy.count(), 2);
|
2021-02-12 22:29:45 +00:00
|
|
|
QCOMPARE(motionSpy.count(), 2);
|
2016-04-06 07:52:13 +00:00
|
|
|
// a new enter on the main surface
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerEnter(serverSurface, QPointF(75, 50));
|
2016-04-06 07:52:13 +00:00
|
|
|
QVERIFY(enteredSpy.wait());
|
|
|
|
QCOMPARE(enteredSpy.count(), 3);
|
|
|
|
QCOMPARE(leftSpy.count(), 2);
|
2021-02-12 22:29:45 +00:00
|
|
|
QCOMPARE(motionSpy.count(), 2);
|
2016-04-06 07:52:13 +00:00
|
|
|
QCOMPARE(enteredSpy.last().last().toPointF(), QPointF(75, 50));
|
2022-08-01 21:29:02 +00:00
|
|
|
QCOMPARE(pointer->enteredSurface(), parentSurface.get());
|
2016-04-06 07:52:13 +00:00
|
|
|
}
|
|
|
|
|
2016-10-26 08:27:14 +00:00
|
|
|
void TestWaylandSeat::testPointerSwipeGesture_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("cancel");
|
|
|
|
QTest::addColumn<int>("expectedEndCount");
|
|
|
|
QTest::addColumn<int>("expectedCancelCount");
|
|
|
|
|
|
|
|
QTest::newRow("end") << false << 1 << 0;
|
|
|
|
QTest::newRow("cancel") << true << 0 << 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSeat::testPointerSwipeGesture()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2016-10-26 08:27:14 +00:00
|
|
|
|
|
|
|
// first create the pointer and pointer swipe gesture
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy hasPointerChangedSpy(m_seat, &KWayland::Client::Seat::hasPointerChanged);
|
2016-10-26 08:27:14 +00:00
|
|
|
m_seatInterface->setHasPointer(true);
|
|
|
|
QVERIFY(hasPointerChangedSpy.wait());
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Pointer> pointer(m_seat->createPointer());
|
|
|
|
std::unique_ptr<KWayland::Client::PointerSwipeGesture> gesture(m_pointerGestures->createSwipeGesture(pointer.get()));
|
2016-10-26 08:27:14 +00:00
|
|
|
QVERIFY(gesture);
|
|
|
|
QVERIFY(gesture->isValid());
|
|
|
|
QVERIFY(gesture->surface().isNull());
|
|
|
|
QCOMPARE(gesture->fingerCount(), 0u);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy startSpy(gesture.get(), &KWayland::Client::PointerSwipeGesture::started);
|
|
|
|
QSignalSpy updateSpy(gesture.get(), &KWayland::Client::PointerSwipeGesture::updated);
|
|
|
|
QSignalSpy endSpy(gesture.get(), &KWayland::Client::PointerSwipeGesture::ended);
|
|
|
|
QSignalSpy cancelledSpy(gesture.get(), &KWayland::Client::PointerSwipeGesture::cancelled);
|
2016-10-26 08:27:14 +00:00
|
|
|
|
|
|
|
// now create a surface
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-10-26 08:27:14 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto serverSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface *>();
|
2016-10-26 08:27:14 +00:00
|
|
|
QVERIFY(serverSurface);
|
2021-02-12 22:29:45 +00:00
|
|
|
|
|
|
|
QImage image(QSize(100, 100), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
image.fill(Qt::black);
|
|
|
|
surface->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
surface->damage(image.rect());
|
2022-11-08 21:15:17 +00:00
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy committedSpy(serverSurface, &KWin::SurfaceInterface::committed);
|
2021-02-12 22:29:45 +00:00
|
|
|
QVERIFY(committedSpy.wait());
|
|
|
|
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerEnter(serverSurface, QPointF(0, 0));
|
2016-10-26 08:27:14 +00:00
|
|
|
QCOMPARE(m_seatInterface->focusedPointerSurface(), serverSurface);
|
2021-02-12 22:29:45 +00:00
|
|
|
QVERIFY(m_seatInterface->pointer());
|
2016-10-26 08:27:14 +00:00
|
|
|
|
|
|
|
// send in the start
|
2022-12-21 00:55:20 +00:00
|
|
|
std::chrono::milliseconds timestamp(1);
|
2016-10-26 08:27:14 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
|
|
|
m_seatInterface->startPointerSwipeGesture(2);
|
|
|
|
QVERIFY(startSpy.wait());
|
|
|
|
QCOMPARE(startSpy.count(), 1);
|
|
|
|
QCOMPARE(startSpy.first().at(0).value<quint32>(), m_display->serial());
|
|
|
|
QCOMPARE(startSpy.first().at(1).value<quint32>(), 1u);
|
|
|
|
QCOMPARE(gesture->fingerCount(), 2u);
|
2022-08-01 21:29:02 +00:00
|
|
|
QCOMPARE(gesture->surface().data(), surface.get());
|
2016-10-26 08:27:14 +00:00
|
|
|
|
|
|
|
// another start should not be possible
|
|
|
|
m_seatInterface->startPointerSwipeGesture(2);
|
2023-04-21 14:30:58 +00:00
|
|
|
QVERIFY(sync());
|
|
|
|
QCOMPARE(startSpy.count(), 1);
|
2016-10-26 08:27:14 +00:00
|
|
|
|
|
|
|
// send in some updates
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2022-10-25 08:18:45 +00:00
|
|
|
m_seatInterface->updatePointerSwipeGesture(QPointF(2, 3));
|
2016-10-26 08:27:14 +00:00
|
|
|
QVERIFY(updateSpy.wait());
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2022-10-25 08:18:45 +00:00
|
|
|
m_seatInterface->updatePointerSwipeGesture(QPointF(4, 5));
|
2016-10-26 08:27:14 +00:00
|
|
|
QVERIFY(updateSpy.wait());
|
|
|
|
QCOMPARE(updateSpy.count(), 2);
|
|
|
|
QCOMPARE(updateSpy.at(0).at(0).toSizeF(), QSizeF(2, 3));
|
|
|
|
QCOMPARE(updateSpy.at(0).at(1).value<quint32>(), 2u);
|
|
|
|
QCOMPARE(updateSpy.at(1).at(0).toSizeF(), QSizeF(4, 5));
|
|
|
|
QCOMPARE(updateSpy.at(1).at(1).value<quint32>(), 3u);
|
|
|
|
|
|
|
|
// now end or cancel
|
|
|
|
QFETCH(bool, cancel);
|
|
|
|
QSignalSpy *spy;
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
|
|
|
if (cancel) {
|
|
|
|
m_seatInterface->cancelPointerSwipeGesture();
|
|
|
|
spy = &cancelledSpy;
|
|
|
|
} else {
|
|
|
|
m_seatInterface->endPointerSwipeGesture();
|
|
|
|
spy = &endSpy;
|
|
|
|
}
|
|
|
|
QVERIFY(spy->wait());
|
2022-10-22 12:00:46 +00:00
|
|
|
QFETCH(int, expectedEndCount);
|
|
|
|
QCOMPARE(endSpy.count(), expectedEndCount);
|
|
|
|
QFETCH(int, expectedCancelCount);
|
|
|
|
QCOMPARE(cancelledSpy.count(), expectedCancelCount);
|
2016-10-26 08:27:14 +00:00
|
|
|
QCOMPARE(spy->count(), 1);
|
|
|
|
QCOMPARE(spy->first().at(0).value<quint32>(), m_display->serial());
|
|
|
|
QCOMPARE(spy->first().at(1).value<quint32>(), 4u);
|
|
|
|
|
|
|
|
QCOMPARE(gesture->fingerCount(), 0u);
|
|
|
|
QVERIFY(gesture->surface().isNull());
|
|
|
|
|
|
|
|
// now a start should be possible again
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
|
|
|
m_seatInterface->startPointerSwipeGesture(2);
|
|
|
|
QVERIFY(startSpy.wait());
|
|
|
|
|
|
|
|
// unsetting the focused pointer surface should not change anything
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerLeave();
|
2016-10-26 08:27:14 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2022-10-25 08:18:45 +00:00
|
|
|
m_seatInterface->updatePointerSwipeGesture(QPointF(6, 7));
|
2016-10-26 08:27:14 +00:00
|
|
|
QVERIFY(updateSpy.wait());
|
|
|
|
// and end
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
|
|
|
if (cancel) {
|
|
|
|
m_seatInterface->cancelPointerSwipeGesture();
|
|
|
|
} else {
|
|
|
|
m_seatInterface->endPointerSwipeGesture();
|
|
|
|
}
|
|
|
|
QVERIFY(spy->wait());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSeat::testPointerPinchGesture_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("cancel");
|
|
|
|
QTest::addColumn<int>("expectedEndCount");
|
|
|
|
QTest::addColumn<int>("expectedCancelCount");
|
|
|
|
|
|
|
|
QTest::newRow("end") << false << 1 << 0;
|
|
|
|
QTest::newRow("cancel") << true << 0 << 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestWaylandSeat::testPointerPinchGesture()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2016-10-26 08:27:14 +00:00
|
|
|
|
|
|
|
// first create the pointer and pointer swipe gesture
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy hasPointerChangedSpy(m_seat, &KWayland::Client::Seat::hasPointerChanged);
|
2016-10-26 08:27:14 +00:00
|
|
|
m_seatInterface->setHasPointer(true);
|
|
|
|
QVERIFY(hasPointerChangedSpy.wait());
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Pointer> pointer(m_seat->createPointer());
|
|
|
|
std::unique_ptr<KWayland::Client::PointerPinchGesture> gesture(m_pointerGestures->createPinchGesture(pointer.get()));
|
2016-10-26 08:27:14 +00:00
|
|
|
QVERIFY(gesture);
|
|
|
|
QVERIFY(gesture->isValid());
|
|
|
|
QVERIFY(gesture->surface().isNull());
|
|
|
|
QCOMPARE(gesture->fingerCount(), 0u);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy startSpy(gesture.get(), &KWayland::Client::PointerPinchGesture::started);
|
|
|
|
QSignalSpy updateSpy(gesture.get(), &KWayland::Client::PointerPinchGesture::updated);
|
|
|
|
QSignalSpy endSpy(gesture.get(), &KWayland::Client::PointerPinchGesture::ended);
|
|
|
|
QSignalSpy cancelledSpy(gesture.get(), &KWayland::Client::PointerPinchGesture::cancelled);
|
2016-10-26 08:27:14 +00:00
|
|
|
|
|
|
|
// now create a surface
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-10-26 08:27:14 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto serverSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface *>();
|
2016-10-26 08:27:14 +00:00
|
|
|
QVERIFY(serverSurface);
|
2021-02-12 22:29:45 +00:00
|
|
|
|
|
|
|
QImage image(QSize(100, 100), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
image.fill(Qt::black);
|
|
|
|
surface->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
surface->damage(image.rect());
|
2022-11-08 21:15:17 +00:00
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy committedSpy(serverSurface, &KWin::SurfaceInterface::committed);
|
2021-02-12 22:29:45 +00:00
|
|
|
QVERIFY(committedSpy.wait());
|
|
|
|
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerEnter(serverSurface, QPointF(0, 0));
|
2016-10-26 08:27:14 +00:00
|
|
|
QCOMPARE(m_seatInterface->focusedPointerSurface(), serverSurface);
|
2021-02-12 22:29:45 +00:00
|
|
|
QVERIFY(m_seatInterface->pointer());
|
2016-10-26 08:27:14 +00:00
|
|
|
|
|
|
|
// send in the start
|
2022-12-21 00:55:20 +00:00
|
|
|
std::chrono::milliseconds timestamp(1);
|
2016-10-26 08:27:14 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
|
|
|
m_seatInterface->startPointerPinchGesture(3);
|
|
|
|
QVERIFY(startSpy.wait());
|
|
|
|
QCOMPARE(startSpy.count(), 1);
|
|
|
|
QCOMPARE(startSpy.first().at(0).value<quint32>(), m_display->serial());
|
|
|
|
QCOMPARE(startSpy.first().at(1).value<quint32>(), 1u);
|
|
|
|
QCOMPARE(gesture->fingerCount(), 3u);
|
2022-08-01 21:29:02 +00:00
|
|
|
QCOMPARE(gesture->surface().data(), surface.get());
|
2016-10-26 08:27:14 +00:00
|
|
|
|
|
|
|
// another start should not be possible
|
|
|
|
m_seatInterface->startPointerPinchGesture(3);
|
2023-04-21 14:30:58 +00:00
|
|
|
QVERIFY(sync());
|
|
|
|
QCOMPARE(startSpy.count(), 1);
|
2016-10-26 08:27:14 +00:00
|
|
|
|
|
|
|
// send in some updates
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2022-10-25 08:18:45 +00:00
|
|
|
m_seatInterface->updatePointerPinchGesture(QPointF(2, 3), 2, 45);
|
2016-10-26 08:27:14 +00:00
|
|
|
QVERIFY(updateSpy.wait());
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2022-10-25 08:18:45 +00:00
|
|
|
m_seatInterface->updatePointerPinchGesture(QPointF(4, 5), 1, 90);
|
2016-10-26 08:27:14 +00:00
|
|
|
QVERIFY(updateSpy.wait());
|
|
|
|
QCOMPARE(updateSpy.count(), 2);
|
|
|
|
QCOMPARE(updateSpy.at(0).at(0).toSizeF(), QSizeF(2, 3));
|
|
|
|
QCOMPARE(updateSpy.at(0).at(1).value<quint32>(), 2u);
|
|
|
|
QCOMPARE(updateSpy.at(0).at(2).value<quint32>(), 45u);
|
|
|
|
QCOMPARE(updateSpy.at(0).at(3).value<quint32>(), 2u);
|
|
|
|
QCOMPARE(updateSpy.at(1).at(0).toSizeF(), QSizeF(4, 5));
|
|
|
|
QCOMPARE(updateSpy.at(1).at(1).value<quint32>(), 1u);
|
|
|
|
QCOMPARE(updateSpy.at(1).at(2).value<quint32>(), 90u);
|
|
|
|
QCOMPARE(updateSpy.at(1).at(3).value<quint32>(), 3u);
|
|
|
|
|
|
|
|
// now end or cancel
|
|
|
|
QFETCH(bool, cancel);
|
|
|
|
QSignalSpy *spy;
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
|
|
|
if (cancel) {
|
|
|
|
m_seatInterface->cancelPointerPinchGesture();
|
|
|
|
spy = &cancelledSpy;
|
|
|
|
} else {
|
|
|
|
m_seatInterface->endPointerPinchGesture();
|
|
|
|
spy = &endSpy;
|
|
|
|
}
|
|
|
|
QVERIFY(spy->wait());
|
2022-10-22 12:00:46 +00:00
|
|
|
QFETCH(int, expectedEndCount);
|
|
|
|
QCOMPARE(endSpy.count(), expectedEndCount);
|
|
|
|
QFETCH(int, expectedCancelCount);
|
|
|
|
QCOMPARE(cancelledSpy.count(), expectedCancelCount);
|
2016-10-26 08:27:14 +00:00
|
|
|
QCOMPARE(spy->count(), 1);
|
|
|
|
QCOMPARE(spy->first().at(0).value<quint32>(), m_display->serial());
|
|
|
|
QCOMPARE(spy->first().at(1).value<quint32>(), 4u);
|
|
|
|
|
|
|
|
QCOMPARE(gesture->fingerCount(), 0u);
|
|
|
|
QVERIFY(gesture->surface().isNull());
|
|
|
|
|
|
|
|
// now a start should be possible again
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
|
|
|
m_seatInterface->startPointerPinchGesture(3);
|
|
|
|
QVERIFY(startSpy.wait());
|
|
|
|
|
|
|
|
// unsetting the focused pointer surface should not change anything
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerLeave();
|
2016-10-26 08:27:14 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2022-10-25 08:18:45 +00:00
|
|
|
m_seatInterface->updatePointerPinchGesture(QPointF(6, 7), 2, -45);
|
2016-10-26 08:27:14 +00:00
|
|
|
QVERIFY(updateSpy.wait());
|
|
|
|
// and end
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
|
|
|
if (cancel) {
|
|
|
|
m_seatInterface->cancelPointerPinchGesture();
|
|
|
|
} else {
|
|
|
|
m_seatInterface->endPointerPinchGesture();
|
|
|
|
}
|
|
|
|
QVERIFY(spy->wait());
|
|
|
|
}
|
|
|
|
|
2021-08-05 08:21:29 +00:00
|
|
|
void TestWaylandSeat::testPointerHoldGesture_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("cancel");
|
|
|
|
QTest::addColumn<int>("expectedEndCount");
|
|
|
|
QTest::addColumn<int>("expectedCancelCount");
|
|
|
|
|
|
|
|
QTest::newRow("end") << false << 1 << 0;
|
|
|
|
QTest::newRow("cancel") << true << 0 << 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
class PointerHoldGesture : public QObject, public QtWayland::zwp_pointer_gesture_hold_v1
|
|
|
|
{
|
|
|
|
using zwp_pointer_gesture_hold_v1::zwp_pointer_gesture_hold_v1;
|
|
|
|
Q_OBJECT
|
|
|
|
void zwp_pointer_gesture_hold_v1_begin(uint32_t serial, uint32_t time, wl_surface *surface, uint32_t fingers) override
|
|
|
|
{
|
2022-04-19 10:14:26 +00:00
|
|
|
Q_EMIT started(serial, time, surface, fingers);
|
2021-08-05 08:21:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void zwp_pointer_gesture_hold_v1_end(uint32_t serial, uint32_t time, int32_t cancelled) override
|
|
|
|
{
|
2022-04-19 10:14:26 +00:00
|
|
|
cancelled ? Q_EMIT this->cancelled(serial, time) : Q_EMIT ended(serial, time);
|
2021-08-05 08:21:29 +00:00
|
|
|
}
|
|
|
|
Q_SIGNALS:
|
2022-04-19 10:14:26 +00:00
|
|
|
void started(quint32 serial, quint32 time, void *surface, quint32 fingers);
|
2021-08-05 08:21:29 +00:00
|
|
|
void ended(quint32 serial, quint32 time);
|
|
|
|
void cancelled(quint32 serial, quint32 time);
|
|
|
|
};
|
|
|
|
|
|
|
|
void TestWaylandSeat::testPointerHoldGesture()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2021-08-05 08:21:29 +00:00
|
|
|
|
|
|
|
// first create the pointer and pointer swipe gesture
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy hasPointerChangedSpy(m_seat, &KWayland::Client::Seat::hasPointerChanged);
|
2021-08-05 08:21:29 +00:00
|
|
|
m_seatInterface->setHasPointer(true);
|
|
|
|
QVERIFY(hasPointerChangedSpy.wait());
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Pointer> pointer(m_seat->createPointer());
|
|
|
|
KWayland::Client::Registry registry;
|
|
|
|
QSignalSpy gesturesAnnoucedSpy(®istry, &KWayland::Client::Registry::pointerGesturesUnstableV1Announced);
|
2021-08-05 08:21:29 +00:00
|
|
|
registry.create(m_connection);
|
|
|
|
registry.setup();
|
|
|
|
QVERIFY(gesturesAnnoucedSpy.wait());
|
|
|
|
QtWayland::zwp_pointer_gestures_v1 gestures(registry, gesturesAnnoucedSpy.first().at(0).value<int>(), gesturesAnnoucedSpy.first().at(1).value<int>());
|
|
|
|
PointerHoldGesture gesture(gestures.get_hold_gesture(*pointer));
|
|
|
|
QVERIFY(gesture.isInitialized());
|
|
|
|
|
|
|
|
QSignalSpy startSpy(&gesture, &PointerHoldGesture::started);
|
|
|
|
QSignalSpy endSpy(&gesture, &PointerHoldGesture::ended);
|
|
|
|
QSignalSpy cancelledSpy(&gesture, &PointerHoldGesture::cancelled);
|
|
|
|
|
|
|
|
// now create a surface
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2021-08-05 08:21:29 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2022-04-19 10:14:26 +00:00
|
|
|
auto serverSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface *>();
|
2021-08-05 08:21:29 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
|
|
|
|
QImage image(QSize(100, 100), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
image.fill(Qt::black);
|
|
|
|
surface->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
surface->damage(image.rect());
|
2022-11-08 21:15:17 +00:00
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy committedSpy(serverSurface, &KWin::SurfaceInterface::committed);
|
2021-08-05 08:21:29 +00:00
|
|
|
QVERIFY(committedSpy.wait());
|
|
|
|
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerEnter(serverSurface, QPointF(0, 0));
|
2021-08-05 08:21:29 +00:00
|
|
|
QCOMPARE(m_seatInterface->focusedPointerSurface(), serverSurface);
|
|
|
|
QVERIFY(m_seatInterface->pointer());
|
|
|
|
|
|
|
|
// send in the start
|
2022-12-21 00:55:20 +00:00
|
|
|
std::chrono::milliseconds timestamp(1);
|
2021-08-05 08:21:29 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
|
|
|
m_seatInterface->startPointerHoldGesture(3);
|
|
|
|
QVERIFY(startSpy.wait());
|
|
|
|
QCOMPARE(startSpy.count(), 1);
|
|
|
|
QCOMPARE(startSpy.first().at(0).value<quint32>(), m_display->serial());
|
|
|
|
QCOMPARE(startSpy.first().at(1).value<quint32>(), 1u);
|
2022-04-19 10:14:26 +00:00
|
|
|
QCOMPARE(startSpy.first().at(2).value<void *>(), *surface.get());
|
2021-08-05 08:21:29 +00:00
|
|
|
QCOMPARE(startSpy.first().at(3).value<quint32>(), 3);
|
|
|
|
|
|
|
|
// another start should not be possible
|
|
|
|
m_seatInterface->startPointerPinchGesture(3);
|
2023-04-21 14:30:58 +00:00
|
|
|
QVERIFY(sync());
|
|
|
|
QCOMPARE(startSpy.count(), 1);
|
2021-08-05 08:21:29 +00:00
|
|
|
|
|
|
|
// now end or cancel
|
|
|
|
QFETCH(bool, cancel);
|
|
|
|
QSignalSpy *spy;
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
|
|
|
if (cancel) {
|
|
|
|
m_seatInterface->cancelPointerHoldGesture();
|
|
|
|
spy = &cancelledSpy;
|
|
|
|
} else {
|
|
|
|
m_seatInterface->endPointerHoldGesture();
|
|
|
|
spy = &endSpy;
|
|
|
|
}
|
|
|
|
QVERIFY(spy->wait());
|
2022-10-22 12:00:46 +00:00
|
|
|
QFETCH(int, expectedEndCount);
|
|
|
|
QCOMPARE(endSpy.count(), expectedEndCount);
|
|
|
|
QFETCH(int, expectedCancelCount);
|
|
|
|
QCOMPARE(cancelledSpy.count(), expectedCancelCount);
|
2021-08-05 08:21:29 +00:00
|
|
|
QCOMPARE(spy->count(), 1);
|
|
|
|
QCOMPARE(spy->first().at(0).value<quint32>(), m_display->serial());
|
|
|
|
QCOMPARE(spy->first().at(1).value<quint32>(), 2);
|
|
|
|
|
|
|
|
// now a start should be possible again
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
|
|
|
m_seatInterface->startPointerHoldGesture(3);
|
|
|
|
QVERIFY(startSpy.wait());
|
|
|
|
|
|
|
|
// and end
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
|
|
|
if (cancel) {
|
|
|
|
m_seatInterface->cancelPointerHoldGesture();
|
|
|
|
} else {
|
|
|
|
m_seatInterface->endPointerHoldGesture();
|
|
|
|
}
|
|
|
|
QVERIFY(spy->wait());
|
|
|
|
}
|
|
|
|
|
2019-02-11 16:35:23 +00:00
|
|
|
void TestWaylandSeat::testPointerAxis()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2019-02-11 16:35:23 +00:00
|
|
|
|
|
|
|
// first create the pointer
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy hasPointerChangedSpy(m_seat, &KWayland::Client::Seat::hasPointerChanged);
|
2019-02-11 16:35:23 +00:00
|
|
|
m_seatInterface->setHasPointer(true);
|
|
|
|
QVERIFY(hasPointerChangedSpy.wait());
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Pointer> pointer(m_seat->createPointer());
|
2019-02-11 16:35:23 +00:00
|
|
|
QVERIFY(pointer);
|
|
|
|
|
|
|
|
// now create a surface
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2019-02-11 16:35:23 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto serverSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface *>();
|
2019-02-11 16:35:23 +00:00
|
|
|
QVERIFY(serverSurface);
|
2021-02-12 22:29:45 +00:00
|
|
|
|
|
|
|
QImage image(QSize(100, 100), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
image.fill(Qt::black);
|
|
|
|
surface->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
surface->damage(image.rect());
|
2022-11-08 21:15:17 +00:00
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy committedSpy(serverSurface, &KWin::SurfaceInterface::committed);
|
2021-02-12 22:29:45 +00:00
|
|
|
QVERIFY(committedSpy.wait());
|
|
|
|
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerEnter(serverSurface, QPointF(0, 0));
|
2019-02-11 16:35:23 +00:00
|
|
|
QCOMPARE(m_seatInterface->focusedPointerSurface(), serverSurface);
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy frameSpy(pointer.get(), &KWayland::Client::Pointer::frame);
|
2019-02-11 16:35:23 +00:00
|
|
|
QVERIFY(frameSpy.wait());
|
|
|
|
QCOMPARE(frameSpy.count(), 1);
|
|
|
|
|
|
|
|
// let's scroll vertically
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy axisSourceSpy(pointer.get(), &KWayland::Client::Pointer::axisSourceChanged);
|
|
|
|
QSignalSpy axisSpy(pointer.get(), &KWayland::Client::Pointer::axisChanged);
|
|
|
|
QSignalSpy axisDiscreteSpy(pointer.get(), &KWayland::Client::Pointer::axisDiscreteChanged);
|
|
|
|
QSignalSpy axisStoppedSpy(pointer.get(), &KWayland::Client::Pointer::axisStopped);
|
2019-02-11 16:35:23 +00:00
|
|
|
|
2022-12-21 00:55:20 +00:00
|
|
|
std::chrono::milliseconds timestamp(1);
|
2019-02-11 16:35:23 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2022-10-11 10:33:04 +00:00
|
|
|
m_seatInterface->notifyPointerAxis(Qt::Vertical, 10, 120, PointerAxisSource::Wheel);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerFrame();
|
2019-02-11 16:35:23 +00:00
|
|
|
QVERIFY(frameSpy.wait());
|
|
|
|
QCOMPARE(frameSpy.count(), 2);
|
|
|
|
QCOMPARE(axisSourceSpy.count(), 1);
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(axisSourceSpy.last().at(0).value<KWayland::Client::Pointer::AxisSource>(), KWayland::Client::Pointer::AxisSource::Wheel);
|
2019-02-11 16:35:23 +00:00
|
|
|
QCOMPARE(axisDiscreteSpy.count(), 1);
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(axisDiscreteSpy.last().at(0).value<KWayland::Client::Pointer::Axis>(), KWayland::Client::Pointer::Axis::Vertical);
|
2019-02-11 16:35:23 +00:00
|
|
|
QCOMPARE(axisDiscreteSpy.last().at(1).value<qint32>(), 1);
|
|
|
|
QCOMPARE(axisSpy.count(), 1);
|
|
|
|
QCOMPARE(axisSpy.last().at(0).value<quint32>(), quint32(1));
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(axisSpy.last().at(1).value<KWayland::Client::Pointer::Axis>(), KWayland::Client::Pointer::Axis::Vertical);
|
2019-02-11 16:35:23 +00:00
|
|
|
QCOMPARE(axisSpy.last().at(2).value<qreal>(), 10.0);
|
|
|
|
QCOMPARE(axisStoppedSpy.count(), 0);
|
|
|
|
|
|
|
|
// let's scroll using fingers
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerAxis(Qt::Horizontal, 42, 0, PointerAxisSource::Finger);
|
|
|
|
m_seatInterface->notifyPointerFrame();
|
2019-02-11 16:35:23 +00:00
|
|
|
QVERIFY(frameSpy.wait());
|
|
|
|
QCOMPARE(frameSpy.count(), 3);
|
|
|
|
QCOMPARE(axisSourceSpy.count(), 2);
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(axisSourceSpy.last().at(0).value<KWayland::Client::Pointer::AxisSource>(), KWayland::Client::Pointer::AxisSource::Finger);
|
2019-02-11 16:35:23 +00:00
|
|
|
QCOMPARE(axisDiscreteSpy.count(), 1);
|
|
|
|
QCOMPARE(axisSpy.count(), 2);
|
|
|
|
QCOMPARE(axisSpy.last().at(0).value<quint32>(), quint32(2));
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(axisSpy.last().at(1).value<KWayland::Client::Pointer::Axis>(), KWayland::Client::Pointer::Axis::Horizontal);
|
2019-02-11 16:35:23 +00:00
|
|
|
QCOMPARE(axisSpy.last().at(2).value<qreal>(), 42.0);
|
|
|
|
QCOMPARE(axisStoppedSpy.count(), 0);
|
|
|
|
|
|
|
|
// lift the fingers off the device
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerAxis(Qt::Horizontal, 0, 0, PointerAxisSource::Finger);
|
|
|
|
m_seatInterface->notifyPointerFrame();
|
2019-02-11 16:35:23 +00:00
|
|
|
QVERIFY(frameSpy.wait());
|
|
|
|
QCOMPARE(frameSpy.count(), 4);
|
|
|
|
QCOMPARE(axisSourceSpy.count(), 3);
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(axisSourceSpy.last().at(0).value<KWayland::Client::Pointer::AxisSource>(), KWayland::Client::Pointer::AxisSource::Finger);
|
2019-02-11 16:35:23 +00:00
|
|
|
QCOMPARE(axisDiscreteSpy.count(), 1);
|
|
|
|
QCOMPARE(axisSpy.count(), 2);
|
|
|
|
QCOMPARE(axisStoppedSpy.count(), 1);
|
|
|
|
QCOMPARE(axisStoppedSpy.last().at(0).value<quint32>(), 3);
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(axisStoppedSpy.last().at(1).value<KWayland::Client::Pointer::Axis>(), KWayland::Client::Pointer::Axis::Horizontal);
|
2019-02-11 16:35:23 +00:00
|
|
|
|
|
|
|
// if the device is unknown, no axis_source event should be sent
|
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2022-10-11 10:33:04 +00:00
|
|
|
m_seatInterface->notifyPointerAxis(Qt::Horizontal, 42, 120, PointerAxisSource::Unknown);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyPointerFrame();
|
2019-02-11 16:35:23 +00:00
|
|
|
QVERIFY(frameSpy.wait());
|
|
|
|
QCOMPARE(frameSpy.count(), 5);
|
|
|
|
QCOMPARE(axisSourceSpy.count(), 3);
|
|
|
|
QCOMPARE(axisDiscreteSpy.count(), 2);
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(axisDiscreteSpy.last().at(0).value<KWayland::Client::Pointer::Axis>(), KWayland::Client::Pointer::Axis::Horizontal);
|
2019-02-11 16:35:23 +00:00
|
|
|
QCOMPARE(axisDiscreteSpy.last().at(1).value<qint32>(), 1);
|
|
|
|
QCOMPARE(axisSpy.count(), 3);
|
|
|
|
QCOMPARE(axisSpy.last().at(0).value<quint32>(), quint32(4));
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(axisSpy.last().at(1).value<KWayland::Client::Pointer::Axis>(), KWayland::Client::Pointer::Axis::Horizontal);
|
2019-02-11 16:35:23 +00:00
|
|
|
QCOMPARE(axisSpy.last().at(2).value<qreal>(), 42.0);
|
|
|
|
QCOMPARE(axisStoppedSpy.count(), 1);
|
|
|
|
}
|
|
|
|
|
2015-02-27 16:36:43 +00:00
|
|
|
void TestWaylandSeat::testCursor()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2015-02-27 16:36:43 +00:00
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy pointerSpy(m_seat, &KWayland::Client::Seat::hasPointerChanged);
|
2015-02-27 16:36:43 +00:00
|
|
|
m_seatInterface->setHasPointer(true);
|
|
|
|
QVERIFY(pointerSpy.wait());
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &KWin::CompositorInterface::surfaceCreated);
|
2021-02-12 22:29:45 +00:00
|
|
|
KWayland::Client::Surface *surface = m_compositor->createSurface(m_compositor);
|
2015-02-27 16:36:43 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value<KWin::SurfaceInterface *>();
|
2015-02-27 16:36:43 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
|
2021-02-12 22:29:45 +00:00
|
|
|
QImage image(QSize(100, 100), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
image.fill(Qt::black);
|
|
|
|
surface->attachBuffer(m_shm->createBuffer(image));
|
|
|
|
surface->damage(image.rect());
|
2022-11-08 21:15:17 +00:00
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy committedSpy(serverSurface, &KWin::SurfaceInterface::committed);
|
2021-02-12 22:29:45 +00:00
|
|
|
QVERIFY(committedSpy.wait());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Pointer> p(m_seat->createPointer());
|
2015-02-27 16:36:43 +00:00
|
|
|
QVERIFY(p->isValid());
|
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
QSignalSpy enteredSpy(p.get(), &KWayland::Client::Pointer::entered);
|
2015-02-27 16:36:43 +00:00
|
|
|
|
2023-04-19 12:16:23 +00:00
|
|
|
uint32_t serial = m_seatInterface->display()->serial();
|
2022-02-23 19:03:51 +00:00
|
|
|
m_seatInterface->notifyPointerEnter(serverSurface, QPointF(20, 18), QPointF(10, 15));
|
2015-02-27 16:36:43 +00:00
|
|
|
QVERIFY(enteredSpy.wait());
|
2023-04-19 12:16:23 +00:00
|
|
|
QCOMPARE_GT(enteredSpy.first().first().value<quint32>(), serial);
|
2015-02-27 16:36:43 +00:00
|
|
|
QVERIFY(m_seatInterface->focusedPointerSurface());
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy cursorChangedSpy(m_seatInterface->pointer(), &KWin::PointerInterface::cursorChanged);
|
2015-02-27 16:36:43 +00:00
|
|
|
// just remove the pointer
|
|
|
|
p->setCursor(nullptr);
|
|
|
|
QVERIFY(cursorChangedSpy.wait());
|
|
|
|
QCOMPARE(cursorChangedSpy.count(), 1);
|
2023-09-13 17:59:29 +00:00
|
|
|
auto cursor = std::get<KWin::PointerSurfaceCursor *>(cursorChangedSpy.last().first().value<KWin::PointerCursor>());
|
2015-02-27 16:36:43 +00:00
|
|
|
QVERIFY(cursor);
|
|
|
|
QVERIFY(!cursor->surface());
|
|
|
|
QCOMPARE(cursor->hotspot(), QPoint());
|
|
|
|
|
|
|
|
// test changing hotspot
|
|
|
|
p->setCursor(nullptr, QPoint(1, 2));
|
2023-05-07 12:44:24 +00:00
|
|
|
QVERIFY(cursorChangedSpy.wait());
|
2015-02-27 16:36:43 +00:00
|
|
|
QCOMPARE(cursorChangedSpy.count(), 2);
|
2023-05-07 12:44:24 +00:00
|
|
|
QCOMPARE(cursor->surface(), nullptr);
|
2015-02-27 16:36:43 +00:00
|
|
|
QCOMPARE(cursor->hotspot(), QPoint(1, 2));
|
|
|
|
|
|
|
|
// set surface
|
|
|
|
QImage img(QSize(10, 20), QImage::Format_RGB32);
|
|
|
|
img.fill(Qt::red);
|
2023-05-07 12:44:24 +00:00
|
|
|
auto cursorSurface = m_compositor->createSurface(m_compositor);
|
2015-02-27 16:36:43 +00:00
|
|
|
cursorSurface->attachBuffer(m_shm->createBuffer(img));
|
|
|
|
cursorSurface->damage(QRect(0, 0, 10, 20));
|
2022-11-08 21:15:17 +00:00
|
|
|
cursorSurface->commit(KWayland::Client::Surface::CommitFlag::None);
|
2023-05-07 12:44:24 +00:00
|
|
|
p->setCursor(cursorSurface, QPoint(1, 2));
|
|
|
|
QVERIFY(cursorChangedSpy.wait());
|
|
|
|
QCOMPARE(cursorChangedSpy.count(), 3);
|
|
|
|
QCOMPARE(cursor->hotspot(), QPoint(1, 2));
|
|
|
|
QVERIFY(cursor->surface());
|
2015-02-27 16:36:43 +00:00
|
|
|
|
2016-02-24 15:46:21 +00:00
|
|
|
p->hideCursor();
|
|
|
|
QVERIFY(cursorChangedSpy.wait());
|
2023-05-07 12:44:24 +00:00
|
|
|
QCOMPARE(cursorChangedSpy.count(), 4);
|
|
|
|
QVERIFY(!cursor->surface());
|
2016-02-24 15:46:21 +00:00
|
|
|
}
|
|
|
|
|
2014-09-02 07:34:31 +00:00
|
|
|
void TestWaylandSeat::testKeyboard()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy keyboardSpy(m_seat, &KWayland::Client::Seat::hasKeyboardChanged);
|
2014-09-02 07:34:31 +00:00
|
|
|
m_seatInterface->setHasKeyboard(true);
|
|
|
|
QVERIFY(keyboardSpy.wait());
|
|
|
|
|
2020-12-07 16:40:14 +00:00
|
|
|
// update modifiers before any surface focused
|
2021-03-24 09:50:52 +00:00
|
|
|
m_seatInterface->notifyKeyboardModifiers(4, 3, 2, 1);
|
2020-12-07 16:40:14 +00:00
|
|
|
|
2014-09-02 07:34:31 +00:00
|
|
|
// create the surface
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &KWin::CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Surface *s = m_compositor->createSurface(m_compositor);
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value<KWin::SurfaceInterface *>();
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Keyboard *keyboard = m_seat->createKeyboard(m_seat);
|
|
|
|
QSignalSpy repeatInfoSpy(keyboard, &KWayland::Client::Keyboard::keyRepeatChanged);
|
|
|
|
const KWayland::Client::Keyboard &ckeyboard = *keyboard;
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(keyboard->isValid());
|
2015-09-02 14:00:11 +00:00
|
|
|
QCOMPARE(keyboard->isKeyRepeatEnabled(), false);
|
|
|
|
QCOMPARE(keyboard->keyRepeatDelay(), 0);
|
|
|
|
QCOMPARE(keyboard->keyRepeatRate(), 0);
|
2020-10-02 14:22:59 +00:00
|
|
|
QVERIFY(repeatInfoSpy.wait());
|
2023-04-21 14:30:58 +00:00
|
|
|
|
2020-10-02 14:22:59 +00:00
|
|
|
auto serverKeyboard = m_seatInterface->keyboard();
|
2016-06-28 15:02:22 +00:00
|
|
|
QVERIFY(serverKeyboard);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2015-09-02 14:00:11 +00:00
|
|
|
// we should get the repeat info announced
|
|
|
|
QCOMPARE(repeatInfoSpy.count(), 1);
|
|
|
|
QCOMPARE(keyboard->isKeyRepeatEnabled(), false);
|
|
|
|
QCOMPARE(keyboard->keyRepeatDelay(), 0);
|
|
|
|
QCOMPARE(keyboard->keyRepeatRate(), 0);
|
|
|
|
|
|
|
|
// let's change repeat in server
|
2020-11-06 04:33:47 +00:00
|
|
|
m_seatInterface->keyboard()->setRepeatInfo(25, 660);
|
2015-09-02 14:00:11 +00:00
|
|
|
QVERIFY(repeatInfoSpy.wait());
|
|
|
|
QCOMPARE(repeatInfoSpy.count(), 2);
|
|
|
|
QCOMPARE(keyboard->isKeyRepeatEnabled(), true);
|
|
|
|
QCOMPARE(keyboard->keyRepeatRate(), 25);
|
|
|
|
QCOMPARE(keyboard->keyRepeatDelay(), 660);
|
|
|
|
|
2022-12-21 00:55:20 +00:00
|
|
|
std::chrono::milliseconds time(1);
|
|
|
|
|
|
|
|
m_seatInterface->setTimestamp(time++);
|
2021-03-24 09:50:52 +00:00
|
|
|
m_seatInterface->notifyKeyboardKey(KEY_K, KeyboardKeyState::Pressed);
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(time++);
|
2021-03-24 09:50:52 +00:00
|
|
|
m_seatInterface->notifyKeyboardKey(KEY_D, KeyboardKeyState::Pressed);
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(time++);
|
2021-03-24 09:50:52 +00:00
|
|
|
m_seatInterface->notifyKeyboardKey(KEY_E, KeyboardKeyState::Pressed);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy modifierSpy(keyboard, &KWayland::Client::Keyboard::modifiersChanged);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy enteredSpy(keyboard, &KWayland::Client::Keyboard::entered);
|
2014-11-26 14:00:44 +00:00
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
|
|
|
QCOMPARE(m_seatInterface->focusedKeyboardSurface(), serverSurface);
|
2020-10-02 14:22:59 +00:00
|
|
|
QCOMPARE(m_seatInterface->keyboard()->focusedSurface(), serverSurface);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
|
|
|
// we get the modifiers sent after the enter
|
|
|
|
QVERIFY(modifierSpy.wait());
|
|
|
|
QCOMPARE(modifierSpy.count(), 1);
|
2020-12-07 16:40:14 +00:00
|
|
|
QCOMPARE(modifierSpy.first().at(0).value<quint32>(), quint32(4));
|
|
|
|
QCOMPARE(modifierSpy.first().at(1).value<quint32>(), quint32(3));
|
|
|
|
QCOMPARE(modifierSpy.first().at(2).value<quint32>(), quint32(2));
|
|
|
|
QCOMPARE(modifierSpy.first().at(3).value<quint32>(), quint32(1));
|
2014-12-06 20:56:12 +00:00
|
|
|
QCOMPARE(enteredSpy.count(), 1);
|
2016-05-25 13:32:59 +00:00
|
|
|
// TODO: get through API
|
|
|
|
QCOMPARE(enteredSpy.first().first().value<quint32>(), m_display->serial() - 1);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy keyChangedSpy(keyboard, &KWayland::Client::Keyboard::keyChanged);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(time++);
|
2021-03-24 09:50:52 +00:00
|
|
|
m_seatInterface->notifyKeyboardKey(KEY_E, KeyboardKeyState::Released);
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(keyChangedSpy.wait());
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(time++);
|
2021-03-24 09:50:52 +00:00
|
|
|
m_seatInterface->notifyKeyboardKey(KEY_D, KeyboardKeyState::Released);
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(keyChangedSpy.wait());
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(time++);
|
2021-03-24 09:50:52 +00:00
|
|
|
m_seatInterface->notifyKeyboardKey(KEY_K, KeyboardKeyState::Released);
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(keyChangedSpy.wait());
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(time++);
|
2021-03-24 09:50:52 +00:00
|
|
|
m_seatInterface->notifyKeyboardKey(KEY_F1, KeyboardKeyState::Pressed);
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(keyChangedSpy.wait());
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(time++);
|
2021-03-24 09:50:52 +00:00
|
|
|
m_seatInterface->notifyKeyboardKey(KEY_F1, KeyboardKeyState::Released);
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(keyChangedSpy.wait());
|
|
|
|
|
|
|
|
QCOMPARE(keyChangedSpy.count(), 5);
|
|
|
|
QCOMPARE(keyChangedSpy.at(0).at(0).value<quint32>(), quint32(KEY_E));
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(keyChangedSpy.at(0).at(1).value<KWayland::Client::Keyboard::KeyState>(), KWayland::Client::Keyboard::KeyState::Released);
|
2014-09-02 07:34:31 +00:00
|
|
|
QCOMPARE(keyChangedSpy.at(0).at(2).value<quint32>(), quint32(4));
|
|
|
|
QCOMPARE(keyChangedSpy.at(1).at(0).value<quint32>(), quint32(KEY_D));
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(keyChangedSpy.at(1).at(1).value<KWayland::Client::Keyboard::KeyState>(), KWayland::Client::Keyboard::KeyState::Released);
|
2014-09-02 07:34:31 +00:00
|
|
|
QCOMPARE(keyChangedSpy.at(1).at(2).value<quint32>(), quint32(5));
|
|
|
|
QCOMPARE(keyChangedSpy.at(2).at(0).value<quint32>(), quint32(KEY_K));
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(keyChangedSpy.at(2).at(1).value<KWayland::Client::Keyboard::KeyState>(), KWayland::Client::Keyboard::KeyState::Released);
|
2014-09-02 07:34:31 +00:00
|
|
|
QCOMPARE(keyChangedSpy.at(2).at(2).value<quint32>(), quint32(6));
|
|
|
|
QCOMPARE(keyChangedSpy.at(3).at(0).value<quint32>(), quint32(KEY_F1));
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(keyChangedSpy.at(3).at(1).value<KWayland::Client::Keyboard::KeyState>(), KWayland::Client::Keyboard::KeyState::Pressed);
|
2014-09-02 07:34:31 +00:00
|
|
|
QCOMPARE(keyChangedSpy.at(3).at(2).value<quint32>(), quint32(7));
|
|
|
|
QCOMPARE(keyChangedSpy.at(4).at(0).value<quint32>(), quint32(KEY_F1));
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(keyChangedSpy.at(4).at(1).value<KWayland::Client::Keyboard::KeyState>(), KWayland::Client::Keyboard::KeyState::Released);
|
2014-09-02 07:34:31 +00:00
|
|
|
QCOMPARE(keyChangedSpy.at(4).at(2).value<quint32>(), quint32(8));
|
|
|
|
|
2016-09-15 07:27:03 +00:00
|
|
|
// releasing a key which is already released should not set a key changed
|
2021-03-24 09:50:52 +00:00
|
|
|
m_seatInterface->notifyKeyboardKey(KEY_F1, KeyboardKeyState::Released);
|
2023-04-21 14:30:58 +00:00
|
|
|
QVERIFY(sync());
|
|
|
|
QCOMPARE(keyChangedSpy.count(), 5);
|
2016-09-15 07:27:03 +00:00
|
|
|
// let's press it again
|
2021-03-24 09:50:52 +00:00
|
|
|
m_seatInterface->notifyKeyboardKey(KEY_F1, KeyboardKeyState::Pressed);
|
2016-09-15 07:27:03 +00:00
|
|
|
QVERIFY(keyChangedSpy.wait());
|
|
|
|
QCOMPARE(keyChangedSpy.count(), 6);
|
|
|
|
// press again should be ignored
|
2021-03-24 09:50:52 +00:00
|
|
|
m_seatInterface->notifyKeyboardKey(KEY_F1, KeyboardKeyState::Pressed);
|
2023-04-21 14:30:58 +00:00
|
|
|
QVERIFY(sync());
|
|
|
|
QCOMPARE(keyChangedSpy.count(), 6);
|
2016-09-15 07:27:03 +00:00
|
|
|
// and release
|
2021-03-24 09:50:52 +00:00
|
|
|
m_seatInterface->notifyKeyboardKey(KEY_F1, KeyboardKeyState::Released);
|
2016-09-15 07:27:03 +00:00
|
|
|
QVERIFY(keyChangedSpy.wait());
|
|
|
|
QCOMPARE(keyChangedSpy.count(), 7);
|
|
|
|
|
2021-03-24 09:50:52 +00:00
|
|
|
m_seatInterface->notifyKeyboardModifiers(1, 2, 3, 4);
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(modifierSpy.wait());
|
|
|
|
QCOMPARE(modifierSpy.count(), 2);
|
|
|
|
QCOMPARE(modifierSpy.last().at(0).value<quint32>(), quint32(1));
|
|
|
|
QCOMPARE(modifierSpy.last().at(1).value<quint32>(), quint32(2));
|
|
|
|
QCOMPARE(modifierSpy.last().at(2).value<quint32>(), quint32(3));
|
|
|
|
QCOMPARE(modifierSpy.last().at(3).value<quint32>(), quint32(4));
|
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy leftSpy(keyboard, &KWayland::Client::Keyboard::left);
|
2014-11-26 14:00:44 +00:00
|
|
|
m_seatInterface->setFocusedKeyboardSurface(nullptr);
|
|
|
|
QVERIFY(!m_seatInterface->focusedKeyboardSurface());
|
2014-12-06 20:56:12 +00:00
|
|
|
QVERIFY(leftSpy.wait());
|
|
|
|
QCOMPARE(leftSpy.count(), 1);
|
2016-05-25 13:32:59 +00:00
|
|
|
// TODO: get through API
|
2021-08-29 05:11:06 +00:00
|
|
|
QCOMPARE(leftSpy.first().first().value<quint32>(), m_display->serial() - 1);
|
2014-12-06 20:56:12 +00:00
|
|
|
|
|
|
|
QVERIFY(!keyboard->enteredSurface());
|
|
|
|
QVERIFY(!ckeyboard.enteredSurface());
|
2014-09-02 07:34:31 +00:00
|
|
|
|
|
|
|
// enter it again
|
2014-11-26 14:00:44 +00:00
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
2014-09-02 07:34:31 +00:00
|
|
|
QVERIFY(modifierSpy.wait());
|
2014-11-26 14:00:44 +00:00
|
|
|
QCOMPARE(m_seatInterface->focusedKeyboardSurface(), serverSurface);
|
2020-10-02 14:22:59 +00:00
|
|
|
QCOMPARE(m_seatInterface->keyboard()->focusedSurface(), serverSurface);
|
2014-12-06 20:56:12 +00:00
|
|
|
QCOMPARE(enteredSpy.count(), 2);
|
|
|
|
|
|
|
|
QCOMPARE(keyboard->enteredSurface(), s);
|
|
|
|
QCOMPARE(ckeyboard.enteredSurface(), s);
|
2014-09-02 07:34:31 +00:00
|
|
|
|
2016-06-28 15:02:22 +00:00
|
|
|
QSignalSpy serverSurfaceDestroyedSpy(serverSurface, &QObject::destroyed);
|
2017-07-16 16:36:14 +00:00
|
|
|
QCOMPARE(keyboard->enteredSurface(), s);
|
2014-09-02 07:34:31 +00:00
|
|
|
delete s;
|
2017-07-16 16:36:14 +00:00
|
|
|
QVERIFY(!keyboard->enteredSurface());
|
2017-07-13 15:45:24 +00:00
|
|
|
QVERIFY(leftSpy.wait());
|
|
|
|
QCOMPARE(serverSurfaceDestroyedSpy.count(), 1);
|
2014-11-26 14:00:44 +00:00
|
|
|
QVERIFY(!m_seatInterface->focusedKeyboardSurface());
|
2016-06-28 15:02:22 +00:00
|
|
|
QVERIFY(!serverKeyboard->focusedSurface());
|
|
|
|
|
|
|
|
// let's create a Surface again
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> s2(m_compositor->createSurface());
|
2016-06-28 15:02:22 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
|
|
|
QCOMPARE(surfaceCreatedSpy.count(), 2);
|
2021-08-29 05:11:06 +00:00
|
|
|
serverSurface = surfaceCreatedSpy.last().first().value<SurfaceInterface *>();
|
2016-06-28 15:02:22 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
|
|
|
QCOMPARE(m_seatInterface->focusedKeyboardSurface(), serverSurface);
|
2020-10-02 14:22:59 +00:00
|
|
|
QCOMPARE(m_seatInterface->keyboard(), serverKeyboard);
|
2014-09-02 07:34:31 +00:00
|
|
|
}
|
|
|
|
|
2014-11-27 12:38:24 +00:00
|
|
|
void TestWaylandSeat::testSelection()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<DataDeviceManagerInterface> ddmi(new DataDeviceManagerInterface(m_display));
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Registry registry;
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy dataDeviceManagerSpy(®istry, &KWayland::Client::Registry::dataDeviceManagerAnnounced);
|
2020-10-02 14:22:59 +00:00
|
|
|
m_seatInterface->setHasKeyboard(true);
|
2014-11-27 12:38:24 +00:00
|
|
|
registry.setEventQueue(m_queue);
|
|
|
|
registry.create(m_connection->display());
|
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
|
|
|
|
|
|
|
QVERIFY(dataDeviceManagerSpy.wait());
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::DataDeviceManager> ddm(
|
2021-08-29 05:11:06 +00:00
|
|
|
registry.createDataDeviceManager(dataDeviceManagerSpy.first().first().value<quint32>(), dataDeviceManagerSpy.first().last().value<quint32>()));
|
2014-11-27 12:38:24 +00:00
|
|
|
QVERIFY(ddm->isValid());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::DataDevice> dd1(ddm->getDataDevice(m_seat));
|
2014-11-27 12:38:24 +00:00
|
|
|
QVERIFY(dd1->isValid());
|
2022-08-01 21:29:02 +00:00
|
|
|
QSignalSpy selectionSpy(dd1.get(), &KWayland::Client::DataDevice::selectionOffered);
|
|
|
|
QSignalSpy selectionClearedSpy(dd1.get(), &KWayland::Client::DataDevice::selectionCleared);
|
2014-11-27 12:38:24 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &KWin::CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2014-11-27 12:38:24 +00:00
|
|
|
QVERIFY(surface->isValid());
|
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto serverSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface *>();
|
2016-06-21 09:14:46 +00:00
|
|
|
QVERIFY(!m_seatInterface->selection());
|
2014-11-27 12:38:24 +00:00
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
|
|
|
QCOMPARE(m_seatInterface->focusedKeyboardSurface(), serverSurface);
|
2016-07-05 08:56:22 +00:00
|
|
|
QVERIFY(selectionClearedSpy.wait());
|
2014-11-27 12:38:24 +00:00
|
|
|
QVERIFY(selectionSpy.isEmpty());
|
2016-07-05 08:56:22 +00:00
|
|
|
QVERIFY(!selectionClearedSpy.isEmpty());
|
|
|
|
selectionClearedSpy.clear();
|
2016-06-21 09:14:46 +00:00
|
|
|
QVERIFY(!m_seatInterface->selection());
|
2014-11-27 12:38:24 +00:00
|
|
|
|
|
|
|
// now let's try to set a selection - we have keyboard focus, so it should be sent to us
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::DataSource> ds(ddm->createDataSource());
|
2014-11-27 12:38:24 +00:00
|
|
|
QVERIFY(ds->isValid());
|
|
|
|
ds->offer(QStringLiteral("text/plain"));
|
2022-08-01 21:29:02 +00:00
|
|
|
dd1->setSelection(0, ds.get());
|
2014-11-27 12:38:24 +00:00
|
|
|
QVERIFY(selectionSpy.wait());
|
|
|
|
QCOMPARE(selectionSpy.count(), 1);
|
2016-06-21 09:14:46 +00:00
|
|
|
auto ddi = m_seatInterface->selection();
|
|
|
|
QVERIFY(ddi);
|
2022-11-08 21:15:17 +00:00
|
|
|
auto df = selectionSpy.first().first().value<KWayland::Client::DataOffer *>();
|
2014-11-27 12:38:24 +00:00
|
|
|
QCOMPARE(df->offeredMimeTypes().count(), 1);
|
|
|
|
QCOMPARE(df->offeredMimeTypes().first().name(), QStringLiteral("text/plain"));
|
|
|
|
|
|
|
|
// try to clear
|
|
|
|
dd1->setSelection(0);
|
|
|
|
QVERIFY(selectionClearedSpy.wait());
|
|
|
|
QCOMPARE(selectionClearedSpy.count(), 1);
|
|
|
|
QCOMPARE(selectionSpy.count(), 1);
|
|
|
|
|
|
|
|
// unset the keyboard focus
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(nullptr);
|
|
|
|
QVERIFY(!m_seatInterface->focusedKeyboardSurface());
|
|
|
|
serverSurface->client()->flush();
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
|
|
|
|
// try to set Selection
|
2022-08-01 21:29:02 +00:00
|
|
|
dd1->setSelection(0, ds.get());
|
2014-11-27 12:38:24 +00:00
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QCOMPARE(selectionSpy.count(), 1);
|
2016-06-21 09:14:46 +00:00
|
|
|
|
|
|
|
// let's unset the selection on the seat
|
|
|
|
m_seatInterface->setSelection(nullptr);
|
|
|
|
// and pass focus back on our surface
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
|
|
|
// we don't have a selection, so it should not send a selection
|
2023-04-21 14:30:58 +00:00
|
|
|
QVERIFY(sync());
|
|
|
|
QCOMPARE(selectionSpy.count(), 1);
|
2016-06-21 09:14:46 +00:00
|
|
|
// now let's set it manually
|
|
|
|
m_seatInterface->setSelection(ddi);
|
|
|
|
QCOMPARE(m_seatInterface->selection(), ddi);
|
|
|
|
QVERIFY(selectionSpy.wait());
|
|
|
|
QCOMPARE(selectionSpy.count(), 2);
|
2016-06-28 12:57:42 +00:00
|
|
|
// setting the same again should not change
|
|
|
|
m_seatInterface->setSelection(ddi);
|
2023-04-21 14:30:58 +00:00
|
|
|
QVERIFY(sync());
|
|
|
|
QCOMPARE(selectionSpy.count(), 2);
|
2018-09-12 17:49:38 +00:00
|
|
|
// now clear it manually
|
2016-06-21 09:14:46 +00:00
|
|
|
m_seatInterface->setSelection(nullptr);
|
|
|
|
QVERIFY(selectionClearedSpy.wait());
|
2016-06-28 12:57:42 +00:00
|
|
|
QCOMPARE(selectionSpy.count(), 2);
|
2016-10-10 08:43:15 +00:00
|
|
|
|
|
|
|
// create a second ddi and a data source
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::DataDevice> dd2(ddm->getDataDevice(m_seat));
|
2016-10-10 08:43:15 +00:00
|
|
|
QVERIFY(dd2->isValid());
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::DataSource> ds2(ddm->createDataSource());
|
2016-10-10 08:43:15 +00:00
|
|
|
QVERIFY(ds2->isValid());
|
|
|
|
ds2->offer(QStringLiteral("text/plain"));
|
2022-08-01 21:29:02 +00:00
|
|
|
dd2->setSelection(0, ds2.get());
|
2016-10-10 08:43:15 +00:00
|
|
|
QVERIFY(selectionSpy.wait());
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy cancelledSpy(ds2.get(), &KWayland::Client::DataSource::cancelled);
|
2016-10-10 08:43:15 +00:00
|
|
|
m_seatInterface->setSelection(ddi);
|
|
|
|
QVERIFY(cancelledSpy.wait());
|
2016-10-24 08:04:33 +00:00
|
|
|
}
|
|
|
|
|
2016-10-24 09:05:04 +00:00
|
|
|
void TestWaylandSeat::testDataDeviceForKeyboardSurface()
|
|
|
|
{
|
|
|
|
// this test verifies that the server does not crash when creating a datadevice for the focused keyboard surface
|
|
|
|
// and the currentSelection does not have a DataSource.
|
|
|
|
// to properly test the functionality this test requires a second client
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2016-10-24 09:05:04 +00:00
|
|
|
// create the DataDeviceManager
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<DataDeviceManagerInterface> ddmi(new DataDeviceManagerInterface(m_display));
|
|
|
|
QSignalSpy ddiCreatedSpy(ddmi.get(), &DataDeviceManagerInterface::dataDeviceCreated);
|
2020-10-02 14:22:59 +00:00
|
|
|
m_seatInterface->setHasKeyboard(true);
|
2016-10-24 09:05:04 +00:00
|
|
|
|
|
|
|
// create a second Wayland client connection to use it for setSelection
|
2022-11-08 21:15:17 +00:00
|
|
|
auto c = new KWayland::Client::ConnectionThread;
|
|
|
|
QSignalSpy connectedSpy(c, &KWayland::Client::ConnectionThread::connected);
|
2016-10-24 09:05:04 +00:00
|
|
|
c->setSocketName(s_socketName);
|
|
|
|
|
|
|
|
auto thread = new QThread(this);
|
|
|
|
c->moveToThread(thread);
|
|
|
|
thread->start();
|
|
|
|
|
|
|
|
c->initConnection();
|
|
|
|
QVERIFY(connectedSpy.wait());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::EventQueue> queue(new KWayland::Client::EventQueue);
|
2016-10-24 09:05:04 +00:00
|
|
|
queue->setup(c);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Registry> registry(new KWayland::Client::Registry);
|
|
|
|
QSignalSpy interfacesAnnouncedSpy(registry.get(), &KWayland::Client::Registry::interfacesAnnounced);
|
2022-08-01 21:29:02 +00:00
|
|
|
registry->setEventQueue(queue.get());
|
2016-10-24 09:05:04 +00:00
|
|
|
registry->create(c);
|
|
|
|
QVERIFY(registry->isValid());
|
|
|
|
registry->setup();
|
|
|
|
|
|
|
|
QVERIFY(interfacesAnnouncedSpy.wait());
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Seat> seat(
|
|
|
|
registry->createSeat(registry->interface(KWayland::Client::Registry::Interface::Seat).name, registry->interface(KWayland::Client::Registry::Interface::Seat).version));
|
2016-10-24 09:05:04 +00:00
|
|
|
QVERIFY(seat->isValid());
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::DataDeviceManager> ddm1(registry->createDataDeviceManager(registry->interface(KWayland::Client::Registry::Interface::DataDeviceManager).name,
|
|
|
|
registry->interface(KWayland::Client::Registry::Interface::DataDeviceManager).version));
|
2016-10-24 09:05:04 +00:00
|
|
|
QVERIFY(ddm1->isValid());
|
|
|
|
|
|
|
|
// now create our first datadevice
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::DataDevice> dd1(ddm1->getDataDevice(seat.get()));
|
2016-10-24 09:05:04 +00:00
|
|
|
QVERIFY(ddiCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto ddi = ddiCreatedSpy.first().first().value<DataDeviceInterface *>();
|
2016-10-24 09:05:04 +00:00
|
|
|
QVERIFY(ddi);
|
2020-05-18 13:43:38 +00:00
|
|
|
m_seatInterface->setSelection(ddi->selection());
|
2016-10-24 09:05:04 +00:00
|
|
|
|
|
|
|
// switch to other client
|
|
|
|
// create a surface and pass it keyboard focus
|
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-10-24 09:05:04 +00:00
|
|
|
QVERIFY(surface->isValid());
|
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto serverSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface *>();
|
2016-10-24 09:05:04 +00:00
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
|
|
|
QCOMPARE(m_seatInterface->focusedKeyboardSurface(), serverSurface);
|
|
|
|
|
|
|
|
// now create a DataDevice
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Registry registry2;
|
|
|
|
QSignalSpy dataDeviceManagerSpy(®istry2, &KWayland::Client::Registry::dataDeviceManagerAnnounced);
|
2016-10-24 09:05:04 +00:00
|
|
|
registry2.setEventQueue(m_queue);
|
|
|
|
registry2.create(m_connection->display());
|
|
|
|
QVERIFY(registry2.isValid());
|
|
|
|
registry2.setup();
|
|
|
|
|
|
|
|
QVERIFY(dataDeviceManagerSpy.wait());
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::DataDeviceManager> ddm(
|
2021-08-29 05:11:06 +00:00
|
|
|
registry2.createDataDeviceManager(dataDeviceManagerSpy.first().first().value<quint32>(), dataDeviceManagerSpy.first().last().value<quint32>()));
|
2016-10-24 09:05:04 +00:00
|
|
|
QVERIFY(ddm->isValid());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::DataDevice> dd(ddm->getDataDevice(m_seat));
|
2016-10-24 09:05:04 +00:00
|
|
|
QVERIFY(dd->isValid());
|
|
|
|
QVERIFY(ddiCreatedSpy.wait());
|
|
|
|
|
2016-10-24 09:17:36 +00:00
|
|
|
// unset surface and set again
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(nullptr);
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
|
|
|
|
2016-10-24 09:05:04 +00:00
|
|
|
// and delete the connection thread again
|
|
|
|
dd1.reset();
|
|
|
|
ddm1.reset();
|
|
|
|
seat.reset();
|
|
|
|
registry.reset();
|
|
|
|
queue.reset();
|
|
|
|
c->deleteLater();
|
|
|
|
thread->quit();
|
|
|
|
thread->wait();
|
|
|
|
delete thread;
|
|
|
|
}
|
|
|
|
|
2015-03-25 12:31:38 +00:00
|
|
|
void TestWaylandSeat::testTouch()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2015-03-25 12:31:38 +00:00
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy touchSpy(m_seat, &KWayland::Client::Seat::hasTouchChanged);
|
2015-03-25 12:31:38 +00:00
|
|
|
m_seatInterface->setHasTouch(true);
|
|
|
|
QVERIFY(touchSpy.wait());
|
|
|
|
|
|
|
|
// create the surface
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &KWin::CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Surface *s = m_compositor->createSurface(m_compositor);
|
2015-03-25 12:31:38 +00:00
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
SurfaceInterface *serverSurface = surfaceCreatedSpy.first().first().value<KWin::SurfaceInterface *>();
|
2015-03-25 12:31:38 +00:00
|
|
|
QVERIFY(serverSurface);
|
|
|
|
|
|
|
|
m_seatInterface->setFocusedTouchSurface(serverSurface);
|
|
|
|
// no keyboard yet
|
|
|
|
QCOMPARE(m_seatInterface->focusedTouchSurface(), serverSurface);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Touch *touch = m_seat->createTouch(m_seat);
|
2015-03-25 12:31:38 +00:00
|
|
|
QVERIFY(touch->isValid());
|
2021-02-12 23:53:06 +00:00
|
|
|
|
|
|
|
// Process wl_touch bind request.
|
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
QCoreApplication::processEvents();
|
2015-03-25 12:31:38 +00:00
|
|
|
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy sequenceStartedSpy(touch, &KWayland::Client::Touch::sequenceStarted);
|
|
|
|
QSignalSpy sequenceEndedSpy(touch, &KWayland::Client::Touch::sequenceEnded);
|
|
|
|
QSignalSpy sequenceCanceledSpy(touch, &KWayland::Client::Touch::sequenceCanceled);
|
|
|
|
QSignalSpy frameEndedSpy(touch, &KWayland::Client::Touch::frameEnded);
|
|
|
|
QSignalSpy pointAddedSpy(touch, &KWayland::Client::Touch::pointAdded);
|
|
|
|
QSignalSpy pointMovedSpy(touch, &KWayland::Client::Touch::pointMoved);
|
|
|
|
QSignalSpy pointRemovedSpy(touch, &KWayland::Client::Touch::pointRemoved);
|
2015-03-25 12:31:38 +00:00
|
|
|
|
2022-12-21 00:55:20 +00:00
|
|
|
std::chrono::milliseconds timestamp(1);
|
|
|
|
|
2015-03-25 12:31:38 +00:00
|
|
|
// try a few things
|
|
|
|
m_seatInterface->setFocusedTouchSurfacePosition(QPointF(10, 20));
|
|
|
|
QCOMPARE(m_seatInterface->focusedTouchSurfacePosition(), QPointF(10, 20));
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyTouchDown(0, QPointF(15, 26));
|
2015-03-25 12:31:38 +00:00
|
|
|
QVERIFY(sequenceStartedSpy.wait());
|
|
|
|
QCOMPARE(sequenceStartedSpy.count(), 1);
|
|
|
|
QCOMPARE(sequenceEndedSpy.count(), 0);
|
|
|
|
QCOMPARE(sequenceCanceledSpy.count(), 0);
|
|
|
|
QCOMPARE(frameEndedSpy.count(), 0);
|
|
|
|
QCOMPARE(pointAddedSpy.count(), 0);
|
|
|
|
QCOMPARE(pointMovedSpy.count(), 0);
|
|
|
|
QCOMPARE(pointRemovedSpy.count(), 0);
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::TouchPoint *tp = sequenceStartedSpy.first().first().value<KWayland::Client::TouchPoint *>();
|
2015-03-25 12:31:38 +00:00
|
|
|
QVERIFY(tp);
|
|
|
|
QCOMPARE(tp->downSerial(), m_seatInterface->display()->serial());
|
|
|
|
QCOMPARE(tp->id(), 0);
|
|
|
|
QVERIFY(tp->isDown());
|
|
|
|
QCOMPARE(tp->position(), QPointF(5, 6));
|
|
|
|
QCOMPARE(tp->positions().size(), 1);
|
|
|
|
QCOMPARE(tp->time(), 1u);
|
|
|
|
QCOMPARE(tp->timestamps().count(), 1);
|
|
|
|
QCOMPARE(tp->upSerial(), 0u);
|
|
|
|
QCOMPARE(tp->surface().data(), s);
|
|
|
|
QCOMPARE(touch->sequence().count(), 1);
|
|
|
|
QCOMPARE(touch->sequence().first(), tp);
|
|
|
|
|
|
|
|
// let's end the frame
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyTouchFrame();
|
2015-03-25 12:31:38 +00:00
|
|
|
QVERIFY(frameEndedSpy.wait());
|
|
|
|
QCOMPARE(frameEndedSpy.count(), 1);
|
|
|
|
|
|
|
|
// move the one point
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyTouchMotion(0, QPointF(10, 20));
|
|
|
|
m_seatInterface->notifyTouchFrame();
|
2015-03-25 12:31:38 +00:00
|
|
|
QVERIFY(frameEndedSpy.wait());
|
|
|
|
QCOMPARE(sequenceStartedSpy.count(), 1);
|
|
|
|
QCOMPARE(sequenceEndedSpy.count(), 0);
|
|
|
|
QCOMPARE(sequenceCanceledSpy.count(), 0);
|
|
|
|
QCOMPARE(frameEndedSpy.count(), 2);
|
|
|
|
QCOMPARE(pointAddedSpy.count(), 0);
|
|
|
|
QCOMPARE(pointMovedSpy.count(), 1);
|
|
|
|
QCOMPARE(pointRemovedSpy.count(), 0);
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(pointMovedSpy.first().first().value<KWayland::Client::TouchPoint *>(), tp);
|
2015-03-25 12:31:38 +00:00
|
|
|
|
|
|
|
QCOMPARE(tp->id(), 0);
|
|
|
|
QVERIFY(tp->isDown());
|
|
|
|
QCOMPARE(tp->position(), QPointF(0, 0));
|
|
|
|
QCOMPARE(tp->positions().size(), 2);
|
|
|
|
QCOMPARE(tp->time(), 2u);
|
|
|
|
QCOMPARE(tp->timestamps().count(), 2);
|
|
|
|
QCOMPARE(tp->upSerial(), 0u);
|
|
|
|
QCOMPARE(tp->surface().data(), s);
|
|
|
|
|
|
|
|
// add onther point
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyTouchDown(1, QPointF(15, 26));
|
|
|
|
m_seatInterface->notifyTouchFrame();
|
2015-03-25 12:31:38 +00:00
|
|
|
QVERIFY(frameEndedSpy.wait());
|
|
|
|
QCOMPARE(sequenceStartedSpy.count(), 1);
|
|
|
|
QCOMPARE(sequenceEndedSpy.count(), 0);
|
|
|
|
QCOMPARE(sequenceCanceledSpy.count(), 0);
|
|
|
|
QCOMPARE(frameEndedSpy.count(), 3);
|
|
|
|
QCOMPARE(pointAddedSpy.count(), 1);
|
|
|
|
QCOMPARE(pointMovedSpy.count(), 1);
|
|
|
|
QCOMPARE(pointRemovedSpy.count(), 0);
|
|
|
|
QCOMPARE(touch->sequence().count(), 2);
|
|
|
|
QCOMPARE(touch->sequence().first(), tp);
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::TouchPoint *tp2 = pointAddedSpy.first().first().value<KWayland::Client::TouchPoint *>();
|
2015-03-25 12:31:38 +00:00
|
|
|
QVERIFY(tp2);
|
|
|
|
QCOMPARE(touch->sequence().last(), tp2);
|
|
|
|
QCOMPARE(tp2->id(), 1);
|
|
|
|
QVERIFY(tp2->isDown());
|
|
|
|
QCOMPARE(tp2->position(), QPointF(5, 6));
|
|
|
|
QCOMPARE(tp2->positions().size(), 1);
|
|
|
|
QCOMPARE(tp2->time(), 3u);
|
|
|
|
QCOMPARE(tp2->timestamps().count(), 1);
|
|
|
|
QCOMPARE(tp2->upSerial(), 0u);
|
|
|
|
QCOMPARE(tp2->surface().data(), s);
|
|
|
|
|
|
|
|
// send it an up
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyTouchUp(1);
|
|
|
|
m_seatInterface->notifyTouchFrame();
|
2015-03-25 12:31:38 +00:00
|
|
|
QVERIFY(frameEndedSpy.wait());
|
|
|
|
QCOMPARE(sequenceStartedSpy.count(), 1);
|
|
|
|
QCOMPARE(sequenceEndedSpy.count(), 0);
|
|
|
|
QCOMPARE(sequenceCanceledSpy.count(), 0);
|
|
|
|
QCOMPARE(frameEndedSpy.count(), 4);
|
|
|
|
QCOMPARE(pointAddedSpy.count(), 1);
|
|
|
|
QCOMPARE(pointMovedSpy.count(), 1);
|
|
|
|
QCOMPARE(pointRemovedSpy.count(), 1);
|
2022-11-08 21:15:17 +00:00
|
|
|
QCOMPARE(pointRemovedSpy.first().first().value<KWayland::Client::TouchPoint *>(), tp2);
|
2015-03-25 12:31:38 +00:00
|
|
|
QCOMPARE(tp2->id(), 1);
|
|
|
|
QVERIFY(!tp2->isDown());
|
|
|
|
QCOMPARE(tp2->position(), QPointF(5, 6));
|
|
|
|
QCOMPARE(tp2->positions().size(), 1);
|
|
|
|
QCOMPARE(tp2->time(), 4u);
|
|
|
|
QCOMPARE(tp2->timestamps().count(), 2);
|
|
|
|
QCOMPARE(tp2->upSerial(), m_seatInterface->display()->serial());
|
|
|
|
QCOMPARE(tp2->surface().data(), s);
|
|
|
|
|
|
|
|
// send another down and up
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyTouchDown(1, QPointF(15, 26));
|
|
|
|
m_seatInterface->notifyTouchFrame();
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyTouchUp(1);
|
2015-03-25 12:31:38 +00:00
|
|
|
// and send an up for the first point
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyTouchUp(0);
|
|
|
|
m_seatInterface->notifyTouchFrame();
|
2015-03-25 12:31:38 +00:00
|
|
|
QVERIFY(frameEndedSpy.wait());
|
|
|
|
QCOMPARE(sequenceStartedSpy.count(), 1);
|
|
|
|
QCOMPARE(sequenceEndedSpy.count(), 1);
|
|
|
|
QCOMPARE(sequenceCanceledSpy.count(), 0);
|
|
|
|
QCOMPARE(frameEndedSpy.count(), 6);
|
|
|
|
QCOMPARE(pointAddedSpy.count(), 2);
|
|
|
|
QCOMPARE(pointMovedSpy.count(), 1);
|
|
|
|
QCOMPARE(pointRemovedSpy.count(), 3);
|
|
|
|
QCOMPARE(touch->sequence().count(), 3);
|
|
|
|
QVERIFY(!touch->sequence().at(0)->isDown());
|
|
|
|
QVERIFY(!touch->sequence().at(1)->isDown());
|
|
|
|
QVERIFY(!touch->sequence().at(2)->isDown());
|
|
|
|
QVERIFY(!m_seatInterface->isTouchSequence());
|
|
|
|
|
|
|
|
// try cancel
|
2015-03-25 12:46:29 +00:00
|
|
|
m_seatInterface->setFocusedTouchSurface(serverSurface, QPointF(15, 26));
|
2022-12-21 00:55:20 +00:00
|
|
|
m_seatInterface->setTimestamp(timestamp++);
|
2021-03-11 08:24:47 +00:00
|
|
|
m_seatInterface->notifyTouchDown(0, QPointF(15, 26));
|
|
|
|
m_seatInterface->notifyTouchFrame();
|
|
|
|
m_seatInterface->notifyTouchCancel();
|
2015-03-25 12:31:38 +00:00
|
|
|
QVERIFY(sequenceCanceledSpy.wait());
|
|
|
|
QCOMPARE(sequenceStartedSpy.count(), 2);
|
|
|
|
QCOMPARE(sequenceEndedSpy.count(), 1);
|
|
|
|
QCOMPARE(sequenceCanceledSpy.count(), 1);
|
|
|
|
QCOMPARE(frameEndedSpy.count(), 7);
|
|
|
|
QCOMPARE(pointAddedSpy.count(), 2);
|
|
|
|
QCOMPARE(pointMovedSpy.count(), 1);
|
|
|
|
QCOMPARE(pointRemovedSpy.count(), 3);
|
2015-03-25 12:46:29 +00:00
|
|
|
QCOMPARE(touch->sequence().first()->position(), QPointF(0, 0));
|
2016-05-19 13:17:07 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 13:58:52 +00:00
|
|
|
void TestWaylandSeat::testKeymap()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2020-03-19 13:58:52 +00:00
|
|
|
|
|
|
|
m_seatInterface->setHasKeyboard(true);
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy keyboardChangedSpy(m_seat, &KWayland::Client::Seat::hasKeyboardChanged);
|
2020-03-19 13:58:52 +00:00
|
|
|
QVERIFY(keyboardChangedSpy.wait());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Keyboard> keyboard(m_seat->createKeyboard());
|
2020-10-02 14:22:59 +00:00
|
|
|
|
|
|
|
// create surface
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy surfaceCreatedSpy(m_compositorInterface, &KWin::CompositorInterface::surfaceCreated);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2020-10-02 14:22:59 +00:00
|
|
|
QVERIFY(surface->isValid());
|
|
|
|
QVERIFY(surfaceCreatedSpy.wait());
|
2021-08-29 05:11:06 +00:00
|
|
|
auto serverSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface *>();
|
2020-10-02 14:22:59 +00:00
|
|
|
QVERIFY(!m_seatInterface->selection());
|
|
|
|
m_seatInterface->setFocusedKeyboardSurface(serverSurface);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy keymapChangedSpy(keyboard.get(), &KWayland::Client::Keyboard::keymapChanged);
|
2020-03-19 13:58:52 +00:00
|
|
|
|
2020-11-06 04:33:47 +00:00
|
|
|
m_seatInterface->keyboard()->setKeymap(QByteArrayLiteral("foo"));
|
2020-03-19 13:58:52 +00:00
|
|
|
QVERIFY(keymapChangedSpy.wait());
|
|
|
|
int fd = keymapChangedSpy.first().first().toInt();
|
|
|
|
QVERIFY(fd != -1);
|
2022-08-16 14:04:10 +00:00
|
|
|
// Account for null terminator.
|
|
|
|
QCOMPARE(keymapChangedSpy.first().last().value<quint32>(), 4u);
|
2020-03-19 13:58:52 +00:00
|
|
|
QFile file;
|
|
|
|
QVERIFY(file.open(fd, QIODevice::ReadOnly));
|
2021-08-29 05:11:06 +00:00
|
|
|
const char *address = reinterpret_cast<char *>(file.map(0, keymapChangedSpy.first().last().value<quint32>()));
|
2020-03-19 13:58:52 +00:00
|
|
|
QVERIFY(address);
|
|
|
|
QCOMPARE(qstrcmp(address, "foo"), 0);
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
// change the keymap
|
|
|
|
keymapChangedSpy.clear();
|
2020-11-06 04:33:47 +00:00
|
|
|
m_seatInterface->keyboard()->setKeymap(QByteArrayLiteral("bar"));
|
2020-03-19 13:58:52 +00:00
|
|
|
QVERIFY(keymapChangedSpy.wait());
|
|
|
|
fd = keymapChangedSpy.first().first().toInt();
|
|
|
|
QVERIFY(fd != -1);
|
2022-08-16 14:04:10 +00:00
|
|
|
// Account for null terminator.
|
|
|
|
QCOMPARE(keymapChangedSpy.first().last().value<quint32>(), 4u);
|
2021-08-29 05:11:06 +00:00
|
|
|
QVERIFY(file.open(fd, QIODevice::ReadWrite));
|
|
|
|
address = reinterpret_cast<char *>(file.map(0, keymapChangedSpy.first().last().value<quint32>()));
|
2020-03-19 13:58:52 +00:00
|
|
|
QVERIFY(address);
|
|
|
|
QCOMPARE(qstrcmp(address, "bar"), 0);
|
|
|
|
}
|
|
|
|
|
2014-09-23 10:00:17 +00:00
|
|
|
QTEST_GUILESS_MAIN(TestWaylandSeat)
|
2014-09-02 07:34:31 +00:00
|
|
|
#include "test_wayland_seat.moc"
|