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
|
|
|
|
*/
|
2017-03-18 10:00:30 +00:00
|
|
|
#ifndef KWIN_GESTURES_H
|
|
|
|
#define KWIN_GESTURES_H
|
|
|
|
|
2017-03-22 20:03:04 +00:00
|
|
|
#include <kwin_export.h>
|
|
|
|
|
2017-03-18 10:00:30 +00:00
|
|
|
#include <QObject>
|
2017-03-19 10:40:03 +00:00
|
|
|
#include <QPointF>
|
|
|
|
#include <QSizeF>
|
2017-03-18 10:00:30 +00:00
|
|
|
#include <QMap>
|
|
|
|
#include <QVector>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
class Gesture : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
~Gesture() override;
|
|
|
|
protected:
|
|
|
|
explicit Gesture(QObject *parent);
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
/**
|
|
|
|
* Matching of a gesture started and this Gesture might match.
|
2019-01-12 10:31:32 +00:00
|
|
|
* On further evaluation either the signal @ref triggered or
|
|
|
|
* @ref cancelled will get emitted.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-03-18 10:00:30 +00:00
|
|
|
void started();
|
|
|
|
/**
|
|
|
|
* Gesture matching ended and this Gesture matched.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-03-18 10:00:30 +00:00
|
|
|
void triggered();
|
|
|
|
/**
|
|
|
|
* This Gesture no longer matches.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-03-18 10:00:30 +00:00
|
|
|
void cancelled();
|
|
|
|
};
|
|
|
|
|
|
|
|
class SwipeGesture : public Gesture
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
enum class Direction {
|
|
|
|
Down,
|
|
|
|
Left,
|
|
|
|
Up,
|
|
|
|
Right
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit SwipeGesture(QObject *parent = nullptr);
|
|
|
|
~SwipeGesture() override;
|
|
|
|
|
|
|
|
bool minimumFingerCountIsRelevant() const {
|
|
|
|
return m_minimumFingerCountRelevant;
|
|
|
|
}
|
|
|
|
void setMinimumFingerCount(uint count) {
|
|
|
|
m_minimumFingerCount = count;
|
|
|
|
m_minimumFingerCountRelevant = true;
|
|
|
|
}
|
|
|
|
uint minimumFingerCount() const {
|
|
|
|
return m_minimumFingerCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool maximumFingerCountIsRelevant() const {
|
|
|
|
return m_maximumFingerCountRelevant;
|
|
|
|
}
|
|
|
|
void setMaximumFingerCount(uint count) {
|
|
|
|
m_maximumFingerCount = count;
|
|
|
|
m_maximumFingerCountRelevant = true;
|
|
|
|
}
|
|
|
|
uint maximumFingerCount() const {
|
|
|
|
return m_maximumFingerCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
Direction direction() const {
|
|
|
|
return m_direction;
|
|
|
|
}
|
|
|
|
void setDirection(Direction direction) {
|
|
|
|
m_direction = direction;
|
|
|
|
}
|
|
|
|
|
2017-03-19 10:40:03 +00:00
|
|
|
void setMinimumX(int x) {
|
|
|
|
m_minimumX = x;
|
|
|
|
m_minimumXRelevant = true;
|
|
|
|
}
|
|
|
|
int minimumX() const {
|
|
|
|
return m_minimumX;
|
|
|
|
}
|
|
|
|
bool minimumXIsRelevant() const {
|
|
|
|
return m_minimumXRelevant;
|
|
|
|
}
|
|
|
|
void setMinimumY(int y) {
|
|
|
|
m_minimumY = y;
|
|
|
|
m_minimumYRelevant = true;
|
|
|
|
}
|
|
|
|
int minimumY() const {
|
|
|
|
return m_minimumY;
|
|
|
|
}
|
|
|
|
bool minimumYIsRelevant() const {
|
|
|
|
return m_minimumYRelevant;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMaximumX(int x) {
|
|
|
|
m_maximumX = x;
|
|
|
|
m_maximumXRelevant = true;
|
|
|
|
}
|
|
|
|
int maximumX() const {
|
|
|
|
return m_maximumX;
|
|
|
|
}
|
|
|
|
bool maximumXIsRelevant() const {
|
|
|
|
return m_maximumXRelevant;
|
|
|
|
}
|
|
|
|
void setMaximumY(int y) {
|
|
|
|
m_maximumY = y;
|
|
|
|
m_maximumYRelevant = true;
|
|
|
|
}
|
|
|
|
int maximumY() const {
|
|
|
|
return m_maximumY;
|
|
|
|
}
|
|
|
|
bool maximumYIsRelevant() const {
|
|
|
|
return m_maximumYRelevant;
|
|
|
|
}
|
|
|
|
void setStartGeometry(const QRect &geometry);
|
|
|
|
|
|
|
|
QSizeF minimumDelta() const {
|
|
|
|
return m_minimumDelta;
|
|
|
|
}
|
|
|
|
void setMinimumDelta(const QSizeF &delta) {
|
|
|
|
m_minimumDelta = delta;
|
|
|
|
m_minimumDeltaRelevant = true;
|
|
|
|
}
|
|
|
|
bool isMinimumDeltaRelevant() const {
|
|
|
|
return m_minimumDeltaRelevant;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal minimumDeltaReachedProgress(const QSizeF &delta) const;
|
|
|
|
bool minimumDeltaReached(const QSizeF &delta) const;
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
/**
|
2019-01-12 10:31:32 +00:00
|
|
|
* The progress of the gesture if a minimumDelta is set.
|
2017-03-19 10:40:03 +00:00
|
|
|
* The progress is reported in [0.0,1.0]
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2017-03-19 10:40:03 +00:00
|
|
|
void progress(qreal);
|
|
|
|
|
2017-03-18 10:00:30 +00:00
|
|
|
private:
|
|
|
|
bool m_minimumFingerCountRelevant = false;
|
|
|
|
uint m_minimumFingerCount = 0;
|
|
|
|
bool m_maximumFingerCountRelevant = false;
|
|
|
|
uint m_maximumFingerCount = 0;
|
|
|
|
Direction m_direction = Direction::Down;
|
2017-03-19 10:40:03 +00:00
|
|
|
bool m_minimumXRelevant = false;
|
|
|
|
int m_minimumX = 0;
|
|
|
|
bool m_minimumYRelevant = false;
|
|
|
|
int m_minimumY = 0;
|
|
|
|
bool m_maximumXRelevant = false;
|
|
|
|
int m_maximumX = 0;
|
|
|
|
bool m_maximumYRelevant = false;
|
|
|
|
int m_maximumY = 0;
|
|
|
|
bool m_minimumDeltaRelevant = false;
|
|
|
|
QSizeF m_minimumDelta;
|
2017-03-18 10:00:30 +00:00
|
|
|
};
|
|
|
|
|
2017-03-22 20:03:04 +00:00
|
|
|
class KWIN_EXPORT GestureRecognizer : public QObject
|
2017-03-18 10:00:30 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
GestureRecognizer(QObject *parent = nullptr);
|
|
|
|
~GestureRecognizer() override;
|
|
|
|
|
|
|
|
void registerGesture(Gesture *gesture);
|
|
|
|
void unregisterGesture(Gesture *gesture);
|
|
|
|
|
2017-03-19 10:40:03 +00:00
|
|
|
int startSwipeGesture(uint fingerCount) {
|
|
|
|
return startSwipeGesture(fingerCount, QPointF(), StartPositionBehavior::Irrelevant);
|
|
|
|
}
|
|
|
|
int startSwipeGesture(const QPointF &startPos) {
|
|
|
|
return startSwipeGesture(1, startPos, StartPositionBehavior::Relevant);
|
|
|
|
}
|
2017-03-18 10:00:30 +00:00
|
|
|
void updateSwipeGesture(const QSizeF &delta);
|
|
|
|
void cancelSwipeGesture();
|
|
|
|
void endSwipeGesture();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void cancelActiveSwipeGestures();
|
2017-03-19 10:40:03 +00:00
|
|
|
enum class StartPositionBehavior {
|
|
|
|
Relevant,
|
|
|
|
Irrelevant
|
|
|
|
};
|
|
|
|
int startSwipeGesture(uint fingerCount, const QPointF &startPos, StartPositionBehavior startPosBehavior);
|
2017-03-18 10:00:30 +00:00
|
|
|
QVector<Gesture*> m_gestures;
|
|
|
|
QVector<Gesture*> m_activeSwipeGestures;
|
|
|
|
QMap<Gesture*, QMetaObject::Connection> m_destroyConnections;
|
|
|
|
QVector<QSizeF> m_swipeUpdates;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(KWin::SwipeGesture::Direction)
|
|
|
|
|
|
|
|
#endif
|