Client tests: Add test for a simple wl_touch tap
Change-Id: I35aec950da0ac0d10cf1fa0c4bc1f56ba232cf89 Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
This commit is contained in:
parent
0d745e8b28
commit
68bbf5fd1c
@ -67,6 +67,7 @@ private slots:
|
|||||||
|
|
||||||
// Touch tests
|
// Touch tests
|
||||||
void createsTouch();
|
void createsTouch();
|
||||||
|
void singleTap();
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_seatv5::bindsToSeat()
|
void tst_seatv5::bindsToSeat()
|
||||||
@ -387,5 +388,64 @@ void tst_seatv5::createsTouch()
|
|||||||
QCOMPOSITOR_TRY_COMPARE(touch()->resourceMap().first()->version(), 5);
|
QCOMPOSITOR_TRY_COMPARE(touch()->resourceMap().first()->version(), 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TouchWindow : public QRasterWindow {
|
||||||
|
public:
|
||||||
|
TouchWindow()
|
||||||
|
{
|
||||||
|
resize(64, 64);
|
||||||
|
show();
|
||||||
|
}
|
||||||
|
void touchEvent(QTouchEvent *event) override
|
||||||
|
{
|
||||||
|
QRasterWindow::touchEvent(event);
|
||||||
|
m_events.append(Event{event});
|
||||||
|
}
|
||||||
|
struct Event // Because I didn't find a convenient way to copy it entirely
|
||||||
|
{
|
||||||
|
explicit Event() = default;
|
||||||
|
explicit Event(const QTouchEvent *event)
|
||||||
|
: type(event->type())
|
||||||
|
, touchPointStates(event->touchPointStates())
|
||||||
|
, touchPoints(event->touchPoints())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
const QEvent::Type type{};
|
||||||
|
const Qt::TouchPointStates touchPointStates{};
|
||||||
|
const QList<QTouchEvent::TouchPoint> touchPoints;
|
||||||
|
};
|
||||||
|
QVector<Event> m_events;
|
||||||
|
};
|
||||||
|
|
||||||
|
void tst_seatv5::singleTap()
|
||||||
|
{
|
||||||
|
TouchWindow window;
|
||||||
|
QCOMPOSITOR_TRY_VERIFY(xdgSurface() && xdgSurface()->m_committedConfigureSerial);
|
||||||
|
|
||||||
|
exec([=] {
|
||||||
|
auto *t = touch();
|
||||||
|
auto *c = client();
|
||||||
|
t->sendDown(xdgToplevel()->surface(), {32, 32}, 1);
|
||||||
|
t->sendFrame(c);
|
||||||
|
t->sendUp(c, 1);
|
||||||
|
t->sendFrame(c);
|
||||||
|
});
|
||||||
|
|
||||||
|
QTRY_VERIFY(!window.m_events.empty());
|
||||||
|
{
|
||||||
|
auto e = window.m_events.takeFirst();
|
||||||
|
QCOMPARE(e.type, QEvent::TouchBegin);
|
||||||
|
QCOMPARE(e.touchPointStates, Qt::TouchPointState::TouchPointPressed);
|
||||||
|
QCOMPARE(e.touchPoints.length(), 1);
|
||||||
|
QCOMPARE(e.touchPoints.first().pos(), QPointF(32-window.frameMargins().left(), 32-window.frameMargins().top()));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto e = window.m_events.takeFirst();
|
||||||
|
QCOMPARE(e.type, QEvent::TouchEnd);
|
||||||
|
QCOMPARE(e.touchPointStates, Qt::TouchPointState::TouchPointReleased);
|
||||||
|
QCOMPARE(e.touchPoints.length(), 1);
|
||||||
|
QCOMPARE(e.touchPoints.first().pos(), QPointF(32-window.frameMargins().left(), 32-window.frameMargins().top()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QCOMPOSITOR_TEST_MAIN(tst_seatv5)
|
QCOMPOSITOR_TEST_MAIN(tst_seatv5)
|
||||||
#include "tst_seatv5.moc"
|
#include "tst_seatv5.moc"
|
||||||
|
@ -397,6 +397,40 @@ void Pointer::pointer_set_cursor(Resource *resource, uint32_t serial, wl_resourc
|
|||||||
emit setCursor(serial);
|
emit setCursor(serial);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint Touch::sendDown(Surface *surface, const QPointF &position, int id)
|
||||||
|
{
|
||||||
|
wl_fixed_t x = wl_fixed_from_double(position.x());
|
||||||
|
wl_fixed_t y = wl_fixed_from_double(position.y());
|
||||||
|
uint serial = m_seat->m_compositor->nextSerial();
|
||||||
|
auto time = m_seat->m_compositor->currentTimeMilliseconds();
|
||||||
|
wl_client *client = surface->resource()->client();
|
||||||
|
|
||||||
|
const auto touchResources = resourceMap().values(client);
|
||||||
|
for (auto *r : touchResources)
|
||||||
|
wl_touch::send_down(r->handle, serial, time, surface->resource()->handle, id, x, y);
|
||||||
|
|
||||||
|
return serial;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint Touch::sendUp(wl_client *client, int id)
|
||||||
|
{
|
||||||
|
uint serial = m_seat->m_compositor->nextSerial();
|
||||||
|
auto time = m_seat->m_compositor->currentTimeMilliseconds();
|
||||||
|
|
||||||
|
const auto touchResources = resourceMap().values(client);
|
||||||
|
for (auto *r : touchResources)
|
||||||
|
wl_touch::send_up(r->handle, serial, time, id);
|
||||||
|
|
||||||
|
return serial;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Touch::sendFrame(wl_client *client)
|
||||||
|
{
|
||||||
|
const auto touchResources = resourceMap().values(client);
|
||||||
|
for (auto *r : touchResources)
|
||||||
|
send_frame(r->handle);
|
||||||
|
}
|
||||||
|
|
||||||
uint Keyboard::sendEnter(Surface *surface)
|
uint Keyboard::sendEnter(Surface *surface)
|
||||||
{
|
{
|
||||||
auto serial = m_seat->m_compositor->nextSerial();
|
auto serial = m_seat->m_compositor->nextSerial();
|
||||||
|
@ -316,6 +316,10 @@ class Touch : public QObject, public QtWaylandServer::wl_touch
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Touch(Seat *seat) : m_seat(seat) {}
|
explicit Touch(Seat *seat) : m_seat(seat) {}
|
||||||
|
uint sendDown(Surface *surface, const QPointF &position, int id);
|
||||||
|
uint sendUp(wl_client *client, int id);
|
||||||
|
void sendFrame(wl_client *client);
|
||||||
|
|
||||||
Seat *m_seat = nullptr;
|
Seat *m_seat = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user