KWin
Loading...
Searching...
No Matches
gesturehandler.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2023 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "gesturehandler.h"
9
10#include <QAction>
11
12#include <functional>
13
14namespace KWin
15{
16
18 : QObject(parent)
19{
20}
21
25
27{
28 m_action = new QAction(this);
29 connect(m_action, &QAction::triggered, this, &SwipeGestureHandler::activated);
30
31 std::function<void (EffectsHandler *, SwipeDirection dir, uint fingerCount, QAction *onUp, std::function<void(qreal)> progressCallback)> registrator;
32 switch (m_deviceType) {
34 registrator = std::mem_fn(&EffectsHandler::registerTouchpadSwipeShortcut);
35 break;
37 registrator = std::mem_fn(&EffectsHandler::registerTouchscreenSwipeShortcut);
38 break;
39 }
40
41 registrator(effects, SwipeDirection(m_direction), m_fingerCount, m_action, [this](qreal progress) {
43 });
44}
45
50
52{
53 if (m_direction != direction) {
54 m_direction = direction;
55 Q_EMIT directionChanged();
56 }
57}
58
60{
61 return m_fingerCount;
62}
63
65{
66 if (m_fingerCount != fingerCount) {
67 m_fingerCount = fingerCount;
68 Q_EMIT fingerCountChanged();
69 }
70}
71
73{
74 return m_progress;
75}
76
78{
79 if (m_progress != progress) {
80 m_progress = progress;
81 Q_EMIT progressChanged();
82 }
83}
84
86{
87 return m_deviceType;
88}
89
91{
92 if (m_deviceType != device) {
93 m_deviceType = device;
94 Q_EMIT deviceTypeChanged();
95 }
96}
97
99 : QObject(parent)
100{
101}
102
106
108{
109 m_action = new QAction(this);
110 connect(m_action, &QAction::triggered, this, &PinchGestureHandler::activated);
111
112 std::function<void (EffectsHandler *, PinchDirection dir, uint fingerCount, QAction *onUp, std::function<void(qreal)> progressCallback)> registrator;
113 switch (m_deviceType) {
114 case Device::Touchpad:
115 registrator = std::mem_fn(&EffectsHandler::registerTouchpadPinchShortcut);
116 break;
117 }
118
119 registrator(effects, PinchDirection(m_direction), m_fingerCount, m_action, [this](qreal progress) {
121 });
122}
123
125{
126 return m_direction;
127}
128
130{
131 if (m_direction != direction) {
132 m_direction = direction;
133 Q_EMIT directionChanged();
134 }
135}
136
138{
139 return m_fingerCount;
140}
141
143{
144 if (m_fingerCount != fingerCount) {
145 m_fingerCount = fingerCount;
146 Q_EMIT fingerCountChanged();
147 }
148}
149
151{
152 return m_progress;
153}
154
156{
157 if (m_progress != progress) {
158 m_progress = progress;
159 Q_EMIT progressChanged();
160 }
161}
162
164{
165 return m_deviceType;
166}
167
169{
170 if (m_deviceType != device) {
171 m_deviceType = device;
172 Q_EMIT deviceTypeChanged();
173 }
174}
175
176} // namespace KWin
177
178#include "moc_gesturehandler.cpp"
Manager class that handles all the effects.
void registerTouchpadPinchShortcut(PinchDirection dir, uint fingerCount, QAction *onUp, std::function< void(qreal)> progressCallback={})
void registerTouchpadSwipeShortcut(SwipeDirection dir, uint fingerCount, QAction *onUp, std::function< void(qreal)> progressCallback={})
Registers a global touchpad swipe gesture shortcut with the provided action.
void registerTouchscreenSwipeShortcut(SwipeDirection direction, uint fingerCount, QAction *action, std::function< void(qreal)> progressCallback)
Registers a global touchscreen swipe gesture shortcut with the provided action.
PinchGestureHandler(QObject *parent=nullptr)
void setDirection(Direction direction)
void componentComplete() override
void setDeviceType(Device device)
void setFingerCount(int fingerCount)
void setProgress(qreal progress)
void setFingerCount(int fingerCount)
SwipeGestureHandler(QObject *parent=nullptr)
void setDeviceType(Device device)
void setProgress(qreal progress)
void setDirection(Direction direction)
void componentComplete() override
PinchDirection
Definition globals.h:123
SwipeDirection
Directions for swipe gestures.
Definition globals.h:115
EffectsHandler * effects