diff --git a/autotests/libinput/touch_event_test.cpp b/autotests/libinput/touch_event_test.cpp --- a/autotests/libinput/touch_event_test.cpp +++ b/autotests/libinput/touch_event_test.cpp @@ -40,6 +40,7 @@ void testType(); void testAbsoluteMotion_data(); void testAbsoluteMotion(); + void testNoAssignedSlot(); private: libinput_device *m_nativeDevice = nullptr; @@ -126,5 +127,19 @@ QCOMPARE(te->absolutePos(QSize(1280, 1024)), QPointF(640, 512)); } +void TestLibinputTouchEvent::testNoAssignedSlot() +{ + // this test verifies that touch events without an assigned slot get id == 0 + libinput_event_touch *touchEvent = new libinput_event_touch; + touchEvent->type = LIBINPUT_EVENT_TOUCH_UP; + touchEvent->device = m_nativeDevice; + // touch events without an assigned slot have slot == -1 + touchEvent->slot = -1; + + QScopedPointer event(Event::create(touchEvent)); + QVERIFY(dynamic_cast(event.data())); + QCOMPARE(dynamic_cast(event.data())->id(), 0); +} + QTEST_GUILESS_MAIN(TestLibinputTouchEvent) #include "touch_event_test.moc" diff --git a/libinput/events.cpp b/libinput/events.cpp --- a/libinput/events.cpp +++ b/libinput/events.cpp @@ -225,7 +225,10 @@ qint32 TouchEvent::id() const { Q_ASSERT(type() != LIBINPUT_EVENT_TOUCH_CANCEL && type() != LIBINPUT_EVENT_TOUCH_FRAME); - return libinput_event_touch_get_slot(m_touchEvent); + + const qint32 slot = libinput_event_touch_get_slot(m_touchEvent); + + return slot == -1 ? 0 : slot; } GestureEvent::GestureEvent(libinput_event *event, libinput_event_type type)