File indexing completed on 2025-02-16 05:03:10
0001 /* 0002 SPDX-FileCopyrightText: 2023 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "effect/globals.h" 0010 0011 #include <QAction> 0012 #include <QObject> 0013 0014 namespace KWin 0015 { 0016 0017 class Effect; 0018 0019 /** 0020 * It's common to have effects that get activated and deactivated. 0021 * This class helps us simplify this process, especially in the cases where we want activation to happen 0022 * progressively, like through a touch our touchpad events. 0023 */ 0024 class KWIN_EXPORT EffectTogglableState : public QObject 0025 { 0026 Q_OBJECT 0027 public: 0028 enum class Status { 0029 Inactive, 0030 Activating, 0031 Deactivating, 0032 Active, 0033 Stopped 0034 }; 0035 Q_ENUM(Status) 0036 0037 /** Constructs the object, passes the effect as the parent. */ 0038 EffectTogglableState(Effect *parent); 0039 0040 bool inProgress() const; 0041 void setInProgress(bool gesture); 0042 0043 qreal partialActivationFactor() const 0044 { 0045 return m_partialActivationFactor; 0046 } 0047 void setPartialActivationFactor(qreal factor); 0048 0049 QAction *activateAction() const 0050 { 0051 return m_activateAction.get(); 0052 } 0053 QAction *deactivateAction() const 0054 { 0055 return m_deactivateAction.get(); 0056 } 0057 QAction *toggleAction() const 0058 { 0059 return m_toggleAction.get(); 0060 } 0061 0062 void activate(); 0063 void deactivate(); 0064 void toggle(); 0065 void stop(); 0066 void setStatus(Status status); 0067 Status status() const 0068 { 0069 return m_status; 0070 } 0071 0072 Q_SIGNALS: 0073 void inProgressChanged(); 0074 void partialActivationFactorChanged(); 0075 void activated(); 0076 void deactivated(); 0077 void statusChanged(Status status); 0078 0079 protected: 0080 std::function<void(qreal progress)> progressCallback(); 0081 std::function<void(qreal progress)> regressCallback(); 0082 void setProgress(qreal progress); 0083 0084 /// regress being the progress when on an active state 0085 void setRegress(qreal regress); 0086 0087 private: 0088 void partialActivate(qreal factor); 0089 void partialDeactivate(qreal factor); 0090 0091 std::unique_ptr<QAction> m_deactivateAction; 0092 std::unique_ptr<QAction> m_activateAction; 0093 std::unique_ptr<QAction> m_toggleAction; 0094 Status m_status = Status::Inactive; 0095 bool m_inProgress = false; 0096 qreal m_partialActivationFactor = 0; 0097 0098 friend class EffectTogglableGesture; 0099 friend class EffectTogglableTouchBorder; 0100 }; 0101 0102 class KWIN_EXPORT EffectTogglableGesture : public QObject 0103 { 0104 public: 0105 /** 0106 * Allows specifying which gestures toggle the state. 0107 * 0108 * The gesture will activate it and once enabled the opposite will disable it back. 0109 * 0110 * @param state the state we care about. This state will become the parent object and will take care to clean it up. 0111 */ 0112 EffectTogglableGesture(EffectTogglableState *state); 0113 0114 void addTouchpadPinchGesture(PinchDirection dir, uint fingerCount); 0115 void addTouchpadSwipeGesture(SwipeDirection dir, uint fingerCount); 0116 void addTouchscreenSwipeGesture(SwipeDirection direction, uint fingerCount); 0117 0118 private: 0119 EffectTogglableState *const m_state; 0120 }; 0121 0122 class KWIN_EXPORT EffectTogglableTouchBorder : public QObject 0123 { 0124 public: 0125 /** 0126 * Allows specifying which boarders get to toggle the state. 0127 * 0128 * @param state the state we care about. This state will become the parent object and will take care to clean it up. 0129 */ 0130 EffectTogglableTouchBorder(EffectTogglableState *state); 0131 ~EffectTogglableTouchBorder(); 0132 0133 void setBorders(const QList<int> &borders); 0134 0135 private: 0136 QList<ElectricBorder> m_touchBorderActivate; 0137 EffectTogglableState *const m_state; 0138 }; 0139 0140 }