Commit 71ffe8a0 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

Simplify SeatInterface::touchDown() api

Currently, the compositor is supposed to pass the position of the touch
point to the touchDown() function and in return get its unique global
id. The id can be be passed to subsequent touchMotion() and touchUp().

The compositor is responsible for mapping between libinput slots and
internal touch point ids.

The mapping step is unnecessary and adds in some complexity as the input
code now has to keep the mapping table up to date.

This change makes the touch API more convenient to use by making
relevant functions take touch ids that are assigned by the compositor.
Usually, compositor would use libinput_event_touch_get_seat_slot() to
get touch ids.

It also allows introducing event objects that can be useful later in the
future.
parent 7a1993af
Pipeline #51147 passed with stage
in 7 minutes and 12 seconds
......@@ -305,7 +305,8 @@ void TestDragAndDrop::testTouchDragAndDrop()
QVERIFY(pointAddedSpy.isValid());
m_seatInterface->setFocusedTouchSurface(serverSurface);
m_seatInterface->setTimestamp(2);
const qint32 touchId = m_seatInterface->touchDown(QPointF(50,50));
const qint32 touchId = 0;
m_seatInterface->touchDown(touchId, QPointF(50,50));
QVERIFY(sequenceStartedSpy.wait());
QScopedPointer<TouchPoint> tp(sequenceStartedSpy.first().at(0).value<TouchPoint*>());
......
......@@ -2000,7 +2000,7 @@ void TestWaylandSeat::testTouch()
m_seatInterface->setFocusedTouchSurfacePosition(QPointF(10, 20));
QCOMPARE(m_seatInterface->focusedTouchSurfacePosition(), QPointF(10, 20));
m_seatInterface->setTimestamp(1);
QCOMPARE(m_seatInterface->touchDown(QPointF(15, 26)), 0);
m_seatInterface->touchDown(0, QPointF(15, 26));
QVERIFY(sequenceStartedSpy.wait());
QCOMPARE(sequenceStartedSpy.count(), 1);
QCOMPARE(sequenceEndedSpy.count(), 0);
......@@ -2053,7 +2053,7 @@ void TestWaylandSeat::testTouch()
// add onther point
m_seatInterface->setTimestamp(3);
QCOMPARE(m_seatInterface->touchDown(QPointF(15, 26)), 1);
m_seatInterface->touchDown(1, QPointF(15, 26));
m_seatInterface->touchFrame();
QVERIFY(frameEndedSpy.wait());
QCOMPARE(sequenceStartedSpy.count(), 1);
......@@ -2101,7 +2101,7 @@ void TestWaylandSeat::testTouch()
// send another down and up
m_seatInterface->setTimestamp(5);
QCOMPARE(m_seatInterface->touchDown(QPointF(15, 26)), 1);
m_seatInterface->touchDown(1, QPointF(15, 26));
m_seatInterface->touchFrame();
m_seatInterface->setTimestamp(6);
m_seatInterface->touchUp(1);
......@@ -2125,7 +2125,7 @@ void TestWaylandSeat::testTouch()
// try cancel
m_seatInterface->setFocusedTouchSurface(serverSurface, QPointF(15, 26));
m_seatInterface->setTimestamp(7);
QCOMPARE(m_seatInterface->touchDown(QPointF(15, 26)), 0);
m_seatInterface->touchDown(0, QPointF(15, 26));
m_seatInterface->touchFrame();
m_seatInterface->cancelTouchSequence();
QVERIFY(sequenceCanceledSpy.wait());
......@@ -2151,10 +2151,10 @@ void TestWaylandSeat::testTouch()
// try to call into all the methods of the touch interface, should not crash
QCOMPARE(m_seatInterface->focusedTouch(), serverTouch);
m_seatInterface->setTimestamp(8);
QCOMPARE(m_seatInterface->touchDown(QPointF(15, 26)), 0);
m_seatInterface->touchDown(0, QPointF(15, 26));
m_seatInterface->touchFrame();
m_seatInterface->touchMove(0, QPointF(0, 0));
QCOMPARE(m_seatInterface->touchDown(QPointF(15, 26)), 1);
m_seatInterface->touchDown(1, QPointF(15, 26));
m_seatInterface->cancelTouchSequence();
QVERIFY(destroyedSpy.wait());
QCOMPARE(destroyedSpy.count(), 1);
......
......@@ -1250,10 +1250,9 @@ void SeatInterface::setFocusedTouchSurfacePosition(const QPointF &surfacePositio
d->globalTouch.focus.offset = surfacePosition;
}
qint32 SeatInterface::touchDown(const QPointF &globalPosition)
void SeatInterface::touchDown(qint32 id, const QPointF &globalPosition)
{
Q_D();
const qint32 id = d->globalTouch.ids.isEmpty() ? 0 : d->globalTouch.ids.lastKey() + 1;
const qint32 serial = display()->nextSerial();
const auto pos = globalPosition - d->globalTouch.focus.offset;
for (auto it = d->globalTouch.focus.touchs.constBegin(), end = d->globalTouch.focus.touchs.constEnd(); it != end; ++it) {
......@@ -1284,7 +1283,6 @@ qint32 SeatInterface::touchDown(const QPointF &globalPosition)
#endif
d->globalTouch.ids[id] = serial;
return id;
}
void SeatInterface::touchMove(qint32 id, const QPointF &globalPosition)
......
......@@ -567,7 +567,7 @@ public:
TouchInterface *focusedTouch() const;
void setFocusedTouchSurfacePosition(const QPointF &surfacePosition);
QPointF focusedTouchSurfacePosition() const;
qint32 touchDown(const QPointF &globalPosition);
void touchDown(qint32 id, const QPointF &globalPosition);
void touchUp(qint32 id);
void touchMove(qint32 id, const QPointF &globalPosition);
void touchFrame();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment