on xenial help sign in
[TGA] Ignore touch events when in the rejected state
c36c2dcRatchanan Srirattanamet
plugins/Ubuntu/Gestures/TouchGestureArea.cpp+6
@@ -328,6 +328,12 @@ void TouchGestureArea::touchEvent_rejected(QTouchEvent *event)
328 }
328 }
329 }
329 }
330 }
330 }
331+
332+ // If this event is a new touch, ignore it and let the item below have it.
333+ // We won't recognize any new touch until the whole current gesture is done
334+ // i.e. we're in WaitingForTouch state.
335+ // And even if it isn't, just ignore it anyway; we don't care about it.
336+ event->ignore();
331}
337}
332
338
333void TouchGestureArea::unownedTouchEvent(QTouchEvent *unownedTouchEvent)
339void TouchGestureArea::unownedTouchEvent(QTouchEvent *unownedTouchEvent)
tests/plugins/Ubuntu/Gestures/tst_TouchGestureArea.cpp+30
@@ -45,6 +45,7 @@ private Q_SLOTS:
45 void releaseAndPressRecognisedGestureDoesNotRejectForPeriod();
45 void releaseAndPressRecognisedGestureDoesNotRejectForPeriod();
46 void topAreaReceivesOwnershipFirstWithEqualPoints();
46 void topAreaReceivesOwnershipFirstWithEqualPoints();
47 void topAreaReceivesOwnershipFirstWithMorePoints();
47 void topAreaReceivesOwnershipFirstWithMorePoints();
48+ void newTouchAfterRejectionIsPassedThrough();
48
49
49private:
50private:
50 void initGestureComponent(TouchGestureArea *area);
51 void initGestureComponent(TouchGestureArea *area);
@@ -265,6 +266,35 @@ void tst_TouchGestureArea::topAreaReceivesOwnershipFirstWithMorePoints()
265 QCOMPARE((int)m_gestureMiddle->status(), (int)TouchGestureArea::Rejected);
266 QCOMPARE((int)m_gestureMiddle->status(), (int)TouchGestureArea::Rejected);
266}
267}
267
268
269+void tst_TouchGestureArea::newTouchAfterRejectionIsPassedThrough() {
270+ m_gestureTop->setEnabled(true);
271+ m_gestureTop->setMinimumTouchPoints(2);
272+ m_gestureTop->setMaximumTouchPoints(2);
273+ m_gestureTop->setRecognitionPeriod(30);
274+
275+ m_gestureBottom->setEnabled(true);
276+ m_gestureBottom->setMinimumTouchPoints(2);
277+ m_gestureBottom->setMaximumTouchPoints(2);
278+ m_gestureBottom->setRecognitionPeriod(50);
279+
280+ QPointF touchPoint = calculateInitialTouchPos(m_gestureBottom);
281+
282+ QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint());
283+ QCOMPARE((int)m_gestureTop->status(), (int)TouchGestureArea::Undecided);
284+ QCOMPARE((int)m_gestureBottom->status(), (int)TouchGestureArea::Undecided);
285+
286+ passTime(40); // 10ms after top item's recognition period.
287+ QCOMPARE((int)m_gestureTop->status(), (int)TouchGestureArea::Rejected);
288+ QCOMPARE((int)m_gestureBottom->status(), (int)TouchGestureArea::Undecided);
289+
290+ // If the top item passes the event down the line, now the bottom one will
291+ // recognize the gesture.
292+ QTest::touchEvent(m_view, m_device).stationary(0)
293+ .press(1, touchPoint.toPoint());
294+ QCOMPARE((int)m_gestureTop->status(), (int)TouchGestureArea::Rejected);
295+ QCOMPARE((int)m_gestureBottom->status(), (int)TouchGestureArea::Recognized);
296+}
297+
268QTEST_MAIN(tst_TouchGestureArea)
298QTEST_MAIN(tst_TouchGestureArea)
269
299
270#include "tst_TouchGestureArea.moc"
300#include "tst_TouchGestureArea.moc"