File indexing completed on 2024-11-10 04:57:17
0001 /* 0002 SPDX-FileCopyrightText: 2023 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "gesturehandler.h" 0008 #include "effect/effecthandler.h" 0009 0010 #include <QAction> 0011 0012 #include <functional> 0013 0014 namespace KWin 0015 { 0016 0017 SwipeGestureHandler::SwipeGestureHandler(QObject *parent) 0018 : QObject(parent) 0019 { 0020 } 0021 0022 void SwipeGestureHandler::classBegin() 0023 { 0024 } 0025 0026 void SwipeGestureHandler::componentComplete() 0027 { 0028 m_action = new QAction(this); 0029 connect(m_action, &QAction::triggered, this, &SwipeGestureHandler::activated); 0030 0031 std::function<void (EffectsHandler *, SwipeDirection dir, uint fingerCount, QAction *onUp, std::function<void(qreal)> progressCallback)> registrator; 0032 switch (m_deviceType) { 0033 case Device::Touchpad: 0034 registrator = std::mem_fn(&EffectsHandler::registerTouchpadSwipeShortcut); 0035 break; 0036 case Device::Touchscreen: 0037 registrator = std::mem_fn(&EffectsHandler::registerTouchscreenSwipeShortcut); 0038 break; 0039 } 0040 0041 registrator(effects, SwipeDirection(m_direction), m_fingerCount, m_action, [this](qreal progress) { 0042 setProgress(progress); 0043 }); 0044 } 0045 0046 SwipeGestureHandler::Direction SwipeGestureHandler::direction() const 0047 { 0048 return m_direction; 0049 } 0050 0051 void SwipeGestureHandler::setDirection(Direction direction) 0052 { 0053 if (m_direction != direction) { 0054 m_direction = direction; 0055 Q_EMIT directionChanged(); 0056 } 0057 } 0058 0059 int SwipeGestureHandler::fingerCount() const 0060 { 0061 return m_fingerCount; 0062 } 0063 0064 void SwipeGestureHandler::setFingerCount(int fingerCount) 0065 { 0066 if (m_fingerCount != fingerCount) { 0067 m_fingerCount = fingerCount; 0068 Q_EMIT fingerCountChanged(); 0069 } 0070 } 0071 0072 qreal SwipeGestureHandler::progress() const 0073 { 0074 return m_progress; 0075 } 0076 0077 void SwipeGestureHandler::setProgress(qreal progress) 0078 { 0079 if (m_progress != progress) { 0080 m_progress = progress; 0081 Q_EMIT progressChanged(); 0082 } 0083 } 0084 0085 SwipeGestureHandler::Device SwipeGestureHandler::deviceType() const 0086 { 0087 return m_deviceType; 0088 } 0089 0090 void SwipeGestureHandler::setDeviceType(Device device) 0091 { 0092 if (m_deviceType != device) { 0093 m_deviceType = device; 0094 Q_EMIT deviceTypeChanged(); 0095 } 0096 } 0097 0098 PinchGestureHandler::PinchGestureHandler(QObject *parent) 0099 : QObject(parent) 0100 { 0101 } 0102 0103 void PinchGestureHandler::classBegin() 0104 { 0105 } 0106 0107 void PinchGestureHandler::componentComplete() 0108 { 0109 m_action = new QAction(this); 0110 connect(m_action, &QAction::triggered, this, &PinchGestureHandler::activated); 0111 0112 std::function<void (EffectsHandler *, PinchDirection dir, uint fingerCount, QAction *onUp, std::function<void(qreal)> progressCallback)> registrator; 0113 switch (m_deviceType) { 0114 case Device::Touchpad: 0115 registrator = std::mem_fn(&EffectsHandler::registerTouchpadPinchShortcut); 0116 break; 0117 } 0118 0119 registrator(effects, PinchDirection(m_direction), m_fingerCount, m_action, [this](qreal progress) { 0120 setProgress(progress); 0121 }); 0122 } 0123 0124 PinchGestureHandler::Direction PinchGestureHandler::direction() const 0125 { 0126 return m_direction; 0127 } 0128 0129 void PinchGestureHandler::setDirection(Direction direction) 0130 { 0131 if (m_direction != direction) { 0132 m_direction = direction; 0133 Q_EMIT directionChanged(); 0134 } 0135 } 0136 0137 int PinchGestureHandler::fingerCount() const 0138 { 0139 return m_fingerCount; 0140 } 0141 0142 void PinchGestureHandler::setFingerCount(int fingerCount) 0143 { 0144 if (m_fingerCount != fingerCount) { 0145 m_fingerCount = fingerCount; 0146 Q_EMIT fingerCountChanged(); 0147 } 0148 } 0149 0150 qreal PinchGestureHandler::progress() const 0151 { 0152 return m_progress; 0153 } 0154 0155 void PinchGestureHandler::setProgress(qreal progress) 0156 { 0157 if (m_progress != progress) { 0158 m_progress = progress; 0159 Q_EMIT progressChanged(); 0160 } 0161 } 0162 0163 PinchGestureHandler::Device PinchGestureHandler::deviceType() const 0164 { 0165 return m_deviceType; 0166 } 0167 0168 void PinchGestureHandler::setDeviceType(Device device) 0169 { 0170 if (m_deviceType != device) { 0171 m_deviceType = device; 0172 Q_EMIT deviceTypeChanged(); 0173 } 0174 } 0175 0176 } // namespace KWin 0177 0178 #include "moc_gesturehandler.cpp"