2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2017-03-18 10:00:30 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2017 Martin Gräßlin <mgraesslin@kde.org>
|
2017-03-18 10:00:30 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2021-02-09 18:18:36 +00:00
|
|
|
#include "gestures.h"
|
2017-03-18 10:00:30 +00:00
|
|
|
|
|
|
|
#include <QSignalSpy>
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <QTest>
|
2022-02-02 21:51:39 +00:00
|
|
|
#include <QtWidgets/qaction.h>
|
|
|
|
#include <iostream>
|
2017-03-18 10:00:30 +00:00
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
|
|
|
|
class GestureTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
2022-09-11 10:14:11 +00:00
|
|
|
void testSwipeMinFinger_data();
|
|
|
|
void testSwipeMinFinger();
|
|
|
|
void testPinchMinFinger_data();
|
|
|
|
void testPinchMinFinger();
|
|
|
|
|
|
|
|
void testSwipeMaxFinger_data();
|
|
|
|
void testSwipeMaxFinger();
|
|
|
|
void testPinchMaxFinger_data();
|
|
|
|
void testPinchMaxFinger();
|
|
|
|
|
2022-09-11 10:14:10 +00:00
|
|
|
void testSwipeDirection_data();
|
|
|
|
void testSwipeDirection();
|
|
|
|
void testPinchDirection_data();
|
|
|
|
void testPinchDirection();
|
2022-02-02 21:51:39 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// swipe only
|
2017-03-19 10:40:03 +00:00
|
|
|
void testMinimumX_data();
|
|
|
|
void testMinimumX();
|
|
|
|
void testMinimumY_data();
|
|
|
|
void testMinimumY();
|
|
|
|
void testMaximumX_data();
|
|
|
|
void testMaximumX();
|
|
|
|
void testMaximumY_data();
|
|
|
|
void testMaximumY();
|
|
|
|
void testStartGeometry();
|
2022-02-02 21:51:39 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// swipe and pinch
|
2022-09-11 10:14:11 +00:00
|
|
|
void testSetMinimumDelta();
|
|
|
|
void testMinimumDeltaReached_data();
|
|
|
|
void testMinimumDeltaReached();
|
|
|
|
void testMinimumScaleDelta();
|
2017-03-18 10:00:30 +00:00
|
|
|
void testUnregisterSwipeCancels();
|
2022-02-02 21:51:39 +00:00
|
|
|
void testUnregisterPinchCancels();
|
2017-03-18 10:00:30 +00:00
|
|
|
void testDeleteSwipeCancels();
|
|
|
|
void testSwipeCancel_data();
|
|
|
|
void testSwipeCancel();
|
|
|
|
void testSwipeUpdateTrigger_data();
|
|
|
|
void testSwipeUpdateTrigger();
|
2022-02-02 21:51:39 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// both
|
2022-09-11 10:14:11 +00:00
|
|
|
void testSwipeMinFingerStart_data();
|
|
|
|
void testSwipeMinFingerStart();
|
|
|
|
void testSwipeMaxFingerStart_data();
|
|
|
|
void testSwipeMaxFingerStart();
|
2022-02-02 21:51:39 +00:00
|
|
|
void testNotEmitCallbacksBeforeDirectionDecided();
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// swipe only
|
2017-03-19 10:40:03 +00:00
|
|
|
void testSwipeGeometryStart_data();
|
|
|
|
void testSwipeGeometryStart();
|
2017-03-18 10:00:30 +00:00
|
|
|
};
|
|
|
|
|
2022-09-11 10:14:11 +00:00
|
|
|
void GestureTest::testSwipeMinFinger_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<uint>("count");
|
|
|
|
QTest::addColumn<uint>("expectedCount");
|
|
|
|
|
|
|
|
QTest::newRow("0") << 0u << 0u;
|
|
|
|
QTest::newRow("1") << 1u << 1u;
|
|
|
|
QTest::newRow("10") << 10u << 10u;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeMinFinger()
|
|
|
|
{
|
|
|
|
SwipeGesture swipeGesture;
|
|
|
|
QCOMPARE(swipeGesture.minimumFingerCountIsRelevant(), false);
|
|
|
|
QCOMPARE(swipeGesture.minimumFingerCount(), 0u);
|
|
|
|
QFETCH(uint, count);
|
|
|
|
swipeGesture.setMinimumFingerCount(count);
|
|
|
|
QCOMPARE(swipeGesture.minimumFingerCountIsRelevant(), true);
|
|
|
|
QTEST(swipeGesture.minimumFingerCount(), "expectedCount");
|
|
|
|
swipeGesture.setMinimumFingerCount(0);
|
|
|
|
QCOMPARE(swipeGesture.minimumFingerCountIsRelevant(), true);
|
|
|
|
QCOMPARE(swipeGesture.minimumFingerCount(), 0u);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testPinchMinFinger_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<uint>("count");
|
|
|
|
QTest::addColumn<uint>("expectedCount");
|
|
|
|
|
|
|
|
QTest::newRow("0") << 0u << 0u;
|
|
|
|
QTest::newRow("1") << 1u << 1u;
|
|
|
|
QTest::newRow("10") << 10u << 10u;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testPinchMinFinger()
|
|
|
|
{
|
|
|
|
PinchGesture pinchGesture;
|
|
|
|
QCOMPARE(pinchGesture.minimumFingerCountIsRelevant(), false);
|
|
|
|
QCOMPARE(pinchGesture.minimumFingerCount(), 0u);
|
|
|
|
QFETCH(uint, count);
|
|
|
|
pinchGesture.setMinimumFingerCount(count);
|
|
|
|
QCOMPARE(pinchGesture.minimumFingerCountIsRelevant(), true);
|
|
|
|
QTEST(pinchGesture.minimumFingerCount(), "expectedCount");
|
|
|
|
pinchGesture.setMinimumFingerCount(0);
|
|
|
|
QCOMPARE(pinchGesture.minimumFingerCountIsRelevant(), true);
|
|
|
|
QCOMPARE(pinchGesture.minimumFingerCount(), 0u);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeMaxFinger_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<uint>("count");
|
|
|
|
QTest::addColumn<uint>("expectedCount");
|
|
|
|
|
|
|
|
QTest::newRow("0") << 0u << 0u;
|
|
|
|
QTest::newRow("1") << 1u << 1u;
|
|
|
|
QTest::newRow("10") << 10u << 10u;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeMaxFinger()
|
|
|
|
{
|
|
|
|
SwipeGesture gesture;
|
|
|
|
QCOMPARE(gesture.maximumFingerCountIsRelevant(), false);
|
|
|
|
QCOMPARE(gesture.maximumFingerCount(), 0u);
|
|
|
|
QFETCH(uint, count);
|
|
|
|
gesture.setMaximumFingerCount(count);
|
|
|
|
QCOMPARE(gesture.maximumFingerCountIsRelevant(), true);
|
|
|
|
QTEST(gesture.maximumFingerCount(), "expectedCount");
|
|
|
|
gesture.setMaximumFingerCount(0);
|
|
|
|
QCOMPARE(gesture.maximumFingerCountIsRelevant(), true);
|
|
|
|
QCOMPARE(gesture.maximumFingerCount(), 0u);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testPinchMaxFinger_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<uint>("count");
|
|
|
|
QTest::addColumn<uint>("expectedCount");
|
|
|
|
|
|
|
|
QTest::newRow("0") << 0u << 0u;
|
|
|
|
QTest::newRow("1") << 1u << 1u;
|
|
|
|
QTest::newRow("10") << 10u << 10u;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testPinchMaxFinger()
|
|
|
|
{
|
|
|
|
PinchGesture gesture;
|
|
|
|
QCOMPARE(gesture.maximumFingerCountIsRelevant(), false);
|
|
|
|
QCOMPARE(gesture.maximumFingerCount(), 0u);
|
|
|
|
QFETCH(uint, count);
|
|
|
|
gesture.setMaximumFingerCount(count);
|
|
|
|
QCOMPARE(gesture.maximumFingerCountIsRelevant(), true);
|
|
|
|
QTEST(gesture.maximumFingerCount(), "expectedCount");
|
|
|
|
gesture.setMaximumFingerCount(0);
|
|
|
|
QCOMPARE(gesture.maximumFingerCountIsRelevant(), true);
|
|
|
|
QCOMPARE(gesture.maximumFingerCount(), 0u);
|
|
|
|
}
|
|
|
|
|
2022-09-11 10:14:10 +00:00
|
|
|
void GestureTest::testSwipeDirection_data()
|
2022-02-02 21:51:39 +00:00
|
|
|
{
|
2022-09-11 10:14:11 +00:00
|
|
|
QTest::addColumn<KWin::SwipeGesture::Direction>("swipe_direction");
|
2022-09-11 10:13:37 +00:00
|
|
|
|
2022-09-11 10:14:11 +00:00
|
|
|
QTest::newRow("Up") << KWin::SwipeGesture::Direction::Up;
|
|
|
|
QTest::newRow("Left") << KWin::SwipeGesture::Direction::Left;
|
|
|
|
QTest::newRow("Right") << KWin::SwipeGesture::Direction::Right;
|
|
|
|
QTest::newRow("Down") << KWin::SwipeGesture::Direction::Down;
|
2017-03-18 10:00:30 +00:00
|
|
|
}
|
|
|
|
|
2022-09-11 10:14:10 +00:00
|
|
|
void GestureTest::testSwipeDirection()
|
2017-03-18 10:00:30 +00:00
|
|
|
{
|
|
|
|
SwipeGesture gesture;
|
2022-09-11 10:14:11 +00:00
|
|
|
QCOMPARE(gesture.direction(), SwipeGesture::Direction::Down);
|
|
|
|
QFETCH(KWin::SwipeGesture::Direction, swipe_direction);
|
2022-09-11 10:14:10 +00:00
|
|
|
gesture.setDirection(swipe_direction);
|
|
|
|
QCOMPARE(gesture.direction(), swipe_direction);
|
2017-03-18 10:00:30 +00:00
|
|
|
// back to down
|
2022-09-11 10:14:11 +00:00
|
|
|
gesture.setDirection(SwipeGesture::Direction::Down);
|
|
|
|
QCOMPARE(gesture.direction(), SwipeGesture::Direction::Down);
|
2017-03-18 10:00:30 +00:00
|
|
|
}
|
|
|
|
|
2022-09-11 10:14:10 +00:00
|
|
|
void GestureTest::testPinchDirection_data()
|
|
|
|
{
|
2022-09-11 10:14:11 +00:00
|
|
|
QTest::addColumn<KWin::PinchGesture::Direction>("pinch_direction");
|
2022-09-11 10:14:10 +00:00
|
|
|
|
2022-09-11 10:14:11 +00:00
|
|
|
QTest::newRow("Contracting") << KWin::PinchGesture::Direction::Contracting;
|
|
|
|
QTest::newRow("Expanding") << KWin::PinchGesture::Direction::Expanding;
|
2022-09-11 10:14:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testPinchDirection()
|
|
|
|
{
|
|
|
|
PinchGesture gesture;
|
2022-09-11 10:14:11 +00:00
|
|
|
QCOMPARE(gesture.direction(), PinchGesture::Direction::Expanding);
|
|
|
|
QFETCH(KWin::PinchGesture::Direction, pinch_direction);
|
2022-09-11 10:14:10 +00:00
|
|
|
gesture.setDirection(pinch_direction);
|
|
|
|
QCOMPARE(gesture.direction(), pinch_direction);
|
|
|
|
// back to down
|
2022-09-11 10:14:11 +00:00
|
|
|
gesture.setDirection(PinchGesture::Direction::Expanding);
|
|
|
|
QCOMPARE(gesture.direction(), PinchGesture::Direction::Expanding);
|
2022-09-11 10:14:10 +00:00
|
|
|
}
|
|
|
|
|
2017-03-19 10:40:03 +00:00
|
|
|
void GestureTest::testMinimumX_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("min");
|
|
|
|
|
|
|
|
QTest::newRow("0") << 0;
|
|
|
|
QTest::newRow("-1") << -1;
|
|
|
|
QTest::newRow("1") << 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMinimumX()
|
|
|
|
{
|
|
|
|
SwipeGesture gesture;
|
|
|
|
QCOMPARE(gesture.minimumX(), 0);
|
|
|
|
QCOMPARE(gesture.minimumXIsRelevant(), false);
|
|
|
|
QFETCH(int, min);
|
|
|
|
gesture.setMinimumX(min);
|
|
|
|
QCOMPARE(gesture.minimumX(), min);
|
|
|
|
QCOMPARE(gesture.minimumXIsRelevant(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMinimumY_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("min");
|
|
|
|
|
|
|
|
QTest::newRow("0") << 0;
|
|
|
|
QTest::newRow("-1") << -1;
|
|
|
|
QTest::newRow("1") << 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMinimumY()
|
|
|
|
{
|
|
|
|
SwipeGesture gesture;
|
|
|
|
QCOMPARE(gesture.minimumY(), 0);
|
|
|
|
QCOMPARE(gesture.minimumYIsRelevant(), false);
|
|
|
|
QFETCH(int, min);
|
|
|
|
gesture.setMinimumY(min);
|
|
|
|
QCOMPARE(gesture.minimumY(), min);
|
|
|
|
QCOMPARE(gesture.minimumYIsRelevant(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMaximumX_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("max");
|
|
|
|
|
|
|
|
QTest::newRow("0") << 0;
|
|
|
|
QTest::newRow("-1") << -1;
|
|
|
|
QTest::newRow("1") << 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMaximumX()
|
|
|
|
{
|
|
|
|
SwipeGesture gesture;
|
|
|
|
QCOMPARE(gesture.maximumX(), 0);
|
|
|
|
QCOMPARE(gesture.maximumXIsRelevant(), false);
|
|
|
|
QFETCH(int, max);
|
|
|
|
gesture.setMaximumX(max);
|
|
|
|
QCOMPARE(gesture.maximumX(), max);
|
|
|
|
QCOMPARE(gesture.maximumXIsRelevant(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMaximumY_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("max");
|
|
|
|
|
|
|
|
QTest::newRow("0") << 0;
|
|
|
|
QTest::newRow("-1") << -1;
|
|
|
|
QTest::newRow("1") << 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMaximumY()
|
|
|
|
{
|
|
|
|
SwipeGesture gesture;
|
|
|
|
QCOMPARE(gesture.maximumY(), 0);
|
|
|
|
QCOMPARE(gesture.maximumYIsRelevant(), false);
|
|
|
|
QFETCH(int, max);
|
|
|
|
gesture.setMaximumY(max);
|
|
|
|
QCOMPARE(gesture.maximumY(), max);
|
|
|
|
QCOMPARE(gesture.maximumYIsRelevant(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testStartGeometry()
|
|
|
|
{
|
|
|
|
SwipeGesture gesture;
|
|
|
|
gesture.setStartGeometry(QRect(1, 2, 20, 30));
|
|
|
|
QCOMPARE(gesture.minimumXIsRelevant(), true);
|
|
|
|
QCOMPARE(gesture.minimumYIsRelevant(), true);
|
|
|
|
QCOMPARE(gesture.maximumXIsRelevant(), true);
|
|
|
|
QCOMPARE(gesture.maximumYIsRelevant(), true);
|
|
|
|
QCOMPARE(gesture.minimumX(), 1);
|
|
|
|
QCOMPARE(gesture.minimumY(), 2);
|
|
|
|
QCOMPARE(gesture.maximumX(), 21);
|
|
|
|
QCOMPARE(gesture.maximumY(), 32);
|
|
|
|
}
|
|
|
|
|
2022-09-11 10:14:11 +00:00
|
|
|
void GestureTest::testSetMinimumDelta()
|
|
|
|
{
|
|
|
|
SwipeGesture swipeGesture;
|
|
|
|
QCOMPARE(swipeGesture.isMinimumDeltaRelevant(), false);
|
|
|
|
QCOMPARE(swipeGesture.minimumDelta(), QSizeF());
|
|
|
|
QCOMPARE(swipeGesture.minimumDeltaReached(QSizeF()), true);
|
|
|
|
swipeGesture.setMinimumDelta(QSizeF(2, 3));
|
|
|
|
QCOMPARE(swipeGesture.isMinimumDeltaRelevant(), true);
|
|
|
|
QCOMPARE(swipeGesture.minimumDelta(), QSizeF(2, 3));
|
|
|
|
QCOMPARE(swipeGesture.minimumDeltaReached(QSizeF()), false);
|
|
|
|
QCOMPARE(swipeGesture.minimumDeltaReached(QSizeF(2, 3)), true);
|
|
|
|
|
|
|
|
PinchGesture pinchGesture;
|
|
|
|
QCOMPARE(pinchGesture.isMinimumScaleDeltaRelevant(), false);
|
|
|
|
QCOMPARE(pinchGesture.minimumScaleDelta(), DEFAULT_UNIT_SCALE_DELTA);
|
|
|
|
QCOMPARE(pinchGesture.minimumScaleDeltaReached(1.25), true);
|
|
|
|
pinchGesture.setMinimumScaleDelta(.5);
|
|
|
|
QCOMPARE(pinchGesture.isMinimumScaleDeltaRelevant(), true);
|
|
|
|
QCOMPARE(pinchGesture.minimumScaleDelta(), .5);
|
|
|
|
QCOMPARE(pinchGesture.minimumScaleDeltaReached(1.24), false);
|
|
|
|
QCOMPARE(pinchGesture.minimumScaleDeltaReached(1.5), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMinimumDeltaReached_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<KWin::SwipeGesture::Direction>("direction");
|
|
|
|
QTest::addColumn<QSizeF>("minimumDelta");
|
|
|
|
QTest::addColumn<QSizeF>("delta");
|
|
|
|
QTest::addColumn<bool>("reached");
|
|
|
|
QTest::addColumn<qreal>("progress");
|
|
|
|
|
|
|
|
QTest::newRow("Up (more)") << KWin::SwipeGesture::Direction::Up << QSizeF(0, -30) << QSizeF(0, -40) << true << 1.0;
|
|
|
|
QTest::newRow("Up (exact)") << KWin::SwipeGesture::Direction::Up << QSizeF(0, -30) << QSizeF(0, -30) << true << 1.0;
|
|
|
|
QTest::newRow("Up (less)") << KWin::SwipeGesture::Direction::Up << QSizeF(0, -30) << QSizeF(0, -29) << false << 29.0 / 30.0;
|
|
|
|
QTest::newRow("Left (more)") << KWin::SwipeGesture::Direction::Left << QSizeF(-30, -30) << QSizeF(-40, 20) << true << 1.0;
|
|
|
|
QTest::newRow("Left (exact)") << KWin::SwipeGesture::Direction::Left << QSizeF(-30, -40) << QSizeF(-30, 0) << true << 1.0;
|
|
|
|
QTest::newRow("Left (less)") << KWin::SwipeGesture::Direction::Left << QSizeF(-30, -30) << QSizeF(-29, 0) << false << 29.0 / 30.0;
|
|
|
|
QTest::newRow("Right (more)") << KWin::SwipeGesture::Direction::Right << QSizeF(30, -30) << QSizeF(40, 20) << true << 1.0;
|
|
|
|
QTest::newRow("Right (exact)") << KWin::SwipeGesture::Direction::Right << QSizeF(30, -40) << QSizeF(30, 0) << true << 1.0;
|
|
|
|
QTest::newRow("Right (less)") << KWin::SwipeGesture::Direction::Right << QSizeF(30, -30) << QSizeF(29, 0) << false << 29.0 / 30.0;
|
|
|
|
QTest::newRow("Down (more)") << KWin::SwipeGesture::Direction::Down << QSizeF(0, 30) << QSizeF(0, 40) << true << 1.0;
|
|
|
|
QTest::newRow("Down (exact)") << KWin::SwipeGesture::Direction::Down << QSizeF(0, 30) << QSizeF(0, 30) << true << 1.0;
|
|
|
|
QTest::newRow("Down (less)") << KWin::SwipeGesture::Direction::Down << QSizeF(0, 30) << QSizeF(0, 29) << false << 29.0 / 30.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMinimumDeltaReached()
|
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
|
|
|
|
|
|
|
// swipe gesture
|
|
|
|
SwipeGesture gesture;
|
|
|
|
QFETCH(SwipeGesture::Direction, direction);
|
|
|
|
gesture.setDirection(direction);
|
|
|
|
QFETCH(QSizeF, minimumDelta);
|
|
|
|
gesture.setMinimumDelta(minimumDelta);
|
|
|
|
QFETCH(QSizeF, delta);
|
|
|
|
QFETCH(bool, reached);
|
|
|
|
QCOMPARE(gesture.minimumDeltaReached(delta), reached);
|
|
|
|
|
|
|
|
recognizer.registerSwipeGesture(&gesture);
|
|
|
|
|
|
|
|
QSignalSpy startedSpy(&gesture, &SwipeGesture::started);
|
|
|
|
QSignalSpy triggeredSpy(&gesture, &SwipeGesture::triggered);
|
|
|
|
QSignalSpy cancelledSpy(&gesture, &SwipeGesture::cancelled);
|
|
|
|
QSignalSpy progressSpy(&gesture, &SwipeGesture::progress);
|
|
|
|
|
|
|
|
recognizer.startSwipeGesture(1);
|
|
|
|
QCOMPARE(startedSpy.count(), 1);
|
|
|
|
QCOMPARE(triggeredSpy.count(), 0);
|
|
|
|
QCOMPARE(cancelledSpy.count(), 0);
|
|
|
|
QCOMPARE(progressSpy.count(), 0);
|
|
|
|
|
|
|
|
recognizer.updateSwipeGesture(delta);
|
|
|
|
QCOMPARE(startedSpy.count(), 1);
|
|
|
|
QCOMPARE(triggeredSpy.count(), 0);
|
|
|
|
QCOMPARE(cancelledSpy.count(), 0);
|
|
|
|
QCOMPARE(progressSpy.count(), 1);
|
|
|
|
QTEST(progressSpy.first().first().value<qreal>(), "progress");
|
|
|
|
|
|
|
|
recognizer.endSwipeGesture();
|
|
|
|
QCOMPARE(startedSpy.count(), 1);
|
|
|
|
QCOMPARE(progressSpy.count(), 1);
|
|
|
|
QCOMPARE(triggeredSpy.isEmpty(), !reached);
|
|
|
|
QCOMPARE(cancelledSpy.isEmpty(), reached);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testMinimumScaleDelta()
|
|
|
|
{
|
|
|
|
// pinch gesture
|
|
|
|
PinchGesture gesture;
|
|
|
|
gesture.setDirection(PinchGesture::Direction::Contracting);
|
|
|
|
gesture.setMinimumScaleDelta(.5);
|
|
|
|
gesture.setMinimumFingerCount(3);
|
|
|
|
gesture.setMaximumFingerCount(4);
|
|
|
|
|
|
|
|
QCOMPARE(gesture.minimumScaleDeltaReached(1.25), false);
|
|
|
|
QCOMPARE(gesture.minimumScaleDeltaReached(1.5), true);
|
|
|
|
|
|
|
|
GestureRecognizer recognizer;
|
|
|
|
recognizer.registerPinchGesture(&gesture);
|
|
|
|
|
|
|
|
QSignalSpy startedSpy(&gesture, &PinchGesture::started);
|
|
|
|
QSignalSpy triggeredSpy(&gesture, &PinchGesture::triggered);
|
|
|
|
QSignalSpy cancelledSpy(&gesture, &PinchGesture::cancelled);
|
|
|
|
QSignalSpy progressSpy(&gesture, &PinchGesture::progress);
|
|
|
|
|
|
|
|
recognizer.startPinchGesture(4);
|
|
|
|
QCOMPARE(startedSpy.count(), 1);
|
|
|
|
QCOMPARE(triggeredSpy.count(), 0);
|
|
|
|
QCOMPARE(cancelledSpy.count(), 0);
|
|
|
|
QCOMPARE(progressSpy.count(), 0);
|
|
|
|
}
|
|
|
|
|
2017-03-18 10:00:30 +00:00
|
|
|
void GestureTest::testUnregisterSwipeCancels()
|
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<SwipeGesture> gesture(new SwipeGesture);
|
|
|
|
QSignalSpy startedSpy(gesture.get(), &SwipeGesture::started);
|
|
|
|
QSignalSpy cancelledSpy(gesture.get(), &SwipeGesture::cancelled);
|
2017-03-18 10:00:30 +00:00
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
recognizer.registerSwipeGesture(gesture.get());
|
2017-03-18 10:00:30 +00:00
|
|
|
recognizer.startSwipeGesture(1);
|
|
|
|
QCOMPARE(startedSpy.count(), 1);
|
|
|
|
QCOMPARE(cancelledSpy.count(), 0);
|
2022-08-01 21:29:02 +00:00
|
|
|
recognizer.unregisterSwipeGesture(gesture.get());
|
2022-02-02 21:51:39 +00:00
|
|
|
QCOMPARE(cancelledSpy.count(), 1);
|
|
|
|
|
|
|
|
// delete the gesture should not trigger cancel
|
|
|
|
gesture.reset();
|
|
|
|
QCOMPARE(cancelledSpy.count(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testUnregisterPinchCancels()
|
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<PinchGesture> gesture(new PinchGesture);
|
|
|
|
QSignalSpy startedSpy(gesture.get(), &PinchGesture::started);
|
|
|
|
QSignalSpy cancelledSpy(gesture.get(), &PinchGesture::cancelled);
|
2022-02-02 21:51:39 +00:00
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
recognizer.registerPinchGesture(gesture.get());
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.startPinchGesture(1);
|
|
|
|
QCOMPARE(startedSpy.count(), 1);
|
|
|
|
QCOMPARE(cancelledSpy.count(), 0);
|
2022-08-01 21:29:02 +00:00
|
|
|
recognizer.unregisterPinchGesture(gesture.get());
|
2017-03-18 10:00:30 +00:00
|
|
|
QCOMPARE(cancelledSpy.count(), 1);
|
|
|
|
|
|
|
|
// delete the gesture should not trigger cancel
|
|
|
|
gesture.reset();
|
|
|
|
QCOMPARE(cancelledSpy.count(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testDeleteSwipeCancels()
|
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<SwipeGesture> gesture(new SwipeGesture);
|
|
|
|
QSignalSpy startedSpy(gesture.get(), &SwipeGesture::started);
|
|
|
|
QSignalSpy cancelledSpy(gesture.get(), &SwipeGesture::cancelled);
|
2017-03-18 10:00:30 +00:00
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
recognizer.registerSwipeGesture(gesture.get());
|
2017-03-18 10:00:30 +00:00
|
|
|
recognizer.startSwipeGesture(1);
|
|
|
|
QCOMPARE(startedSpy.count(), 1);
|
|
|
|
QCOMPARE(cancelledSpy.count(), 0);
|
|
|
|
gesture.reset();
|
|
|
|
QCOMPARE(cancelledSpy.count(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeCancel_data()
|
|
|
|
{
|
2022-09-11 10:14:11 +00:00
|
|
|
QTest::addColumn<KWin::SwipeGesture::Direction>("direction");
|
2017-03-18 10:00:30 +00:00
|
|
|
|
2022-09-11 10:14:11 +00:00
|
|
|
QTest::newRow("Up") << KWin::SwipeGesture::Direction::Up;
|
|
|
|
QTest::newRow("Left") << KWin::SwipeGesture::Direction::Left;
|
|
|
|
QTest::newRow("Right") << KWin::SwipeGesture::Direction::Right;
|
|
|
|
QTest::newRow("Down") << KWin::SwipeGesture::Direction::Down;
|
2017-03-18 10:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeCancel()
|
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<SwipeGesture> gesture(new SwipeGesture);
|
2022-09-11 10:14:11 +00:00
|
|
|
QFETCH(SwipeGesture::Direction, direction);
|
2017-03-18 10:00:30 +00:00
|
|
|
gesture->setDirection(direction);
|
2022-08-01 21:29:02 +00:00
|
|
|
QSignalSpy startedSpy(gesture.get(), &SwipeGesture::started);
|
|
|
|
QSignalSpy cancelledSpy(gesture.get(), &SwipeGesture::cancelled);
|
|
|
|
QSignalSpy triggeredSpy(gesture.get(), &SwipeGesture::triggered);
|
2017-03-18 10:00:30 +00:00
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
recognizer.registerSwipeGesture(gesture.get());
|
2017-03-18 10:00:30 +00:00
|
|
|
recognizer.startSwipeGesture(1);
|
|
|
|
QCOMPARE(startedSpy.count(), 1);
|
|
|
|
QCOMPARE(cancelledSpy.count(), 0);
|
|
|
|
recognizer.cancelSwipeGesture();
|
|
|
|
QCOMPARE(cancelledSpy.count(), 1);
|
|
|
|
QCOMPARE(triggeredSpy.count(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeUpdateTrigger_data()
|
|
|
|
{
|
2022-09-11 10:14:11 +00:00
|
|
|
QTest::addColumn<KWin::SwipeGesture::Direction>("direction");
|
2017-03-18 10:00:30 +00:00
|
|
|
QTest::addColumn<QSizeF>("delta");
|
|
|
|
|
2022-09-11 10:14:11 +00:00
|
|
|
QTest::newRow("Up") << KWin::SwipeGesture::Direction::Up << QSizeF(2, -3);
|
|
|
|
QTest::newRow("Left") << KWin::SwipeGesture::Direction::Left << QSizeF(-3, 1);
|
|
|
|
QTest::newRow("Right") << KWin::SwipeGesture::Direction::Right << QSizeF(20, -19);
|
|
|
|
QTest::newRow("Down") << KWin::SwipeGesture::Direction::Down << QSizeF(0, 50);
|
2017-03-18 10:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeUpdateTrigger()
|
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
|
|
|
SwipeGesture gesture;
|
2022-09-11 10:14:11 +00:00
|
|
|
QFETCH(SwipeGesture::Direction, direction);
|
2017-03-18 10:00:30 +00:00
|
|
|
gesture.setDirection(direction);
|
|
|
|
|
|
|
|
QSignalSpy triggeredSpy(&gesture, &SwipeGesture::triggered);
|
|
|
|
QSignalSpy cancelledSpy(&gesture, &SwipeGesture::cancelled);
|
|
|
|
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.registerSwipeGesture(&gesture);
|
2017-03-18 10:00:30 +00:00
|
|
|
|
|
|
|
recognizer.startSwipeGesture(1);
|
|
|
|
QFETCH(QSizeF, delta);
|
|
|
|
recognizer.updateSwipeGesture(delta);
|
|
|
|
QCOMPARE(cancelledSpy.count(), 0);
|
|
|
|
QCOMPARE(triggeredSpy.count(), 0);
|
|
|
|
|
|
|
|
recognizer.endSwipeGesture();
|
|
|
|
QCOMPARE(cancelledSpy.count(), 0);
|
|
|
|
QCOMPARE(triggeredSpy.count(), 1);
|
|
|
|
}
|
|
|
|
|
2022-09-11 10:14:11 +00:00
|
|
|
void GestureTest::testSwipeMinFingerStart_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<uint>("min");
|
|
|
|
QTest::addColumn<uint>("count");
|
|
|
|
QTest::addColumn<bool>("started");
|
|
|
|
|
|
|
|
QTest::newRow("same") << 1u << 1u << true;
|
|
|
|
QTest::newRow("less") << 2u << 1u << false;
|
|
|
|
QTest::newRow("more") << 1u << 2u << true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeMinFingerStart()
|
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
|
|
|
SwipeGesture gesture;
|
|
|
|
QFETCH(uint, min);
|
|
|
|
gesture.setMinimumFingerCount(min);
|
|
|
|
|
|
|
|
QSignalSpy startedSpy(&gesture, &SwipeGesture::started);
|
|
|
|
|
|
|
|
recognizer.registerSwipeGesture(&gesture);
|
|
|
|
QFETCH(uint, count);
|
|
|
|
recognizer.startSwipeGesture(count);
|
|
|
|
QTEST(!startedSpy.isEmpty(), "started");
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeMaxFingerStart_data()
|
2017-03-18 10:00:30 +00:00
|
|
|
{
|
2022-09-11 10:14:11 +00:00
|
|
|
QTest::addColumn<uint>("max");
|
2017-03-18 10:00:30 +00:00
|
|
|
QTest::addColumn<uint>("count");
|
2022-09-11 10:14:11 +00:00
|
|
|
QTest::addColumn<bool>("started");
|
2017-03-18 10:00:30 +00:00
|
|
|
|
2022-09-11 10:14:11 +00:00
|
|
|
QTest::newRow("same") << 1u << 1u << true;
|
|
|
|
QTest::newRow("less") << 2u << 1u << true;
|
|
|
|
QTest::newRow("more") << 1u << 2u << false;
|
2017-03-18 10:00:30 +00:00
|
|
|
}
|
|
|
|
|
2022-09-11 10:14:11 +00:00
|
|
|
void GestureTest::testSwipeMaxFingerStart()
|
2017-03-18 10:00:30 +00:00
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
|
|
|
SwipeGesture gesture;
|
2022-09-11 10:14:11 +00:00
|
|
|
QFETCH(uint, max);
|
|
|
|
gesture.setMaximumFingerCount(max);
|
2017-03-18 10:00:30 +00:00
|
|
|
|
|
|
|
QSignalSpy startedSpy(&gesture, &SwipeGesture::started);
|
|
|
|
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.registerSwipeGesture(&gesture);
|
2017-03-18 10:00:30 +00:00
|
|
|
QFETCH(uint, count);
|
|
|
|
recognizer.startSwipeGesture(count);
|
|
|
|
QTEST(!startedSpy.isEmpty(), "started");
|
|
|
|
}
|
|
|
|
|
2022-02-02 21:51:39 +00:00
|
|
|
void GestureTest::testNotEmitCallbacksBeforeDirectionDecided()
|
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
|
|
|
SwipeGesture up;
|
|
|
|
SwipeGesture down;
|
|
|
|
SwipeGesture right;
|
|
|
|
PinchGesture expand;
|
|
|
|
PinchGesture contract;
|
2022-09-11 10:14:11 +00:00
|
|
|
up.setDirection(SwipeGesture::Direction::Up);
|
|
|
|
down.setDirection(SwipeGesture::Direction::Down);
|
|
|
|
right.setDirection(SwipeGesture::Direction::Right);
|
|
|
|
expand.setDirection(PinchGesture::Direction::Expanding);
|
|
|
|
contract.setDirection(PinchGesture::Direction::Contracting);
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.registerSwipeGesture(&up);
|
|
|
|
recognizer.registerSwipeGesture(&down);
|
|
|
|
recognizer.registerSwipeGesture(&right);
|
|
|
|
recognizer.registerPinchGesture(&expand);
|
|
|
|
recognizer.registerPinchGesture(&contract);
|
|
|
|
|
2022-09-11 10:14:08 +00:00
|
|
|
QSignalSpy upSpy(&up, &SwipeGesture::progress);
|
|
|
|
QSignalSpy downSpy(&down, &SwipeGesture::progress);
|
|
|
|
QSignalSpy rightSpy(&right, &SwipeGesture::progress);
|
|
|
|
QSignalSpy expandSpy(&expand, &PinchGesture::progress);
|
|
|
|
QSignalSpy contractSpy(&contract, &PinchGesture::progress);
|
2022-02-02 21:51:39 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// don't release callback until we know the direction of swipe gesture
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.startSwipeGesture(4);
|
|
|
|
QCOMPARE(upSpy.count(), 0);
|
|
|
|
QCOMPARE(downSpy.count(), 0);
|
|
|
|
QCOMPARE(rightSpy.count(), 0);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// up (negative y)
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.updateSwipeGesture(QSizeF(0, -1.5));
|
|
|
|
QCOMPARE(upSpy.count(), 1);
|
|
|
|
QCOMPARE(downSpy.count(), 0);
|
|
|
|
QCOMPARE(rightSpy.count(), 0);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// down (positive y)
|
|
|
|
// recognizer.updateSwipeGesture(QSizeF(0, 0));
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.updateSwipeGesture(QSizeF(0, 3));
|
|
|
|
QCOMPARE(upSpy.count(), 1);
|
|
|
|
QCOMPARE(downSpy.count(), 1);
|
|
|
|
QCOMPARE(rightSpy.count(), 0);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// right
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.cancelSwipeGesture();
|
|
|
|
recognizer.startSwipeGesture(4);
|
|
|
|
recognizer.updateSwipeGesture(QSizeF(1, 0));
|
|
|
|
QCOMPARE(upSpy.count(), 1);
|
|
|
|
QCOMPARE(downSpy.count(), 1);
|
|
|
|
QCOMPARE(rightSpy.count(), 1);
|
|
|
|
|
|
|
|
recognizer.cancelSwipeGesture();
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// same test for pinch gestures
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.startPinchGesture(4);
|
|
|
|
QCOMPARE(expandSpy.count(), 0);
|
|
|
|
QCOMPARE(contractSpy.count(), 0);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// contracting
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.updatePinchGesture(.5, 0, QSizeF(0, 0));
|
|
|
|
QCOMPARE(expandSpy.count(), 0);
|
|
|
|
QCOMPARE(contractSpy.count(), 1);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// expanding
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.updatePinchGesture(1.5, 0, QSizeF(0, 0));
|
|
|
|
QCOMPARE(expandSpy.count(), 1);
|
|
|
|
QCOMPARE(contractSpy.count(), 1);
|
|
|
|
}
|
|
|
|
|
2017-03-19 10:40:03 +00:00
|
|
|
void GestureTest::testSwipeGeometryStart_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QRect>("geometry");
|
|
|
|
QTest::addColumn<QPointF>("startPos");
|
|
|
|
QTest::addColumn<bool>("started");
|
|
|
|
|
|
|
|
QTest::newRow("top left") << QRect(0, 0, 10, 20) << QPointF(0, 0) << true;
|
|
|
|
QTest::newRow("top right") << QRect(0, 0, 10, 20) << QPointF(10, 0) << true;
|
|
|
|
QTest::newRow("bottom left") << QRect(0, 0, 10, 20) << QPointF(0, 20) << true;
|
|
|
|
QTest::newRow("bottom right") << QRect(0, 0, 10, 20) << QPointF(10, 20) << true;
|
|
|
|
QTest::newRow("x too small") << QRect(10, 20, 30, 40) << QPointF(9, 25) << false;
|
|
|
|
QTest::newRow("y too small") << QRect(10, 20, 30, 40) << QPointF(25, 19) << false;
|
|
|
|
QTest::newRow("x too large") << QRect(10, 20, 30, 40) << QPointF(41, 25) << false;
|
|
|
|
QTest::newRow("y too large") << QRect(10, 20, 30, 40) << QPointF(25, 61) << false;
|
|
|
|
QTest::newRow("inside") << QRect(10, 20, 30, 40) << QPointF(25, 25) << true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GestureTest::testSwipeGeometryStart()
|
|
|
|
{
|
|
|
|
GestureRecognizer recognizer;
|
|
|
|
SwipeGesture gesture;
|
|
|
|
QFETCH(QRect, geometry);
|
|
|
|
gesture.setStartGeometry(geometry);
|
|
|
|
|
|
|
|
QSignalSpy startedSpy(&gesture, &SwipeGesture::started);
|
|
|
|
|
2022-02-02 21:51:39 +00:00
|
|
|
recognizer.registerSwipeGesture(&gesture);
|
2017-03-19 10:40:03 +00:00
|
|
|
QFETCH(QPointF, startPos);
|
|
|
|
recognizer.startSwipeGesture(startPos);
|
|
|
|
QTEST(!startedSpy.isEmpty(), "started");
|
|
|
|
}
|
|
|
|
|
2017-03-18 10:00:30 +00:00
|
|
|
QTEST_MAIN(GestureTest)
|
|
|
|
#include "test_gestures.moc"
|