From 4c3d3053ab8fc181020145f9d6439ccdf58a01aa Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Sun, 7 May 2023 18:24:15 +0200 Subject: [PATCH] overview: Make the deactivation gesture to be the inverse of the activation It is not intuitive that one needs to use the same gesture to activate and deactivate an effect. Make the deactivation the inverse of the activation instead. --- src/plugins/overview/overvieweffect.cpp | 35 +++++++++++++++++-------- src/plugins/overview/overvieweffect.h | 3 ++- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/plugins/overview/overvieweffect.cpp b/src/plugins/overview/overvieweffect.cpp index b650a36b0b..65e07f3045 100644 --- a/src/plugins/overview/overvieweffect.cpp +++ b/src/plugins/overview/overvieweffect.cpp @@ -33,20 +33,24 @@ OverviewEffect::OverviewEffect() KGlobalAccel::self()->setShortcut(m_toggleAction, {defaultToggleShortcut}); m_toggleShortcut = KGlobalAccel::self()->shortcut(m_toggleAction); - m_realtimeToggleAction = new QAction(this); - connect(m_realtimeToggleAction, &QAction::triggered, this, [this]() { + m_activateAction = new QAction(this); + connect(m_activateAction, &QAction::triggered, this, [this]() { + if (m_status == Status::Activating) { + if (m_partialActivationFactor > 0.5) { + activate(); + } else { + cancelPartialActivate(); + } + } + }); + m_deactivateAction = new QAction(this); + connect(m_deactivateAction, &QAction::triggered, this, [this]() { if (m_status == Status::Deactivating) { if (m_partialActivationFactor < 0.5) { deactivate(); } else { cancelPartialDeactivate(); } - } else if (m_status == Status::Activating) { - if (m_partialActivationFactor > 0.5) { - activate(); - } else { - cancelPartialActivate(); - } } }); @@ -57,6 +61,13 @@ OverviewEffect::OverviewEffect() case Status::Activating: partialActivate(progress); break; + } + } + }; + + auto progressCallbackInv = [this](qreal progress) { + if (!effects->hasActiveFullScreenEffect() || effects->activeFullScreenEffect() == this) { + switch (m_status) { case Status::Active: case Status::Deactivating: partialDeactivate(progress); @@ -65,8 +76,10 @@ OverviewEffect::OverviewEffect() } }; - effects->registerTouchpadPinchShortcut(PinchDirection::Contracting, 4, m_realtimeToggleAction, progressCallback); - effects->registerTouchscreenSwipeShortcut(SwipeDirection::Up, 3, m_realtimeToggleAction, progressCallback); + effects->registerTouchpadPinchShortcut(PinchDirection::Contracting, 4, m_activateAction, progressCallback); + effects->registerTouchpadPinchShortcut(PinchDirection::Expanding, 4, m_deactivateAction, progressCallbackInv); + effects->registerTouchscreenSwipeShortcut(SwipeDirection::Up, 3, m_activateAction, progressCallback); + effects->registerTouchscreenSwipeShortcut(SwipeDirection::Down, 3, m_deactivateAction, progressCallbackInv); connect(effects, &EffectsHandler::screenAboutToLock, this, &OverviewEffect::realDeactivate); @@ -106,7 +119,7 @@ void OverviewEffect::reconfigure(ReconfigureFlags) const QList touchActivateBorders = OverviewConfig::touchBorderActivate(); for (const int &border : touchActivateBorders) { m_touchBorderActivate.append(ElectricBorder(border)); - effects->registerRealtimeTouchBorder(ElectricBorder(border), m_realtimeToggleAction, [this](ElectricBorder border, const QPointF &deltaProgress, const EffectScreen *screen) { + effects->registerRealtimeTouchBorder(ElectricBorder(border), m_deactivateAction, [this](ElectricBorder border, const QPointF &deltaProgress, const EffectScreen *screen) { if (m_status == Status::Active) { return; } diff --git a/src/plugins/overview/overvieweffect.h b/src/plugins/overview/overvieweffect.h index e4fc349e65..eb0b8515ef 100644 --- a/src/plugins/overview/overvieweffect.h +++ b/src/plugins/overview/overvieweffect.h @@ -73,7 +73,8 @@ private: QTimer *m_shutdownTimer; QAction *m_toggleAction = nullptr; - QAction *m_realtimeToggleAction = nullptr; + QAction *m_deactivateAction = nullptr; + QAction *m_activateAction = nullptr; QList m_toggleShortcut; QList m_borderActivate; QList m_touchBorderActivate;