effects/overview: Support touchpad realtime activation

Now it follows your fingers when you do a four-finger swipe up to activate it.

CCBUG: 401479
This commit is contained in:
Marco Martin 2022-04-08 14:17:21 +00:00 committed by Nate Graham
parent 08d18503e3
commit 170b0e9aa0
3 changed files with 40 additions and 3 deletions

View file

@ -30,6 +30,18 @@ OverviewEffect::OverviewEffect()
m_shutdownTimer->setSingleShot(true);
connect(m_shutdownTimer, &QTimer::timeout, this, &OverviewEffect::realDeactivate);
m_realtimeToggleAction = new QAction(this);
connect(m_realtimeToggleAction, &QAction::triggered, this, [this]() {
if (isRunning() && m_partialActivationFactor > 0.5) {
activate();
} else {
deactivate();
}
m_partialActivationFactor = 0;
Q_EMIT gestureInProgressChanged();
Q_EMIT partialActivationFactorChanged();
});
const QKeySequence defaultToggleShortcut = Qt::META | Qt::Key_W;
m_toggleAction = new QAction(this);
connect(m_toggleAction, &QAction::triggered, this, &OverviewEffect::toggle);
@ -39,10 +51,26 @@ OverviewEffect::OverviewEffect()
KGlobalAccel::self()->setShortcut(m_toggleAction, {defaultToggleShortcut});
m_toggleShortcut = KGlobalAccel::self()->shortcut(m_toggleAction);
effects->registerGlobalShortcut({defaultToggleShortcut}, m_toggleAction);
effects->registerTouchpadSwipeShortcut(SwipeDirection::Up, 4, m_toggleAction);
effects->registerTouchscreenSwipeShortcut(SwipeDirection::Up, 3, m_toggleAction);
effects->registerTouchscreenSwipeShortcut(SwipeDirection::Down, 3, m_toggleAction);
auto progressCallback = [this](qreal progress) {
if (m_status == Status::Active) {
return;
}
const bool wasInProgress = m_partialActivationFactor > 0;
m_partialActivationFactor = progress;
Q_EMIT partialActivationFactorChanged();
if (!wasInProgress) {
Q_EMIT gestureInProgressChanged();
}
if (!isRunning()) {
partialActivate();
}
};
effects->registerRealtimeTouchpadSwipeShortcut(SwipeDirection::Up, 4, m_realtimeToggleAction, progressCallback);
connect(effects, &EffectsHandler::screenAboutToLock, this, &OverviewEffect::realDeactivate);
initConfig<OverviewConfig>();
@ -90,7 +118,7 @@ void OverviewEffect::reconfigure(ReconfigureFlags)
const QList<int> touchActivateBorders = OverviewConfig::touchBorderActivate();
for (const int &border : touchActivateBorders) {
m_touchBorderActivate.append(ElectricBorder(border));
effects->registerRealtimeTouchBorder(ElectricBorder(border), m_toggleAction, [this](ElectricBorder border, const QSizeF &deltaProgress, const EffectScreen *screen) {
effects->registerRealtimeTouchBorder(ElectricBorder(border), m_realtimeToggleAction, [this](ElectricBorder border, const QSizeF &deltaProgress, const EffectScreen *screen) {
Q_UNUSED(screen)
if (m_status == Status::Active) {
return;

View file

@ -71,6 +71,7 @@ private:
QTimer *m_shutdownTimer;
QAction *m_toggleAction = nullptr;
QAction *m_realtimeToggleAction = nullptr;
QList<QKeySequence> m_toggleShortcut;
QList<ElectricBorder> m_borderActivate;
QList<ElectricBorder> m_touchBorderActivate;

View file

@ -82,9 +82,17 @@ PresentWindowsEffect::PresentWindowsEffect()
KGlobalAccel::self()->setShortcut(exposeAllAction, QList<QKeySequence>() << (Qt::CTRL | Qt::Key_F10) << Qt::Key_LaunchC);
shortcutAll = KGlobalAccel::self()->shortcut(exposeAllAction);
effects->registerGlobalShortcut(Qt::CTRL + Qt::Key_F10, exposeAllAction);
effects->registerTouchpadSwipeShortcut(SwipeDirection::Down, 4, exposeAllAction);
connect(exposeAllAction, &QAction::triggered, this, &PresentWindowsEffect::toggleActiveAllDesktops);
effects->registerRealtimeTouchpadSwipeShortcut(SwipeDirection::Down, 4, new QAction(this), [this](qreal progress) {
m_mode = ModeAllDesktops;
if (progress > .2 && !m_activated) {
setActive(true);
} else if (progress <= .2 && m_activated) {
setActive(false);
}
});
QAction *exposeClassAction = m_exposeClassAction;
exposeClassAction->setObjectName(QStringLiteral("ExposeClass"));
exposeClassAction->setText(i18n("Toggle Present Windows (Window class)"));