forked from ukui/ukui-kwin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gestures.h
227 lines (198 loc) · 5.85 KB
/
gestures.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/********************************************************************
UKUI-KWin - the UKUI3.0 window manager
This file is part of the UKUI project
The ukui-kwin is forked from kwin
Copyright (C) 2014-2020 kylinos.cn
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2017 Martin Gräßlin <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_GESTURES_H
#define KWIN_GESTURES_H
#include <ukui-kwin_export.h>
#include <QObject>
#include <QPointF>
#include <QSizeF>
#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.
* On further evaluation either the signal @ref triggered or
* @ref cancelled will get emitted.
*/
void started();
/**
* Gesture matching ended and this Gesture matched.
*/
void triggered();
/**
* This Gesture no longer matches.
*/
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;
}
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:
/**
* The progress of the gesture if a minimumDelta is set.
* The progress is reported in [0.0,1.0]
*/
void progress(qreal);
private:
bool m_minimumFingerCountRelevant = false;
uint m_minimumFingerCount = 0;
bool m_maximumFingerCountRelevant = false;
uint m_maximumFingerCount = 0;
Direction m_direction = Direction::Down;
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;
};
class UKUI_KWIN_EXPORT GestureRecognizer : public QObject
{
Q_OBJECT
public:
GestureRecognizer(QObject *parent = nullptr);
~GestureRecognizer() override;
void registerGesture(Gesture *gesture);
void unregisterGesture(Gesture *gesture);
int startSwipeGesture(uint fingerCount) {
return startSwipeGesture(fingerCount, QPointF(), StartPositionBehavior::Irrelevant);
}
int startSwipeGesture(const QPointF &startPos) {
return startSwipeGesture(1, startPos, StartPositionBehavior::Relevant);
}
void updateSwipeGesture(const QSizeF &delta);
void cancelSwipeGesture();
void endSwipeGesture();
private:
void cancelActiveSwipeGestures();
enum class StartPositionBehavior {
Relevant,
Irrelevant
};
int startSwipeGesture(uint fingerCount, const QPointF &startPos, StartPositionBehavior startPosBehavior);
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