gesture: use the global direction enums
This commit is contained in:
parent
a9334cb9c6
commit
1746af4b02
6 changed files with 87 additions and 104 deletions
|
@ -171,6 +171,7 @@ add_executable(testGestures ${testGestures_SRCS})
|
||||||
|
|
||||||
target_link_libraries(testGestures
|
target_link_libraries(testGestures
|
||||||
Qt::Test
|
Qt::Test
|
||||||
|
Qt::Widgets
|
||||||
)
|
)
|
||||||
|
|
||||||
add_test(NAME kwin-testGestures COMMAND testGestures)
|
add_test(NAME kwin-testGestures COMMAND testGestures)
|
||||||
|
|
|
@ -15,6 +15,9 @@
|
||||||
|
|
||||||
using namespace KWin;
|
using namespace KWin;
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(SwipeDirection);
|
||||||
|
Q_DECLARE_METATYPE(PinchDirection);
|
||||||
|
|
||||||
class GestureTest : public QObject
|
class GestureTest : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -168,44 +171,44 @@ void GestureTest::testPinchMaxFinger()
|
||||||
|
|
||||||
void GestureTest::testSwipeDirection_data()
|
void GestureTest::testSwipeDirection_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<KWin::SwipeGesture::Direction>("swipe_direction");
|
QTest::addColumn<SwipeDirection>("swipe_direction");
|
||||||
|
|
||||||
QTest::newRow("Up") << KWin::SwipeGesture::Direction::Up;
|
QTest::newRow("Up") << SwipeDirection::Up;
|
||||||
QTest::newRow("Left") << KWin::SwipeGesture::Direction::Left;
|
QTest::newRow("Left") << SwipeDirection::Left;
|
||||||
QTest::newRow("Right") << KWin::SwipeGesture::Direction::Right;
|
QTest::newRow("Right") << SwipeDirection::Right;
|
||||||
QTest::newRow("Down") << KWin::SwipeGesture::Direction::Down;
|
QTest::newRow("Down") << SwipeDirection::Down;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GestureTest::testSwipeDirection()
|
void GestureTest::testSwipeDirection()
|
||||||
{
|
{
|
||||||
SwipeGesture gesture;
|
SwipeGesture gesture;
|
||||||
QCOMPARE(gesture.direction(), SwipeGesture::Direction::Down);
|
QCOMPARE(gesture.direction(), SwipeDirection::Down);
|
||||||
QFETCH(KWin::SwipeGesture::Direction, swipe_direction);
|
QFETCH(SwipeDirection, swipe_direction);
|
||||||
gesture.setDirection(swipe_direction);
|
gesture.setDirection(swipe_direction);
|
||||||
QCOMPARE(gesture.direction(), swipe_direction);
|
QCOMPARE(gesture.direction(), swipe_direction);
|
||||||
// back to down
|
// back to down
|
||||||
gesture.setDirection(SwipeGesture::Direction::Down);
|
gesture.setDirection(SwipeDirection::Down);
|
||||||
QCOMPARE(gesture.direction(), SwipeGesture::Direction::Down);
|
QCOMPARE(gesture.direction(), SwipeDirection::Down);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GestureTest::testPinchDirection_data()
|
void GestureTest::testPinchDirection_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<KWin::PinchGesture::Direction>("pinch_direction");
|
QTest::addColumn<PinchDirection>("pinch_direction");
|
||||||
|
|
||||||
QTest::newRow("Contracting") << KWin::PinchGesture::Direction::Contracting;
|
QTest::newRow("Contracting") << PinchDirection::Contracting;
|
||||||
QTest::newRow("Expanding") << KWin::PinchGesture::Direction::Expanding;
|
QTest::newRow("Expanding") << PinchDirection::Expanding;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GestureTest::testPinchDirection()
|
void GestureTest::testPinchDirection()
|
||||||
{
|
{
|
||||||
PinchGesture gesture;
|
PinchGesture gesture;
|
||||||
QCOMPARE(gesture.direction(), PinchGesture::Direction::Expanding);
|
QCOMPARE(gesture.direction(), PinchDirection::Expanding);
|
||||||
QFETCH(KWin::PinchGesture::Direction, pinch_direction);
|
QFETCH(PinchDirection, pinch_direction);
|
||||||
gesture.setDirection(pinch_direction);
|
gesture.setDirection(pinch_direction);
|
||||||
QCOMPARE(gesture.direction(), pinch_direction);
|
QCOMPARE(gesture.direction(), pinch_direction);
|
||||||
// back to down
|
// back to down
|
||||||
gesture.setDirection(PinchGesture::Direction::Expanding);
|
gesture.setDirection(PinchDirection::Expanding);
|
||||||
QCOMPARE(gesture.direction(), PinchGesture::Direction::Expanding);
|
QCOMPARE(gesture.direction(), PinchDirection::Expanding);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GestureTest::testMinimumX_data()
|
void GestureTest::testMinimumX_data()
|
||||||
|
@ -327,24 +330,24 @@ void GestureTest::testSetMinimumDelta()
|
||||||
|
|
||||||
void GestureTest::testMinimumDeltaReached_data()
|
void GestureTest::testMinimumDeltaReached_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<KWin::SwipeGesture::Direction>("direction");
|
QTest::addColumn<SwipeDirection>("direction");
|
||||||
QTest::addColumn<QPointF>("minimumDelta");
|
QTest::addColumn<QPointF>("minimumDelta");
|
||||||
QTest::addColumn<QPointF>("delta");
|
QTest::addColumn<QPointF>("delta");
|
||||||
QTest::addColumn<bool>("reached");
|
QTest::addColumn<bool>("reached");
|
||||||
QTest::addColumn<qreal>("progress");
|
QTest::addColumn<qreal>("progress");
|
||||||
|
|
||||||
QTest::newRow("Up (more)") << KWin::SwipeGesture::Direction::Up << QPointF(0, -30) << QPointF(0, -40) << true << 1.0;
|
QTest::newRow("Up (more)") << SwipeDirection::Up << QPointF(0, -30) << QPointF(0, -40) << true << 1.0;
|
||||||
QTest::newRow("Up (exact)") << KWin::SwipeGesture::Direction::Up << QPointF(0, -30) << QPointF(0, -30) << true << 1.0;
|
QTest::newRow("Up (exact)") << SwipeDirection::Up << QPointF(0, -30) << QPointF(0, -30) << true << 1.0;
|
||||||
QTest::newRow("Up (less)") << KWin::SwipeGesture::Direction::Up << QPointF(0, -30) << QPointF(0, -29) << false << 29.0 / 30.0;
|
QTest::newRow("Up (less)") << SwipeDirection::Up << QPointF(0, -30) << QPointF(0, -29) << false << 29.0 / 30.0;
|
||||||
QTest::newRow("Left (more)") << KWin::SwipeGesture::Direction::Left << QPointF(-30, -30) << QPointF(-40, 20) << true << 1.0;
|
QTest::newRow("Left (more)") << SwipeDirection::Left << QPointF(-30, -30) << QPointF(-40, 20) << true << 1.0;
|
||||||
QTest::newRow("Left (exact)") << KWin::SwipeGesture::Direction::Left << QPointF(-30, -40) << QPointF(-30, 0) << true << 1.0;
|
QTest::newRow("Left (exact)") << SwipeDirection::Left << QPointF(-30, -40) << QPointF(-30, 0) << true << 1.0;
|
||||||
QTest::newRow("Left (less)") << KWin::SwipeGesture::Direction::Left << QPointF(-30, -30) << QPointF(-29, 0) << false << 29.0 / 30.0;
|
QTest::newRow("Left (less)") << SwipeDirection::Left << QPointF(-30, -30) << QPointF(-29, 0) << false << 29.0 / 30.0;
|
||||||
QTest::newRow("Right (more)") << KWin::SwipeGesture::Direction::Right << QPointF(30, -30) << QPointF(40, 20) << true << 1.0;
|
QTest::newRow("Right (more)") << SwipeDirection::Right << QPointF(30, -30) << QPointF(40, 20) << true << 1.0;
|
||||||
QTest::newRow("Right (exact)") << KWin::SwipeGesture::Direction::Right << QPointF(30, -40) << QPointF(30, 0) << true << 1.0;
|
QTest::newRow("Right (exact)") << SwipeDirection::Right << QPointF(30, -40) << QPointF(30, 0) << true << 1.0;
|
||||||
QTest::newRow("Right (less)") << KWin::SwipeGesture::Direction::Right << QPointF(30, -30) << QPointF(29, 0) << false << 29.0 / 30.0;
|
QTest::newRow("Right (less)") << SwipeDirection::Right << QPointF(30, -30) << QPointF(29, 0) << false << 29.0 / 30.0;
|
||||||
QTest::newRow("Down (more)") << KWin::SwipeGesture::Direction::Down << QPointF(0, 30) << QPointF(0, 40) << true << 1.0;
|
QTest::newRow("Down (more)") << SwipeDirection::Down << QPointF(0, 30) << QPointF(0, 40) << true << 1.0;
|
||||||
QTest::newRow("Down (exact)") << KWin::SwipeGesture::Direction::Down << QPointF(0, 30) << QPointF(0, 30) << true << 1.0;
|
QTest::newRow("Down (exact)") << SwipeDirection::Down << QPointF(0, 30) << QPointF(0, 30) << true << 1.0;
|
||||||
QTest::newRow("Down (less)") << KWin::SwipeGesture::Direction::Down << QPointF(0, 30) << QPointF(0, 29) << false << 29.0 / 30.0;
|
QTest::newRow("Down (less)") << SwipeDirection::Down << QPointF(0, 30) << QPointF(0, 29) << false << 29.0 / 30.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GestureTest::testMinimumDeltaReached()
|
void GestureTest::testMinimumDeltaReached()
|
||||||
|
@ -353,7 +356,7 @@ void GestureTest::testMinimumDeltaReached()
|
||||||
|
|
||||||
// swipe gesture
|
// swipe gesture
|
||||||
SwipeGesture gesture;
|
SwipeGesture gesture;
|
||||||
QFETCH(SwipeGesture::Direction, direction);
|
QFETCH(SwipeDirection, direction);
|
||||||
gesture.setDirection(direction);
|
gesture.setDirection(direction);
|
||||||
QFETCH(QPointF, minimumDelta);
|
QFETCH(QPointF, minimumDelta);
|
||||||
gesture.setMinimumDelta(minimumDelta);
|
gesture.setMinimumDelta(minimumDelta);
|
||||||
|
@ -392,7 +395,7 @@ void GestureTest::testMinimumScaleDelta()
|
||||||
{
|
{
|
||||||
// pinch gesture
|
// pinch gesture
|
||||||
PinchGesture gesture;
|
PinchGesture gesture;
|
||||||
gesture.setDirection(PinchGesture::Direction::Contracting);
|
gesture.setDirection(PinchDirection::Contracting);
|
||||||
gesture.setMinimumScaleDelta(.5);
|
gesture.setMinimumScaleDelta(.5);
|
||||||
gesture.setMinimumFingerCount(3);
|
gesture.setMinimumFingerCount(3);
|
||||||
gesture.setMaximumFingerCount(4);
|
gesture.setMaximumFingerCount(4);
|
||||||
|
@ -470,19 +473,19 @@ void GestureTest::testDeleteSwipeCancels()
|
||||||
|
|
||||||
void GestureTest::testSwipeCancel_data()
|
void GestureTest::testSwipeCancel_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<KWin::SwipeGesture::Direction>("direction");
|
QTest::addColumn<SwipeDirection>("direction");
|
||||||
|
|
||||||
QTest::newRow("Up") << KWin::SwipeGesture::Direction::Up;
|
QTest::newRow("Up") << SwipeDirection::Up;
|
||||||
QTest::newRow("Left") << KWin::SwipeGesture::Direction::Left;
|
QTest::newRow("Left") << SwipeDirection::Left;
|
||||||
QTest::newRow("Right") << KWin::SwipeGesture::Direction::Right;
|
QTest::newRow("Right") << SwipeDirection::Right;
|
||||||
QTest::newRow("Down") << KWin::SwipeGesture::Direction::Down;
|
QTest::newRow("Down") << SwipeDirection::Down;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GestureTest::testSwipeCancel()
|
void GestureTest::testSwipeCancel()
|
||||||
{
|
{
|
||||||
GestureRecognizer recognizer;
|
GestureRecognizer recognizer;
|
||||||
std::unique_ptr<SwipeGesture> gesture(new SwipeGesture);
|
std::unique_ptr<SwipeGesture> gesture(new SwipeGesture);
|
||||||
QFETCH(SwipeGesture::Direction, direction);
|
QFETCH(SwipeDirection, direction);
|
||||||
gesture->setDirection(direction);
|
gesture->setDirection(direction);
|
||||||
QSignalSpy startedSpy(gesture.get(), &SwipeGesture::started);
|
QSignalSpy startedSpy(gesture.get(), &SwipeGesture::started);
|
||||||
QSignalSpy cancelledSpy(gesture.get(), &SwipeGesture::cancelled);
|
QSignalSpy cancelledSpy(gesture.get(), &SwipeGesture::cancelled);
|
||||||
|
@ -499,20 +502,20 @@ void GestureTest::testSwipeCancel()
|
||||||
|
|
||||||
void GestureTest::testSwipeUpdateTrigger_data()
|
void GestureTest::testSwipeUpdateTrigger_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<KWin::SwipeGesture::Direction>("direction");
|
QTest::addColumn<SwipeDirection>("direction");
|
||||||
QTest::addColumn<QPointF>("delta");
|
QTest::addColumn<QPointF>("delta");
|
||||||
|
|
||||||
QTest::newRow("Up") << KWin::SwipeGesture::Direction::Up << QPointF(2, -3);
|
QTest::newRow("Up") << SwipeDirection::Up << QPointF(2, -3);
|
||||||
QTest::newRow("Left") << KWin::SwipeGesture::Direction::Left << QPointF(-3, 1);
|
QTest::newRow("Left") << SwipeDirection::Left << QPointF(-3, 1);
|
||||||
QTest::newRow("Right") << KWin::SwipeGesture::Direction::Right << QPointF(20, -19);
|
QTest::newRow("Right") << SwipeDirection::Right << QPointF(20, -19);
|
||||||
QTest::newRow("Down") << KWin::SwipeGesture::Direction::Down << QPointF(0, 50);
|
QTest::newRow("Down") << SwipeDirection::Down << QPointF(0, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GestureTest::testSwipeUpdateTrigger()
|
void GestureTest::testSwipeUpdateTrigger()
|
||||||
{
|
{
|
||||||
GestureRecognizer recognizer;
|
GestureRecognizer recognizer;
|
||||||
SwipeGesture gesture;
|
SwipeGesture gesture;
|
||||||
QFETCH(SwipeGesture::Direction, direction);
|
QFETCH(SwipeDirection, direction);
|
||||||
gesture.setDirection(direction);
|
gesture.setDirection(direction);
|
||||||
|
|
||||||
QSignalSpy triggeredSpy(&gesture, &SwipeGesture::triggered);
|
QSignalSpy triggeredSpy(&gesture, &SwipeGesture::triggered);
|
||||||
|
@ -591,11 +594,11 @@ void GestureTest::testNotEmitCallbacksBeforeDirectionDecided()
|
||||||
SwipeGesture right;
|
SwipeGesture right;
|
||||||
PinchGesture expand;
|
PinchGesture expand;
|
||||||
PinchGesture contract;
|
PinchGesture contract;
|
||||||
up.setDirection(SwipeGesture::Direction::Up);
|
up.setDirection(SwipeDirection::Up);
|
||||||
down.setDirection(SwipeGesture::Direction::Down);
|
down.setDirection(SwipeDirection::Down);
|
||||||
right.setDirection(SwipeGesture::Direction::Right);
|
right.setDirection(SwipeDirection::Right);
|
||||||
expand.setDirection(PinchGesture::Direction::Expanding);
|
expand.setDirection(PinchDirection::Expanding);
|
||||||
contract.setDirection(PinchGesture::Direction::Contracting);
|
contract.setDirection(PinchDirection::Contracting);
|
||||||
recognizer.registerSwipeGesture(&up);
|
recognizer.registerSwipeGesture(&up);
|
||||||
recognizer.registerSwipeGesture(&down);
|
recognizer.registerSwipeGesture(&down);
|
||||||
recognizer.registerSwipeGesture(&right);
|
recognizer.registerSwipeGesture(&right);
|
||||||
|
|
|
@ -48,11 +48,11 @@ qreal SwipeGesture::deltaToProgress(const QPointF &delta) const
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (m_direction) {
|
switch (m_direction) {
|
||||||
case Direction::Up:
|
case SwipeDirection::Up:
|
||||||
case Direction::Down:
|
case SwipeDirection::Down:
|
||||||
return std::min(std::abs(delta.y()) / std::abs(m_minimumDelta.y()), 1.0);
|
return std::min(std::abs(delta.y()) / std::abs(m_minimumDelta.y()), 1.0);
|
||||||
case Direction::Left:
|
case SwipeDirection::Left:
|
||||||
case Direction::Right:
|
case SwipeDirection::Right:
|
||||||
return std::min(std::abs(delta.x()) / std::abs(m_minimumDelta.x()), 1.0);
|
return std::min(std::abs(delta.x()) / std::abs(m_minimumDelta.x()), 1.0);
|
||||||
default:
|
default:
|
||||||
Q_UNREACHABLE();
|
Q_UNREACHABLE();
|
||||||
|
@ -173,18 +173,20 @@ int GestureRecognizer::startSwipeGesture(uint fingerCount, const QPointF &startP
|
||||||
|
|
||||||
// Only add gestures who's direction aligns with current swipe axis
|
// Only add gestures who's direction aligns with current swipe axis
|
||||||
switch (gesture->direction()) {
|
switch (gesture->direction()) {
|
||||||
case SwipeGesture::Direction::Up:
|
case SwipeDirection::Up:
|
||||||
case SwipeGesture::Direction::Down:
|
case SwipeDirection::Down:
|
||||||
if (m_currentSwipeAxis == Axis::Horizontal) {
|
if (m_currentSwipeAxis == Axis::Horizontal) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SwipeGesture::Direction::Left:
|
case SwipeDirection::Left:
|
||||||
case SwipeGesture::Direction::Right:
|
case SwipeDirection::Right:
|
||||||
if (m_currentSwipeAxis == Axis::Vertical) {
|
if (m_currentSwipeAxis == Axis::Vertical) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SwipeDirection::Invalid:
|
||||||
|
Q_UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_activeSwipeGestures << gesture;
|
m_activeSwipeGestures << gesture;
|
||||||
|
@ -198,17 +200,17 @@ void GestureRecognizer::updateSwipeGesture(const QPointF &delta)
|
||||||
{
|
{
|
||||||
m_currentDelta += delta;
|
m_currentDelta += delta;
|
||||||
|
|
||||||
SwipeGesture::Direction direction; // Overall direction
|
SwipeDirection direction; // Overall direction
|
||||||
Axis swipeAxis;
|
Axis swipeAxis;
|
||||||
|
|
||||||
// Pick an axis for gestures so horizontal ones don't change to vertical ones without lifting fingers
|
// Pick an axis for gestures so horizontal ones don't change to vertical ones without lifting fingers
|
||||||
if (m_currentSwipeAxis == Axis::None) {
|
if (m_currentSwipeAxis == Axis::None) {
|
||||||
if (std::abs(m_currentDelta.x()) >= std::abs(m_currentDelta.y())) {
|
if (std::abs(m_currentDelta.x()) >= std::abs(m_currentDelta.y())) {
|
||||||
swipeAxis = Axis::Horizontal;
|
swipeAxis = Axis::Horizontal;
|
||||||
direction = m_currentDelta.x() < 0 ? SwipeGesture::Direction::Left : SwipeGesture::Direction::Right;
|
direction = m_currentDelta.x() < 0 ? SwipeDirection::Left : SwipeDirection::Right;
|
||||||
} else {
|
} else {
|
||||||
swipeAxis = Axis::Vertical;
|
swipeAxis = Axis::Vertical;
|
||||||
direction = m_currentDelta.y() < 0 ? SwipeGesture::Direction::Up : SwipeGesture::Direction::Down;
|
direction = m_currentDelta.y() < 0 ? SwipeDirection::Up : SwipeDirection::Down;
|
||||||
}
|
}
|
||||||
if (std::abs(m_currentDelta.x()) >= 5 || std::abs(m_currentDelta.y()) >= 5) {
|
if (std::abs(m_currentDelta.x()) >= 5 || std::abs(m_currentDelta.y()) >= 5) {
|
||||||
// only lock in a direction if the delta is big enough
|
// only lock in a direction if the delta is big enough
|
||||||
|
@ -222,10 +224,10 @@ void GestureRecognizer::updateSwipeGesture(const QPointF &delta)
|
||||||
// Find the current swipe direction
|
// Find the current swipe direction
|
||||||
switch (swipeAxis) {
|
switch (swipeAxis) {
|
||||||
case Axis::Vertical:
|
case Axis::Vertical:
|
||||||
direction = m_currentDelta.y() < 0 ? SwipeGesture::Direction::Up : SwipeGesture::Direction::Down;
|
direction = m_currentDelta.y() < 0 ? SwipeDirection::Up : SwipeDirection::Down;
|
||||||
break;
|
break;
|
||||||
case Axis::Horizontal:
|
case Axis::Horizontal:
|
||||||
direction = m_currentDelta.x() < 0 ? SwipeGesture::Direction::Left : SwipeGesture::Direction::Right;
|
direction = m_currentDelta.x() < 0 ? SwipeDirection::Left : SwipeDirection::Right;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Q_UNREACHABLE();
|
Q_UNREACHABLE();
|
||||||
|
@ -332,11 +334,11 @@ void GestureRecognizer::updatePinchGesture(qreal scale, qreal angleDelta, const
|
||||||
m_currentScale = scale;
|
m_currentScale = scale;
|
||||||
|
|
||||||
// Determine the direction of the swipe
|
// Determine the direction of the swipe
|
||||||
PinchGesture::Direction direction;
|
PinchDirection direction;
|
||||||
if (scale < 1) {
|
if (scale < 1) {
|
||||||
direction = PinchGesture::Direction::Contracting;
|
direction = PinchDirection::Contracting;
|
||||||
} else {
|
} else {
|
||||||
direction = PinchGesture::Direction::Expanding;
|
direction = PinchDirection::Expanding;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Eliminate wrong gestures (takes two iterations)
|
// Eliminate wrong gestures (takes two iterations)
|
||||||
|
@ -418,12 +420,12 @@ uint SwipeGesture::maximumFingerCount() const
|
||||||
return m_maximumFingerCount;
|
return m_maximumFingerCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
SwipeGesture::Direction SwipeGesture::direction() const
|
SwipeDirection SwipeGesture::direction() const
|
||||||
{
|
{
|
||||||
return m_direction;
|
return m_direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwipeGesture::setDirection(Direction direction)
|
void SwipeGesture::setDirection(SwipeDirection direction)
|
||||||
{
|
{
|
||||||
m_direction = direction;
|
m_direction = direction;
|
||||||
}
|
}
|
||||||
|
@ -540,12 +542,12 @@ uint PinchGesture::maximumFingerCount() const
|
||||||
return m_maximumFingerCount;
|
return m_maximumFingerCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
PinchGesture::Direction PinchGesture::direction() const
|
PinchDirection PinchGesture::direction() const
|
||||||
{
|
{
|
||||||
return m_direction;
|
return m_direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PinchGesture::setDirection(Direction direction)
|
void PinchGesture::setDirection(PinchDirection direction)
|
||||||
{
|
{
|
||||||
m_direction = direction;
|
m_direction = direction;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "kwinglobals.h"
|
||||||
#include <kwin_export.h>
|
#include <kwin_export.h>
|
||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
@ -53,13 +54,6 @@ class SwipeGesture : public Gesture
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum class Direction {
|
|
||||||
Down,
|
|
||||||
Left,
|
|
||||||
Up,
|
|
||||||
Right,
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit SwipeGesture(QObject *parent = nullptr);
|
explicit SwipeGesture(QObject *parent = nullptr);
|
||||||
~SwipeGesture() override;
|
~SwipeGesture() override;
|
||||||
|
|
||||||
|
@ -71,8 +65,8 @@ public:
|
||||||
void setMaximumFingerCount(uint count);
|
void setMaximumFingerCount(uint count);
|
||||||
uint maximumFingerCount() const;
|
uint maximumFingerCount() const;
|
||||||
|
|
||||||
Direction direction() const;
|
SwipeDirection direction() const;
|
||||||
void setDirection(Direction direction);
|
void setDirection(SwipeDirection direction);
|
||||||
|
|
||||||
void setMinimumX(int x);
|
void setMinimumX(int x);
|
||||||
int minimumX() const;
|
int minimumX() const;
|
||||||
|
@ -113,7 +107,7 @@ private:
|
||||||
uint m_minimumFingerCount = 0;
|
uint m_minimumFingerCount = 0;
|
||||||
bool m_maximumFingerCountRelevant = false;
|
bool m_maximumFingerCountRelevant = false;
|
||||||
uint m_maximumFingerCount = 0;
|
uint m_maximumFingerCount = 0;
|
||||||
Direction m_direction = Direction::Down;
|
SwipeDirection m_direction = SwipeDirection::Down;
|
||||||
bool m_minimumXRelevant = false;
|
bool m_minimumXRelevant = false;
|
||||||
int m_minimumX = 0;
|
int m_minimumX = 0;
|
||||||
bool m_minimumYRelevant = false;
|
bool m_minimumYRelevant = false;
|
||||||
|
@ -130,11 +124,6 @@ class PinchGesture : public Gesture
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum class Direction {
|
|
||||||
Expanding,
|
|
||||||
Contracting,
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit PinchGesture(QObject *parent = nullptr);
|
explicit PinchGesture(QObject *parent = nullptr);
|
||||||
~PinchGesture() override;
|
~PinchGesture() override;
|
||||||
|
|
||||||
|
@ -146,8 +135,8 @@ public:
|
||||||
void setMaximumFingerCount(uint count);
|
void setMaximumFingerCount(uint count);
|
||||||
uint maximumFingerCount() const;
|
uint maximumFingerCount() const;
|
||||||
|
|
||||||
Direction direction() const;
|
PinchDirection direction() const;
|
||||||
void setDirection(Direction direction);
|
void setDirection(PinchDirection direction);
|
||||||
|
|
||||||
qreal minimumScaleDelta() const;
|
qreal minimumScaleDelta() const;
|
||||||
|
|
||||||
|
@ -173,7 +162,7 @@ private:
|
||||||
uint m_minimumFingerCount = 0;
|
uint m_minimumFingerCount = 0;
|
||||||
bool m_maximumFingerCountRelevant = false;
|
bool m_maximumFingerCountRelevant = false;
|
||||||
uint m_maximumFingerCount = 0;
|
uint m_maximumFingerCount = 0;
|
||||||
Direction m_direction = Direction::Expanding;
|
PinchDirection m_direction = PinchDirection::Expanding;
|
||||||
bool m_minimumScaleDeltaRelevant = false;
|
bool m_minimumScaleDeltaRelevant = false;
|
||||||
qreal m_minimumScaleDelta = DEFAULT_UNIT_SCALE_DELTA;
|
qreal m_minimumScaleDelta = DEFAULT_UNIT_SCALE_DELTA;
|
||||||
};
|
};
|
||||||
|
@ -227,6 +216,3 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(KWin::SwipeGesture::Direction)
|
|
||||||
Q_DECLARE_METATYPE(KWin::PinchGesture::Direction)
|
|
||||||
|
|
|
@ -30,18 +30,9 @@ GlobalShortcut::GlobalShortcut(Shortcut &&sc, QAction *action)
|
||||||
: m_shortcut(sc)
|
: m_shortcut(sc)
|
||||||
, m_action(action)
|
, m_action(action)
|
||||||
{
|
{
|
||||||
static const QMap<SwipeDirection, SwipeGesture::Direction> swipeDirs = {
|
|
||||||
{SwipeDirection::Up, SwipeGesture::Direction::Up},
|
|
||||||
{SwipeDirection::Down, SwipeGesture::Direction::Down},
|
|
||||||
{SwipeDirection::Left, SwipeGesture::Direction::Left},
|
|
||||||
{SwipeDirection::Right, SwipeGesture::Direction::Right},
|
|
||||||
};
|
|
||||||
static const QMap<PinchDirection, PinchGesture::Direction> pinchDirs = {
|
|
||||||
{PinchDirection::Expanding, PinchGesture::Direction::Expanding},
|
|
||||||
{PinchDirection::Contracting, PinchGesture::Direction::Contracting}};
|
|
||||||
if (auto swipeGesture = std::get_if<RealtimeFeedbackSwipeShortcut>(&sc)) {
|
if (auto swipeGesture = std::get_if<RealtimeFeedbackSwipeShortcut>(&sc)) {
|
||||||
m_swipeGesture = std::make_unique<SwipeGesture>();
|
m_swipeGesture = std::make_unique<SwipeGesture>();
|
||||||
m_swipeGesture->setDirection(swipeDirs[swipeGesture->direction]);
|
m_swipeGesture->setDirection(swipeGesture->direction);
|
||||||
m_swipeGesture->setMinimumDelta(QPointF(200, 200));
|
m_swipeGesture->setMinimumDelta(QPointF(200, 200));
|
||||||
m_swipeGesture->setMaximumFingerCount(swipeGesture->fingerCount);
|
m_swipeGesture->setMaximumFingerCount(swipeGesture->fingerCount);
|
||||||
m_swipeGesture->setMinimumFingerCount(swipeGesture->fingerCount);
|
m_swipeGesture->setMinimumFingerCount(swipeGesture->fingerCount);
|
||||||
|
@ -52,7 +43,7 @@ GlobalShortcut::GlobalShortcut(Shortcut &&sc, QAction *action)
|
||||||
}
|
}
|
||||||
} else if (auto pinchGesture = std::get_if<RealtimeFeedbackPinchShortcut>(&sc)) {
|
} else if (auto pinchGesture = std::get_if<RealtimeFeedbackPinchShortcut>(&sc)) {
|
||||||
m_pinchGesture = std::make_unique<PinchGesture>();
|
m_pinchGesture = std::make_unique<PinchGesture>();
|
||||||
m_pinchGesture->setDirection(pinchDirs[pinchGesture->direction]);
|
m_pinchGesture->setDirection(pinchGesture->direction);
|
||||||
m_pinchGesture->setMaximumFingerCount(pinchGesture->fingerCount);
|
m_pinchGesture->setMaximumFingerCount(pinchGesture->fingerCount);
|
||||||
m_pinchGesture->setMinimumFingerCount(pinchGesture->fingerCount);
|
m_pinchGesture->setMinimumFingerCount(pinchGesture->fingerCount);
|
||||||
QObject::connect(m_pinchGesture.get(), &PinchGesture::triggered, m_action, &QAction::trigger, Qt::QueuedConnection);
|
QObject::connect(m_pinchGesture.get(), &PinchGesture::triggered, m_action, &QAction::trigger, Qt::QueuedConnection);
|
||||||
|
|
|
@ -709,16 +709,16 @@ void Edge::setBorder(ElectricBorder border)
|
||||||
m_border = border;
|
m_border = border;
|
||||||
switch (m_border) {
|
switch (m_border) {
|
||||||
case ElectricTop:
|
case ElectricTop:
|
||||||
m_gesture->setDirection(SwipeGesture::Direction::Down);
|
m_gesture->setDirection(SwipeDirection::Down);
|
||||||
break;
|
break;
|
||||||
case ElectricRight:
|
case ElectricRight:
|
||||||
m_gesture->setDirection(SwipeGesture::Direction::Left);
|
m_gesture->setDirection(SwipeDirection::Left);
|
||||||
break;
|
break;
|
||||||
case ElectricBottom:
|
case ElectricBottom:
|
||||||
m_gesture->setDirection(SwipeGesture::Direction::Up);
|
m_gesture->setDirection(SwipeDirection::Up);
|
||||||
break;
|
break;
|
||||||
case ElectricLeft:
|
case ElectricLeft:
|
||||||
m_gesture->setDirection(SwipeGesture::Direction::Right);
|
m_gesture->setDirection(SwipeDirection::Right);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue