mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-08-01 09:18:07 +00:00
taskswitcher: Port to EffectTogglableState
This commit is contained in:
parent
335ae705ca
commit
a3cd470efc
3 changed files with 45 additions and 141 deletions
|
|
@ -15,56 +15,38 @@ namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
MobileTaskSwitcherEffect::MobileTaskSwitcherEffect()
|
MobileTaskSwitcherEffect::MobileTaskSwitcherEffect()
|
||||||
: m_shutdownTimer(new QTimer(this))
|
: m_taskSwitcherState{new EffectTogglableState(this)}
|
||||||
|
, m_border{new EffectTogglableTouchBorder{m_taskSwitcherState}}
|
||||||
|
, m_shutdownTimer{new QTimer{this}}
|
||||||
{
|
{
|
||||||
m_shutdownTimer->setSingleShot(true);
|
auto gesture = new EffectTogglableGesture{m_taskSwitcherState};
|
||||||
connect(m_shutdownTimer, &QTimer::timeout, this, &MobileTaskSwitcherEffect::realDeactivate);
|
gesture->addTouchpadSwipeGesture(SwipeDirection::Up, 3);
|
||||||
|
gesture->addTouchscreenSwipeGesture(SwipeDirection::Up, 1);
|
||||||
|
|
||||||
const QKeySequence defaultToggleShortcut = Qt::META | Qt::Key_C;
|
connect(m_taskSwitcherState, &EffectTogglableState::inProgressChanged, this, &MobileTaskSwitcherEffect::gestureInProgressChanged);
|
||||||
|
connect(m_taskSwitcherState, &EffectTogglableState::partialActivationFactorChanged, this, &MobileTaskSwitcherEffect::partialActivationFactorChanged);
|
||||||
m_toggleAction = new QAction(this);
|
connect(m_taskSwitcherState, &EffectTogglableState::statusChanged, this, [this](EffectTogglableState::Status status) {
|
||||||
m_toggleAction->setObjectName(QStringLiteral("Mobile Task Switcher"));
|
if (status == EffectTogglableState::Status::Activating || status == EffectTogglableState::Status::Active) {
|
||||||
m_toggleAction->setText(i18n("Toggle Mobile Task Switcher"));
|
setRunning(true);
|
||||||
|
setDBusState(true);
|
||||||
connect(m_toggleAction, &QAction::triggered, this, &MobileTaskSwitcherEffect::toggle);
|
}
|
||||||
|
if (status == EffectTogglableState::Status::Inactive) {
|
||||||
KGlobalAccel::self()->setDefaultShortcut(m_toggleAction, {defaultToggleShortcut});
|
deactivate(true);
|
||||||
KGlobalAccel::self()->setShortcut(m_toggleAction, {defaultToggleShortcut});
|
|
||||||
|
|
||||||
m_realtimeToggleAction = new QAction(this);
|
|
||||||
connect(m_realtimeToggleAction, &QAction::triggered, this, [this]() {
|
|
||||||
if (m_status == Status::Deactivating) {
|
|
||||||
if (m_partialActivationFactor < 0.5) {
|
|
||||||
deactivate(false);
|
|
||||||
} else {
|
|
||||||
cancelPartialDeactivate();
|
|
||||||
}
|
|
||||||
} else if (m_status == Status::Activating) {
|
|
||||||
if (m_partialActivationFactor > 0.5) {
|
|
||||||
activate();
|
|
||||||
} else {
|
|
||||||
cancelPartialActivate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
auto progressCallback = [this](qreal progress) {
|
// configure close timer
|
||||||
if (!effects->hasActiveFullScreenEffect() || effects->activeFullScreenEffect() == this) {
|
m_shutdownTimer->setSingleShot(true);
|
||||||
switch (m_status) {
|
connect(m_shutdownTimer, &QTimer::timeout, this, &MobileTaskSwitcherEffect::realDeactivate);
|
||||||
case Status::Inactive:
|
|
||||||
case Status::Activating:
|
|
||||||
partialActivate(progress);
|
|
||||||
break;
|
|
||||||
case Status::Active:
|
|
||||||
case Status::Deactivating:
|
|
||||||
partialDeactivate(progress);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
effects->registerTouchpadPinchShortcut(PinchDirection::Contracting, 4, m_realtimeToggleAction, progressCallback);
|
// toggle action
|
||||||
effects->registerTouchscreenSwipeShortcut(SwipeDirection::Up, 3, m_realtimeToggleAction, progressCallback);
|
const QKeySequence defaultToggleShortcut = Qt::META | Qt::Key_C;
|
||||||
|
|
||||||
|
auto toggleAction = m_taskSwitcherState->toggleAction();
|
||||||
|
toggleAction->setObjectName(QStringLiteral("Mobile Task Switcher"));
|
||||||
|
toggleAction->setText(i18n("Toggle Mobile Task Switcher"));
|
||||||
|
KGlobalAccel::self()->setDefaultShortcut(toggleAction, {defaultToggleShortcut});
|
||||||
|
KGlobalAccel::self()->setShortcut(toggleAction, {defaultToggleShortcut});
|
||||||
|
|
||||||
connect(effects, &EffectsHandler::screenAboutToLock, this, &MobileTaskSwitcherEffect::realDeactivate);
|
connect(effects, &EffectsHandler::screenAboutToLock, this, &MobileTaskSwitcherEffect::realDeactivate);
|
||||||
|
|
||||||
|
|
@ -84,36 +66,13 @@ void MobileTaskSwitcherEffect::reconfigure(ReconfigureFlags)
|
||||||
effects->unreserveElectricBorder(border, this);
|
effects->unreserveElectricBorder(border, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const ElectricBorder &border : std::as_const(m_touchBorderActivate)) {
|
|
||||||
effects->unregisterTouchBorder(border, m_toggleAction);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_borderActivate.clear();
|
m_borderActivate.clear();
|
||||||
m_touchBorderActivate.clear();
|
|
||||||
|
|
||||||
const QList<int> activateBorders = {ElectricBorder::ElectricBottom};
|
const QList<int> activateBorders = {ElectricBorder::ElectricBottom};
|
||||||
for (const int &border : activateBorders) {
|
for (const int &border : activateBorders) {
|
||||||
m_borderActivate.append(ElectricBorder(border));
|
m_borderActivate.append(ElectricBorder(border));
|
||||||
effects->reserveElectricBorder(ElectricBorder(border), this);
|
effects->reserveElectricBorder(ElectricBorder(border), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QList<int> touchActivateBorders = {ElectricBorder::ElectricBottom};
|
|
||||||
for (const int &border : touchActivateBorders) {
|
|
||||||
m_touchBorderActivate.append(ElectricBorder(border));
|
|
||||||
effects->registerRealtimeTouchBorder(ElectricBorder(border),
|
|
||||||
m_realtimeToggleAction,
|
|
||||||
[this](ElectricBorder border, const QPointF &deltaProgress, const Output *screen) {
|
|
||||||
if (m_status == Status::Active) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const int maxDelta = 500; // Arbitrary logical pixels value seems to behave better than scaledScreenSize
|
|
||||||
if (border == ElectricTop || border == ElectricBottom) {
|
|
||||||
partialActivate(std::min(1.0, std::abs(deltaProgress.y()) / maxDelta));
|
|
||||||
} else {
|
|
||||||
partialActivate(std::min(1.0, std::abs(deltaProgress.x()) / maxDelta));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int MobileTaskSwitcherEffect::requestedEffectChainPosition() const
|
int MobileTaskSwitcherEffect::requestedEffectChainPosition() const
|
||||||
|
|
@ -123,6 +82,9 @@ int MobileTaskSwitcherEffect::requestedEffectChainPosition() const
|
||||||
|
|
||||||
bool MobileTaskSwitcherEffect::borderActivated(ElectricBorder border)
|
bool MobileTaskSwitcherEffect::borderActivated(ElectricBorder border)
|
||||||
{
|
{
|
||||||
|
if (m_borderActivate.contains(border)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -152,9 +114,7 @@ void MobileTaskSwitcherEffect::activate()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_status = Status::Active;
|
m_taskSwitcherState->activate();
|
||||||
setRunning(true);
|
|
||||||
setDBusState(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MobileTaskSwitcherEffect::deactivate(bool deactivateInstantly)
|
void MobileTaskSwitcherEffect::deactivate(bool deactivateInstantly)
|
||||||
|
|
@ -166,49 +126,15 @@ void MobileTaskSwitcherEffect::deactivate(bool deactivateInstantly)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_shutdownTimer->start(animationTime(deactivateInstantly ? 0 : 200));
|
m_shutdownTimer->start(animationTime(deactivateInstantly ? 0 : 200));
|
||||||
|
|
||||||
setGestureInProgress(false);
|
|
||||||
setPartialActivationFactor(0.0);
|
|
||||||
|
|
||||||
setDBusState(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MobileTaskSwitcherEffect::partialActivate(qreal factor)
|
|
||||||
{
|
|
||||||
if (effects->isScreenLocked()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_status = Status::Activating;
|
|
||||||
|
|
||||||
setPartialActivationFactor(factor);
|
|
||||||
setGestureInProgress(true);
|
|
||||||
|
|
||||||
setRunning(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MobileTaskSwitcherEffect::partialDeactivate(qreal factor)
|
|
||||||
{
|
|
||||||
m_status = Status::Deactivating;
|
|
||||||
|
|
||||||
setPartialActivationFactor(1.0 - factor);
|
|
||||||
setGestureInProgress(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MobileTaskSwitcherEffect::cancelPartialDeactivate()
|
|
||||||
{
|
|
||||||
activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MobileTaskSwitcherEffect::cancelPartialActivate()
|
|
||||||
{
|
|
||||||
deactivate(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MobileTaskSwitcherEffect::realDeactivate()
|
void MobileTaskSwitcherEffect::realDeactivate()
|
||||||
{
|
{
|
||||||
setRunning(false);
|
m_taskSwitcherState->deactivate();
|
||||||
m_status = Status::Inactive;
|
if (m_taskSwitcherState->status() == EffectTogglableState::Status::Inactive) {
|
||||||
|
setRunning(false);
|
||||||
|
setDBusState(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MobileTaskSwitcherEffect::quickDeactivate()
|
void MobileTaskSwitcherEffect::quickDeactivate()
|
||||||
|
|
@ -231,29 +157,12 @@ void MobileTaskSwitcherEffect::setAnimationDuration(int duration)
|
||||||
|
|
||||||
bool MobileTaskSwitcherEffect::gestureInProgress() const
|
bool MobileTaskSwitcherEffect::gestureInProgress() const
|
||||||
{
|
{
|
||||||
return m_gestureInProgress;
|
return m_taskSwitcherState->inProgress();
|
||||||
}
|
|
||||||
|
|
||||||
void MobileTaskSwitcherEffect::setGestureInProgress(bool gesture)
|
|
||||||
{
|
|
||||||
if (m_gestureInProgress != gesture) {
|
|
||||||
m_gestureInProgress = gesture;
|
|
||||||
Q_EMIT gestureInProgressChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal MobileTaskSwitcherEffect::partialActivationFactor() const
|
qreal MobileTaskSwitcherEffect::partialActivationFactor() const
|
||||||
{
|
{
|
||||||
return m_partialActivationFactor;
|
return m_taskSwitcherState->partialActivationFactor();
|
||||||
}
|
|
||||||
|
|
||||||
void MobileTaskSwitcherEffect::setPartialActivationFactor(qreal factor)
|
|
||||||
{
|
|
||||||
if (m_partialActivationFactor != factor) {
|
|
||||||
qDebug() << factor;
|
|
||||||
m_partialActivationFactor = factor;
|
|
||||||
Q_EMIT partialActivationFactorChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MobileTaskSwitcherEffect::setDBusState(bool active)
|
void MobileTaskSwitcherEffect::setDBusState(bool active)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
#include <libkwineffects/effects.h>
|
#include <libkwineffects/effects.h>
|
||||||
#include <libkwineffects/quickeffect.h>
|
#include <libkwineffects/quickeffect.h>
|
||||||
|
#include <libkwineffects/effect.h>
|
||||||
|
#include <libkwineffects/effecttogglablestate.h>
|
||||||
|
|
||||||
#include <span>
|
#include <span>
|
||||||
|
|
||||||
|
|
@ -34,10 +36,8 @@ public:
|
||||||
void setAnimationDuration(int duration);
|
void setAnimationDuration(int duration);
|
||||||
|
|
||||||
bool gestureInProgress() const;
|
bool gestureInProgress() const;
|
||||||
void setGestureInProgress(bool gesture);
|
|
||||||
|
|
||||||
qreal partialActivationFactor() const;
|
qreal partialActivationFactor() const;
|
||||||
void setPartialActivationFactor(qreal factor);
|
|
||||||
|
|
||||||
int requestedEffectChainPosition() const override;
|
int requestedEffectChainPosition() const override;
|
||||||
bool borderActivated(ElectricBorder border) override;
|
bool borderActivated(ElectricBorder border) override;
|
||||||
|
|
@ -49,10 +49,6 @@ public:
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void activate();
|
void activate();
|
||||||
void realDeactivate();
|
void realDeactivate();
|
||||||
void partialActivate(qreal factor);
|
|
||||||
void cancelPartialActivate();
|
|
||||||
void partialDeactivate(qreal factor);
|
|
||||||
void cancelPartialDeactivate();
|
|
||||||
void deactivate(bool deactivateInstantly);
|
void deactivate(bool deactivateInstantly);
|
||||||
void quickDeactivate();
|
void quickDeactivate();
|
||||||
void toggle();
|
void toggle();
|
||||||
|
|
@ -63,18 +59,17 @@ Q_SIGNALS:
|
||||||
void partialActivationFactorChanged();
|
void partialActivationFactorChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
EffectTogglableState *const m_taskSwitcherState;
|
||||||
|
EffectTogglableTouchBorder *const m_border;
|
||||||
|
QList<ElectricBorder> m_borderActivate;
|
||||||
|
|
||||||
QAction *m_realtimeToggleAction = nullptr;
|
QAction *m_realtimeToggleAction = nullptr;
|
||||||
QAction *m_toggleAction = nullptr;
|
QAction *m_toggleAction = nullptr;
|
||||||
QList<QKeySequence> m_toggleShortcut;
|
QList<QKeySequence> m_toggleShortcut;
|
||||||
Status m_status = Status::Inactive;
|
|
||||||
;
|
|
||||||
QTimer *m_shutdownTimer;
|
QTimer *m_shutdownTimer;
|
||||||
QList<ElectricBorder> m_borderActivate;
|
|
||||||
QList<ElectricBorder> m_touchBorderActivate;
|
|
||||||
|
|
||||||
int m_animationDuration = 400;
|
int m_animationDuration = 400;
|
||||||
qreal m_partialActivationFactor = 0;
|
|
||||||
bool m_gestureInProgress = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace KWin
|
} // namespace KWin
|
||||||
|
|
|
||||||
|
|
@ -277,7 +277,7 @@ FocusScope {
|
||||||
implicitWidth: Kirigami.Units.iconSizes.large
|
implicitWidth: Kirigami.Units.iconSizes.large
|
||||||
implicitHeight: Kirigami.Units.iconSizes.large
|
implicitHeight: Kirigami.Units.iconSizes.large
|
||||||
source: "window"
|
source: "window"
|
||||||
// color: "white"
|
color: "white"
|
||||||
}
|
}
|
||||||
|
|
||||||
Kirigami.Heading {
|
Kirigami.Heading {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue