Rename TogglableState -> EffectTogglableState

This commit is contained in:
Aleix Pol 2023-05-09 22:19:33 +02:00 committed by Aleix Pol Gonzalez
parent ad68d6860e
commit 33c3a60aa7
7 changed files with 64 additions and 64 deletions

View file

@ -19,7 +19,7 @@ set(kwin_EFFECTSLIB_SRCS
logging.cpp
rendertarget.cpp
renderviewport.cpp
togglablestate.cpp
effecttogglablestate.cpp
)
add_library(kwineffects SHARED ${kwin_EFFECTSLIB_SRCS})

View file

@ -4,13 +4,13 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "togglablestate.h"
#include "effecttogglablestate.h"
#include "kwineffects.h"
namespace KWin
{
TogglableState::TogglableState(Effect *effect)
EffectTogglableState::EffectTogglableState(Effect *effect)
: QObject(effect)
, m_deactivateAction(std::make_unique<QAction>())
, m_activateAction(std::make_unique<QAction>())
@ -38,17 +38,17 @@ TogglableState::TogglableState(Effect *effect)
}
}
});
connect(m_toggleAction.get(), &QAction::triggered, this, &TogglableState::toggle);
connect(m_toggleAction.get(), &QAction::triggered, this, &EffectTogglableState::toggle);
}
void TogglableState::activate()
void EffectTogglableState::activate()
{
setStatus(Status::Active);
setInProgress(false);
setPartialActivationFactor(0.0);
}
void TogglableState::setPartialActivationFactor(qreal factor)
void EffectTogglableState::setPartialActivationFactor(qreal factor)
{
if (m_partialActivationFactor != factor) {
m_partialActivationFactor = factor;
@ -56,18 +56,18 @@ void TogglableState::setPartialActivationFactor(qreal factor)
}
}
void TogglableState::deactivate()
void EffectTogglableState::deactivate()
{
setInProgress(false);
setPartialActivationFactor(0.0);
}
bool TogglableState::inProgress() const
bool EffectTogglableState::inProgress() const
{
return m_inProgress;
}
void TogglableState::setInProgress(bool gesture)
void EffectTogglableState::setInProgress(bool gesture)
{
if (m_inProgress != gesture) {
m_inProgress = gesture;
@ -75,7 +75,7 @@ void TogglableState::setInProgress(bool gesture)
}
}
void TogglableState::setStatus(Status status)
void EffectTogglableState::setStatus(Status status)
{
if (m_status != status) {
m_status = status;
@ -83,7 +83,7 @@ void TogglableState::setStatus(Status status)
}
}
void TogglableState::partialActivate(qreal factor)
void EffectTogglableState::partialActivate(qreal factor)
{
if (effects->isScreenLocked()) {
return;
@ -94,14 +94,14 @@ void TogglableState::partialActivate(qreal factor)
setInProgress(true);
}
void TogglableState::partialDeactivate(qreal factor)
void EffectTogglableState::partialDeactivate(qreal factor)
{
setStatus(Status::Deactivating);
setPartialActivationFactor(1.0 - factor);
setInProgress(true);
}
void TogglableState::toggle()
void EffectTogglableState::toggle()
{
if (m_status == Status::Inactive || m_partialActivationFactor > 0.5) {
activate();
@ -112,7 +112,7 @@ void TogglableState::toggle()
}
}
void TogglableState::setProgress(qreal progress)
void EffectTogglableState::setProgress(qreal progress)
{
if (!effects->hasActiveFullScreenEffect() || effects->activeFullScreenEffect() == parent()) {
switch (m_status) {
@ -126,7 +126,7 @@ void TogglableState::setProgress(qreal progress)
}
}
void TogglableState::setRegress(qreal regress)
void EffectTogglableState::setRegress(qreal regress)
{
if (!effects->hasActiveFullScreenEffect() || effects->activeFullScreenEffect() == parent()) {
switch (m_status) {
@ -140,7 +140,7 @@ void TogglableState::setRegress(qreal regress)
}
}
TogglableGesture::TogglableGesture(TogglableState *state)
EffectTogglableGesture::EffectTogglableGesture(EffectTogglableState *state)
: QObject(state)
, m_state(state)
{
@ -174,52 +174,52 @@ static SwipeDirection opposite(SwipeDirection direction)
return SwipeDirection::Invalid;
}
std::function<void(qreal progress)> TogglableState::progressCallback()
std::function<void(qreal progress)> EffectTogglableState::progressCallback()
{
return [this](qreal progress) {
setProgress(progress);
};
}
std::function<void(qreal progress)> TogglableState::regressCallback()
std::function<void(qreal progress)> EffectTogglableState::regressCallback()
{
return [this](qreal progress) {
setRegress(progress);
};
}
void TogglableGesture::addTouchpadPinchGesture(PinchDirection direction, uint fingerCount)
void EffectTogglableGesture::addTouchpadPinchGesture(PinchDirection direction, uint fingerCount)
{
effects->registerTouchpadPinchShortcut(direction, fingerCount, m_state->activateAction(), m_state->progressCallback());
effects->registerTouchpadPinchShortcut(opposite(direction), fingerCount, m_state->deactivateAction(), m_state->regressCallback());
}
void TogglableGesture::addTouchpadSwipeGesture(SwipeDirection direction, uint fingerCount)
void EffectTogglableGesture::addTouchpadSwipeGesture(SwipeDirection direction, uint fingerCount)
{
effects->registerTouchpadSwipeShortcut(direction, fingerCount, m_state->activateAction(), m_state->progressCallback());
effects->registerTouchpadSwipeShortcut(opposite(direction), fingerCount, m_state->deactivateAction(), m_state->regressCallback());
}
void TogglableGesture::addTouchscreenSwipeGesture(SwipeDirection direction, uint fingerCount)
void EffectTogglableGesture::addTouchscreenSwipeGesture(SwipeDirection direction, uint fingerCount)
{
effects->registerTouchscreenSwipeShortcut(direction, fingerCount, m_state->activateAction(), m_state->progressCallback());
effects->registerTouchscreenSwipeShortcut(opposite(direction), fingerCount, m_state->deactivateAction(), m_state->regressCallback());
}
TogglableTouchBorder::TogglableTouchBorder(TogglableState *state)
EffectTogglableTouchBorder::EffectTogglableTouchBorder(EffectTogglableState *state)
: QObject(state)
, m_state(state)
{
}
TogglableTouchBorder::~TogglableTouchBorder()
EffectTogglableTouchBorder::~EffectTogglableTouchBorder()
{
for (const ElectricBorder &border : std::as_const(m_touchBorderActivate)) {
effects->unregisterTouchBorder(border, m_state->toggleAction());
}
}
void TogglableTouchBorder::setBorders(const QList<int> &touchActivateBorders)
void EffectTogglableTouchBorder::setBorders(const QList<int> &touchActivateBorders)
{
for (const ElectricBorder &border : std::as_const(m_touchBorderActivate)) {
effects->unregisterTouchBorder(border, m_state->toggleAction());
@ -229,7 +229,7 @@ void TogglableTouchBorder::setBorders(const QList<int> &touchActivateBorders)
for (const int &border : touchActivateBorders) {
m_touchBorderActivate.append(ElectricBorder(border));
effects->registerRealtimeTouchBorder(ElectricBorder(border), m_state->toggleAction(), [this](ElectricBorder border, const QPointF &deltaProgress, const EffectScreen *screen) {
if (m_state->status() == TogglableState::Status::Active) {
if (m_state->status() == EffectTogglableState::Status::Active) {
return;
}
const int maxDelta = 500; // Arbitrary logical pixels value seems to behave better than scaledScreenSize

View file

@ -16,7 +16,7 @@ namespace KWin
class Effect;
class KWINEFFECTS_EXPORT TogglableState : public QObject
class KWINEFFECTS_EXPORT EffectTogglableState : public QObject
{
Q_OBJECT
public:
@ -28,7 +28,7 @@ public:
};
Q_ENUM(Status);
TogglableState(Effect *parent);
EffectTogglableState(Effect *parent);
bool inProgress() const;
void setInProgress(bool gesture);
@ -87,34 +87,34 @@ private:
bool m_inProgress = false;
qreal m_partialActivationFactor = 0;
friend class TogglableGesture;
friend class TogglableTouchBorder;
friend class EffectTogglableGesture;
friend class EffectTogglableTouchBorder;
};
class KWINEFFECTS_EXPORT TogglableGesture : public QObject
class KWINEFFECTS_EXPORT EffectTogglableGesture : public QObject
{
public:
TogglableGesture(TogglableState *state);
EffectTogglableGesture(EffectTogglableState *state);
void addTouchpadPinchGesture(PinchDirection dir, uint fingerCount);
void addTouchpadSwipeGesture(SwipeDirection dir, uint fingerCount);
void addTouchscreenSwipeGesture(SwipeDirection direction, uint fingerCount);
private:
TogglableState *const m_state;
EffectTogglableState *const m_state;
};
class KWINEFFECTS_EXPORT TogglableTouchBorder : public QObject
class KWINEFFECTS_EXPORT EffectTogglableTouchBorder : public QObject
{
public:
TogglableTouchBorder(TogglableState *state);
~TogglableTouchBorder();
EffectTogglableTouchBorder(EffectTogglableState *state);
~EffectTogglableTouchBorder();
void setBorders(const QList<int> &borders);
private:
QList<ElectricBorder> m_touchBorderActivate;
TogglableState *const m_state;
EffectTogglableState *const m_state;
};
}

View file

@ -20,8 +20,8 @@ namespace KWin
DesktopGridEffect::DesktopGridEffect()
: m_shutdownTimer(new QTimer(this))
, m_state(new TogglableState(this))
, m_border(new TogglableTouchBorder(m_state))
, m_state(new EffectTogglableState(this))
, m_border(new EffectTogglableTouchBorder(m_state))
{
qmlRegisterUncreatableType<DesktopGridEffect>("org.kde.kwin.private.desktopgrid", 1, 0, "DesktopGridEffect", QStringLiteral("Cannot create elements of type DesktopGridEffect"));
@ -30,12 +30,12 @@ DesktopGridEffect::DesktopGridEffect()
connect(effects, &EffectsHandler::screenAboutToLock, this, &DesktopGridEffect::realDeactivate);
connect(effects, &EffectsHandler::desktopGridWidthChanged, this, &DesktopGridEffect::gridColumnsChanged);
connect(effects, &EffectsHandler::desktopGridHeightChanged, this, &DesktopGridEffect::gridRowsChanged);
connect(m_state, &TogglableState::activated, this, &DesktopGridEffect::activate);
connect(m_state, &TogglableState::deactivated, this, &DesktopGridEffect::deactivate);
connect(m_state, &TogglableState::inProgressChanged, this, &DesktopGridEffect::gestureInProgressChanged);
connect(m_state, &TogglableState::partialActivationFactorChanged, this, &DesktopGridEffect::partialActivationFactorChanged);
connect(m_state, &TogglableState::statusChanged, this, [this](TogglableState::Status status) {
setRunning(status != TogglableState::Status::Inactive);
connect(m_state, &EffectTogglableState::activated, this, &DesktopGridEffect::activate);
connect(m_state, &EffectTogglableState::deactivated, this, &DesktopGridEffect::deactivate);
connect(m_state, &EffectTogglableState::inProgressChanged, this, &DesktopGridEffect::gestureInProgressChanged);
connect(m_state, &EffectTogglableState::partialActivationFactorChanged, this, &DesktopGridEffect::partialActivationFactorChanged);
connect(m_state, &EffectTogglableState::statusChanged, this, [this](EffectTogglableState::Status status) {
setRunning(status != EffectTogglableState::Status::Inactive);
});
auto toggleAction = m_state->toggleAction();
@ -45,7 +45,7 @@ DesktopGridEffect::DesktopGridEffect()
KGlobalAccel::self()->setShortcut(toggleAction, QList<QKeySequence>() << (Qt::META | Qt::Key_F8));
m_toggleShortcut = KGlobalAccel::self()->shortcut(toggleAction);
auto gesture = new TogglableGesture(m_state);
auto gesture = new EffectTogglableGesture(m_state);
gesture->addTouchpadSwipeGesture(SwipeDirection::Up, 4);
initConfig<DesktopGridConfig>();
@ -242,7 +242,7 @@ void DesktopGridEffect::deactivate()
void DesktopGridEffect::realDeactivate()
{
m_state->setStatus(TogglableState::Status::Inactive);
m_state->setStatus(EffectTogglableState::Status::Inactive);
}
} // namespace KWin

View file

@ -6,8 +6,8 @@
#pragma once
#include "libkwineffects/effecttogglablestate.h"
#include "libkwineffects/kwinquickeffect.h"
#include "libkwineffects/togglablestate.h"
namespace KWin
{
@ -90,8 +90,8 @@ private:
QTimer *m_shutdownTimer;
QList<QKeySequence> m_toggleShortcut;
QList<ElectricBorder> m_borderActivate;
TogglableState *const m_state;
TogglableTouchBorder *const m_border;
EffectTogglableState *const m_state;
EffectTogglableTouchBorder *const m_border;
int m_animationDuration = 400;
int m_layout = 1;
};

View file

@ -19,23 +19,23 @@ namespace KWin
{
OverviewEffect::OverviewEffect()
: m_state(new TogglableState(this))
, m_border(new TogglableTouchBorder(m_state))
: m_state(new EffectTogglableState(this))
, m_border(new EffectTogglableTouchBorder(m_state))
, m_shutdownTimer(new QTimer(this))
{
auto gesture = new TogglableGesture(m_state);
auto gesture = new EffectTogglableGesture(m_state);
gesture->addTouchpadPinchGesture(PinchDirection::Contracting, 4);
gesture->addTouchscreenSwipeGesture(SwipeDirection::Up, 3);
connect(m_state, &TogglableState::activated, this, &OverviewEffect::activate);
connect(m_state, &TogglableState::deactivated, this, &OverviewEffect::deactivate);
connect(m_state, &TogglableState::inProgressChanged, this, &OverviewEffect::gestureInProgressChanged);
connect(m_state, &TogglableState::partialActivationFactorChanged, this, &OverviewEffect::partialActivationFactorChanged);
connect(m_state, &TogglableState::statusChanged, this, [this](TogglableState::Status status) {
if (status == TogglableState::Status::Activating) {
connect(m_state, &EffectTogglableState::activated, this, &OverviewEffect::activate);
connect(m_state, &EffectTogglableState::deactivated, this, &OverviewEffect::deactivate);
connect(m_state, &EffectTogglableState::inProgressChanged, this, &OverviewEffect::gestureInProgressChanged);
connect(m_state, &EffectTogglableState::partialActivationFactorChanged, this, &OverviewEffect::partialActivationFactorChanged);
connect(m_state, &EffectTogglableState::statusChanged, this, [this](EffectTogglableState::Status status) {
if (status == EffectTogglableState::Status::Activating) {
m_searchText = QString();
}
setRunning(status != TogglableState::Status::Inactive);
setRunning(status != EffectTogglableState::Status::Inactive);
});
m_shutdownTimer->setSingleShot(true);
@ -43,7 +43,7 @@ OverviewEffect::OverviewEffect()
const QKeySequence defaultToggleShortcut = Qt::META | Qt::Key_W;
auto toggleAction = m_state->toggleAction();
connect(toggleAction, &QAction::triggered, m_state, &TogglableState::toggle);
connect(toggleAction, &QAction::triggered, m_state, &EffectTogglableState::toggle);
toggleAction->setObjectName(QStringLiteral("Overview"));
toggleAction->setText(i18n("Toggle Overview"));
KGlobalAccel::self()->setDefaultShortcut(toggleAction, {defaultToggleShortcut});
@ -152,7 +152,7 @@ void OverviewEffect::deactivate()
void OverviewEffect::realDeactivate()
{
m_state->setStatus(TogglableState::Status::Inactive);
m_state->setStatus(EffectTogglableState::Status::Inactive);
}
void OverviewEffect::grabbedKeyboardEvent(QKeyEvent *keyEvent)

View file

@ -6,8 +6,8 @@
#pragma once
#include "libkwineffects/effecttogglablestate.h"
#include "libkwineffects/kwinquickeffect.h"
#include "libkwineffects/togglablestate.h"
namespace KWin
{
@ -65,8 +65,8 @@ public Q_SLOTS:
private:
void realDeactivate();
TogglableState *const m_state;
TogglableTouchBorder *const m_border;
EffectTogglableState *const m_state;
EffectTogglableTouchBorder *const m_border;
QTimer *m_shutdownTimer;
QList<QKeySequence> m_toggleShortcut;