-
Notifications
You must be signed in to change notification settings - Fork 6
/
globalgesture.cpp
155 lines (134 loc) · 4.1 KB
/
globalgesture.cpp
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
/*
KWin - the KDE window manager
This file is part of the KDE project.
SPDX-FileCopyrightText: 2020 guoxiang yang <[email protected]>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "globalgesture.h"
#include "globalgesturetypes.h"
#include <QDebug>
#include <QTimer>
#include <QSizeF>
#include <QDBusInterface>
#include "screenedge.h"
#include "input.h"
#include "abstract_client.h"
#include "wayland_server.h"
#include "workspace.h"
#include "screens.h"
#include "taskmanager.h"
#include "effects.h"
namespace KWin {
extern KWINEFFECTS_EXPORT EffectsHandler* effects;
GlobalGesture* GlobalGesture::_self = new GlobalGesture();
const QDataStream::Version QDATA_STREAM_VERSION = QDataStream::Qt_5_14;
GlobalGesture::GlobalGesture(QObject *parent)
: QObject(parent)
{
}
void GlobalGesture::init(int pid)
{
Q_UNUSED(pid)
}
void GlobalGesture::pinchGestureBegin(int fingerCount, quint32 time)
{
Q_UNUSED(fingerCount)
Q_UNUSED(time)
}
void GlobalGesture::pinchGestureUpdate(qreal scale, qreal angleDelta, const QSizeF &delta, quint32 time)
{
Q_UNUSED(scale)
Q_UNUSED(angleDelta)
Q_UNUSED(delta)
Q_UNUSED(time)
}
void GlobalGesture::pinchGestureEnd(quint32 time)
{
Q_UNUSED(time)
}
void GlobalGesture::pinchGestureCancelled(quint32 time)
{
Q_UNUSED(time)
}
void GlobalGesture::swipeGestureBegin(int fingerCount, quint32 time, bool isTouch)
{
Q_UNUSED(isTouch);
if (fingerCount == 3) {
_swipeTime = time;
_swipeStarted = true;
_lastSpead = QSize(0., 0.);
_progress = 0.;
_upGesture = false;
taskManager->setTaskState(TaskManager::TS_Prepare);
} else if (fingerCount == 4) {
_screenShotStart = true;
}
}
void GlobalGesture::swipeGestureUpdate(const QSizeF &delta, quint32 time, bool isTouch)
{
Q_UNUSED(isTouch);
if (_swipeStarted) {
_swipeDelta += delta;
if (time != _swipeTime) {
_lastSpead = delta / (time - _swipeTime);
}
_swipeTime = time;
// _progress = std::abs(_swipeDelta.height())/(screens()->size(0).height() - 50);
// taskManager->updateMove(delta, std::abs(_swipeDelta.height())/(screens()->size(0).height() - 50));
_swipeDelta -= delta;
qreal limitation = 140;
if(_swipeDelta.height() + delta.height()>=limitation) {
_swipeDelta.setHeight(limitation);
QSize d(delta.width(), limitation-_swipeDelta.height());
taskManager->updateMove(d, limitation/(screens()->size(0).height() - 50));
} else {
_swipeDelta += delta;
_progress = std::abs(_swipeDelta.height())/(screens()->size(0).height() - 50);
taskManager->updateMove(delta, _progress);
}
} else if (_screenShotStart) {
_swipeDelta += delta;
if(_swipeDelta.height()>400) {
takeScreenShot();
_screenShotStart = false;
_swipeDelta = QSizeF(0.0f, 0.0f);
}
}
}
void GlobalGesture::swipeGestureEnd(quint32 time, bool isTouch)
{
Q_UNUSED(time);
Q_UNUSED(isTouch)
if (_swipeStarted) {
taskManager->onGestueEnd(_swipeDelta, _lastSpead);
_swipeStarted = false;
}
_screenShotStart = false;
_swipeDelta = QSizeF(0.0f, 0.0f);
_swipeTime = 0;
_progress = 0.;
}
void GlobalGesture::takeScreenShot()
{
QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/org/jingos/screenshot"), QStringLiteral("org.jingos.screenshot"), QStringLiteral("screenshot"));
QDBusConnection::sessionBus().send(message);
}
void GlobalGesture::minimumWindow()
{
if (nullptr != Workspace::self() && nullptr != Workspace::self()->activeClient()&& waylandServer() && !waylandServer()->isScreenLocked()) {
Workspace::self()->activeClient()->minimize(false);
}
}
void GlobalGesture::swipeGestureCancelled(quint32 time, bool isTouch)
{
Q_UNUSED(time)
Q_UNUSED(isTouch)
if (_swipeStarted) {
taskManager->onGestueEnd(_swipeDelta, _lastSpead);
_swipeStarted = false;
}
_screenShotStart = false;
_swipeDelta = QSizeF(0.0f, 0.0f);
_swipeTime = 0;
}
}