From 93ee2f6815792d04213833a1fc9f12712a0fd8e5 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Sun, 17 Jan 2021 23:18:08 +0100 Subject: [PATCH] Add test for TouchInputRedirection::m_touches --- autotests/integration/touch_input_test.cpp | 21 ++++++++++++++++++++- input.cpp | 10 ++++++++++ input.h | 6 ++++++ platform.cpp | 16 ++++++++++++++++ platform.h | 2 ++ touch_input.h | 4 ++++ 6 files changed, 58 insertions(+), 1 deletion(-) diff --git a/autotests/integration/touch_input_test.cpp b/autotests/integration/touch_input_test.cpp index b686d93fd9..3031d6de97 100644 --- a/autotests/integration/touch_input_test.cpp +++ b/autotests/integration/touch_input_test.cpp @@ -38,6 +38,7 @@ private Q_SLOTS: void testMultipleTouchPoints(); void testCancel(); void testTouchMouseAction(); + void testTouchPointCount(); private: AbstractClient *showWindow(bool decorated = false); @@ -263,7 +264,25 @@ void TouchInputTest::testTouchMouseAction() QCOMPARE(sequenceStartedSpy.count(), 1); // cleanup - kwinApp()->platform()->touchCancel(); + kwinApp()->platform()->cancelTouchSequence(); +} + +void TouchInputTest::testTouchPointCount() +{ + QCOMPARE(kwinApp()->platform()->touchPointCount(), 0); + quint32 timestamp = 1; + kwinApp()->platform()->touchDown(0, QPointF(125, 125), timestamp++); + kwinApp()->platform()->touchDown(1, QPointF(125, 125), timestamp++); + kwinApp()->platform()->touchDown(2, QPointF(125, 125), timestamp++); + QCOMPARE(kwinApp()->platform()->touchPointCount(), 3); + + kwinApp()->platform()->touchUp(1, timestamp++); + QCOMPARE(kwinApp()->platform()->touchPointCount(), 2); + + kwinApp()->platform()->cancelTouchSequence(); + QCOMPARE(kwinApp()->platform()->touchPointCount(), 1); + kwinApp()->platform()->cancelTouchSequence(); + QCOMPARE(kwinApp()->platform()->touchPointCount(), 0); } } diff --git a/input.cpp b/input.cpp index 2561e17709..49d1d44a8b 100644 --- a/input.cpp +++ b/input.cpp @@ -2517,6 +2517,11 @@ void InputRedirection::processTouchMotion(qint32 id, const QPointF &pos, quint32 m_touch->processMotion(id, pos, time); } +void InputRedirection::cancelTouchSequence() +{ + m_touch->processCancel(); +} + void InputRedirection::cancelTouch() { m_touch->cancel(); @@ -2527,6 +2532,11 @@ void InputRedirection::touchFrame() m_touch->frame(); } +int InputRedirection::touchPointCount() +{ + return m_touch->touchPointCount(); +} + Qt::MouseButtons InputRedirection::qtButtonStates() const { return m_pointer->buttons(); diff --git a/input.h b/input.h index 786453dd59..6716b1060c 100644 --- a/input.h +++ b/input.h @@ -168,8 +168,14 @@ public: void processTouchDown(qint32 id, const QPointF &pos, quint32 time); void processTouchUp(qint32 id, quint32 time); void processTouchMotion(qint32 id, const QPointF &pos, quint32 time); + /** + * triggers the same code path as LIBINPUT_TOUCH_CANCEL_EVENT. + * Only intended for autotests + */ + void cancelTouchSequence(); void cancelTouch(); void touchFrame(); + int touchPointCount(); bool supportsPointerWarping() const; void warpPointer(const QPointF &pos); diff --git a/platform.cpp b/platform.cpp index a5a12fdbc5..971e03eb5f 100644 --- a/platform.cpp +++ b/platform.cpp @@ -311,6 +311,14 @@ void Platform::pointerButtonReleased(quint32 button, quint32 time) input()->processPointerButton(button, InputRedirection::PointerButtonReleased, time); } +int Platform::touchPointCount() +{ + if (!input()) { + return 0; + } + return input()->touchPointCount(); +} + void Platform::pointerMotion(const QPointF &position, quint32 time) { if (!input()) { @@ -319,6 +327,14 @@ void Platform::pointerMotion(const QPointF &position, quint32 time) input()->processPointerMotion(position, time); } +void Platform::cancelTouchSequence() +{ + if (!input()) { + return; + } + input()->cancelTouchSequence(); +} + void Platform::touchCancel() { if (!input()) { diff --git a/platform.h b/platform.h index 7274e5879f..e4eea932fb 100644 --- a/platform.h +++ b/platform.h @@ -483,8 +483,10 @@ public Q_SLOTS: void touchDown(qint32 id, const QPointF &pos, quint32 time); void touchUp(qint32 id, quint32 time); void touchMotion(qint32 id, const QPointF &pos, quint32 time); + void cancelTouchSequence(); void touchCancel(); void touchFrame(); + int touchPointCount(); void processSwipeGestureBegin(int fingerCount, quint32 time); void processSwipeGestureUpdate(const QSizeF &delta, quint32 time); diff --git a/touch_input.h b/touch_input.h index d0d67e7090..bc30aade88 100644 --- a/touch_input.h +++ b/touch_input.h @@ -71,6 +71,10 @@ public: return m_lastPosition; } + int touchPointCount() const { + return m_touches; + } + private: void cleanupInternalWindow(QWindow *old, QWindow *now) override; void cleanupDecoration(Decoration::DecoratedClientImpl *old, Decoration::DecoratedClientImpl *now) override;