From 083481d971a0b02944f8b3bf44c0f46adccfbc40 Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Fri, 24 Mar 2023 23:29:40 -0700 Subject: [PATCH] taskswitcher: Expose visible state to DBus and hookup to homescreen anim --- .../mobileshell/qml/homescreen/HomeScreen.qml | 35 +++++++++++++------ .../mobileshellstate/shelldbusclient.cpp | 20 ++++++++--- components/mobileshellstate/shelldbusclient.h | 21 +++++++---- .../mobileshellstate/shelldbusobject.cpp | 13 +++++++ components/mobileshellstate/shelldbusobject.h | 5 +++ .../mobiletaskswitchereffect.cpp | 16 +++++++++ .../mobiletaskswitchereffect.h | 2 ++ kwin/mobiletaskswitcher/qml/TaskSwitcher.qml | 6 +--- .../qml/TaskSwitcherState.qml | 5 --- 9 files changed, 91 insertions(+), 32 deletions(-) diff --git a/components/mobileshell/qml/homescreen/HomeScreen.qml b/components/mobileshell/qml/homescreen/HomeScreen.qml index 9a5674d9..d94b1943 100644 --- a/components/mobileshell/qml/homescreen/HomeScreen.qml +++ b/components/mobileshell/qml/homescreen/HomeScreen.qml @@ -103,6 +103,14 @@ Item { function onCloseAppLaunchAnimationRequested() { startupFeedback.close(); } + + function onIsTaskSwitcherVisibleChanged() { + if (MobileShellState.ShellDBusClient.isTaskSwitcherVisible) { + itemContainer.zoomOutImmediately(); + } else { + itemContainer.zoomIn(); + } + } } //END API implementation @@ -132,9 +140,9 @@ Item { // animations opacity: 0 - property real zoomScale: 0.8 + property real zoomScale: 1 - Component.onCompleted: zoomIn() + readonly property real zoomScaleOut: 0.8 function zoomIn() { // don't use check animationsEnabled here, so we ensure the scale and opacity is always 1 when disabled @@ -143,31 +151,36 @@ Item { opacityAnim.to = 1; opacityAnim.restart(); } + function zoomOut() { - if (ShellSettings.Settings.animationsEnabled) { - scaleAnim.to = 0.8; - scaleAnim.restart(); - opacityAnim.to = 0; - opacityAnim.restart(); - } + scaleAnim.to = zoomScaleOut; + scaleAnim.restart(); + opacityAnim.to = 0; + opacityAnim.restart(); + } + + function zoomOutImmediately() { + zoomScale = zoomScaleOut; + opacity = 0; } NumberAnimation on opacity { id: opacityAnim - duration: ShellSettings.Settings.animationsEnabled ? 300 : 0 + duration: 300 running: false } NumberAnimation on zoomScale { id: scaleAnim - duration: ShellSettings.Settings.animationsEnabled ? 600 : 0 + duration: 600 running: false easing.type: Easing.OutExpo } function evaluateAnimChange() { // only animate if homescreen is visible - if (!WindowPlugin.WindowMaximizedTracker.showingWindow || WindowPlugin.WindowUtil.activeWindowIsShell) { + if ((!WindowPlugin.WindowMaximizedTracker.showingWindow || WindowPlugin.WindowUtil.activeWindowIsShell) && + !MobileShellState.ShellDBusClient.isTaskSwitcherVisible) { itemContainer.zoomIn(); } else { itemContainer.zoomOut(); diff --git a/components/mobileshellstate/shelldbusclient.cpp b/components/mobileshellstate/shelldbusclient.cpp index ead21e36..4df1f179 100644 --- a/components/mobileshellstate/shelldbusclient.cpp +++ b/components/mobileshellstate/shelldbusclient.cpp @@ -8,10 +8,9 @@ ShellDBusClient::ShellDBusClient(QObject *parent) : QObject{parent} , m_interface{new OrgKdePlasmashellInterface{QStringLiteral("org.kde.plasmashell"), QStringLiteral("/Mobile"), QDBusConnection::sessionBus(), this}} + , m_watcher{new QDBusServiceWatcher(QStringLiteral("org.kde.plasmashell"), QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this)} , m_connected{false} { - m_watcher = new QDBusServiceWatcher(QStringLiteral("org.kde.plasmashell"), QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); - if (m_interface->isValid()) { connectSignals(); } @@ -38,6 +37,7 @@ void ShellDBusClient::connectSignals() { connect(m_interface, &OrgKdePlasmashellInterface::isActionDrawerOpenChanged, this, &ShellDBusClient::updateIsActionDrawerOpen); connect(m_interface, &OrgKdePlasmashellInterface::doNotDisturbChanged, this, &ShellDBusClient::updateDoNotDisturb); + connect(m_interface, &OrgKdePlasmashellInterface::isTaskSwitcherVisibleChanged, this, &ShellDBusClient::updateIsTaskSwitcherVisible); connect(m_interface, &OrgKdePlasmashellInterface::openActionDrawerRequested, this, &ShellDBusClient::openActionDrawerRequested); connect(m_interface, &OrgKdePlasmashellInterface::closeActionDrawerRequested, this, &ShellDBusClient::closeActionDrawerRequested); connect(m_interface, &OrgKdePlasmashellInterface::openAppLaunchAnimationRequested, this, &ShellDBusClient::openAppLaunchAnimationRequested); @@ -48,9 +48,10 @@ void ShellDBusClient::connectSignals() updateIsActionDrawerOpen(); updateDoNotDisturb(); + updateIsTaskSwitcherVisible(); } -bool ShellDBusClient::doNotDisturb() +bool ShellDBusClient::doNotDisturb() const { return m_doNotDisturb; } @@ -60,7 +61,7 @@ void ShellDBusClient::setDoNotDisturb(bool value) m_interface->setDoNotDisturb(value); } -bool ShellDBusClient::isActionDrawerOpen() +bool ShellDBusClient::isActionDrawerOpen() const { return m_isActionDrawerOpen; } @@ -80,6 +81,11 @@ void ShellDBusClient::closeActionDrawer() m_interface->closeActionDrawer(); } +bool ShellDBusClient::isTaskSwitcherVisible() const +{ + return m_isTaskSwitcherVisible; +} + void ShellDBusClient::openAppLaunchAnimation(QString splashIcon, QString title, qreal x, qreal y, qreal sourceIconSize) { m_interface->openAppLaunchAnimation(splashIcon, title, x, y, sourceIconSize); @@ -116,3 +122,9 @@ void ShellDBusClient::updateIsActionDrawerOpen() m_isActionDrawerOpen = m_interface->isActionDrawerOpen(); Q_EMIT isActionDrawerOpenChanged(); } + +void ShellDBusClient::updateIsTaskSwitcherVisible() +{ + m_isTaskSwitcherVisible = m_interface->isTaskSwitcherVisible(); + Q_EMIT isTaskSwitcherVisibleChanged(); +} diff --git a/components/mobileshellstate/shelldbusclient.h b/components/mobileshellstate/shelldbusclient.h index 47b5e49a..c4b1a827 100644 --- a/components/mobileshellstate/shelldbusclient.h +++ b/components/mobileshellstate/shelldbusclient.h @@ -12,19 +12,22 @@ class ShellDBusClient : public QObject { Q_OBJECT - Q_PROPERTY(bool doNotDisturb READ doNotDisturb WRITE setDoNotDisturb NOTIFY doNotDisturbChanged); - Q_PROPERTY(bool isActionDrawerOpen READ isActionDrawerOpen WRITE setIsActionDrawerOpen NOTIFY isActionDrawerOpenChanged); + Q_PROPERTY(bool doNotDisturb READ doNotDisturb WRITE setDoNotDisturb NOTIFY doNotDisturbChanged) + Q_PROPERTY(bool isActionDrawerOpen READ isActionDrawerOpen WRITE setIsActionDrawerOpen NOTIFY isActionDrawerOpenChanged) + Q_PROPERTY(bool isTaskSwitcherVisible READ isTaskSwitcherVisible NOTIFY isTaskSwitcherVisibleChanged) public: explicit ShellDBusClient(QObject *parent = nullptr); static ShellDBusClient *self(); - bool doNotDisturb(); + bool doNotDisturb() const; void setDoNotDisturb(bool value); - bool isActionDrawerOpen(); + bool isActionDrawerOpen() const; void setIsActionDrawerOpen(bool value); + bool isTaskSwitcherVisible() const; + Q_INVOKABLE void openActionDrawer(); Q_INVOKABLE void closeActionDrawer(); @@ -38,6 +41,7 @@ public: Q_SIGNALS: void isActionDrawerOpenChanged(); void doNotDisturbChanged(); + void isTaskSwitcherVisibleChanged(); void openActionDrawerRequested(); void closeActionDrawerRequested(); void openAppLaunchAnimationRequested(QString splashIcon, QString title, qreal x, qreal y, qreal sourceIconSize); @@ -49,6 +53,7 @@ Q_SIGNALS: private Q_SLOTS: void updateDoNotDisturb(); void updateIsActionDrawerOpen(); + void updateIsTaskSwitcherVisible(); private: void connectSignals(); @@ -56,7 +61,9 @@ private: OrgKdePlasmashellInterface *m_interface; QDBusServiceWatcher *m_watcher; - bool m_doNotDisturb; - bool m_isActionDrawerOpen; - bool m_connected; + bool m_doNotDisturb = false; + bool m_isActionDrawerOpen = false; + bool m_isTaskSwitcherVisible = false; + + bool m_connected = false; }; diff --git a/components/mobileshellstate/shelldbusobject.cpp b/components/mobileshellstate/shelldbusobject.cpp index 48ead1ac..b626f1b2 100644 --- a/components/mobileshellstate/shelldbusobject.cpp +++ b/components/mobileshellstate/shelldbusobject.cpp @@ -52,6 +52,19 @@ void ShellDBusObject::setIsActionDrawerOpen(bool value) } } +bool ShellDBusObject::isTaskSwitcherVisible() +{ + return m_isTaskSwitcherVisible; +} + +void ShellDBusObject::setIsTaskSwitcherVisible(bool value) +{ + if (value != m_isTaskSwitcherVisible) { + m_isTaskSwitcherVisible = value; + Q_EMIT isTaskSwitcherVisibleChanged(); + } +} + void ShellDBusObject::openActionDrawer() { Q_EMIT openActionDrawerRequested(); diff --git a/components/mobileshellstate/shelldbusobject.h b/components/mobileshellstate/shelldbusobject.h index b433400b..ef9c0be1 100644 --- a/components/mobileshellstate/shelldbusobject.h +++ b/components/mobileshellstate/shelldbusobject.h @@ -21,6 +21,7 @@ public: Q_SIGNALS: Q_SCRIPTABLE void doNotDisturbChanged(); Q_SCRIPTABLE void isActionDrawerOpenChanged(); + Q_SCRIPTABLE void isTaskSwitcherVisibleChanged(); Q_SCRIPTABLE void openActionDrawerRequested(); Q_SCRIPTABLE void closeActionDrawerRequested(); Q_SCRIPTABLE void openAppLaunchAnimationRequested(QString splashIcon, QString title, qreal x, qreal y, qreal sourceIconSize); @@ -37,6 +38,9 @@ public Q_SLOTS: Q_SCRIPTABLE bool isActionDrawerOpen(); Q_SCRIPTABLE void setIsActionDrawerOpen(bool value); + Q_SCRIPTABLE bool isTaskSwitcherVisible(); + Q_SCRIPTABLE void setIsTaskSwitcherVisible(bool value); + Q_SCRIPTABLE void openActionDrawer(); Q_SCRIPTABLE void closeActionDrawer(); @@ -52,4 +56,5 @@ private: bool m_doNotDisturb = false; bool m_isActionDrawerOpen = false; + bool m_isTaskSwitcherVisible = false; }; diff --git a/kwin/mobiletaskswitcher/mobiletaskswitchereffect.cpp b/kwin/mobiletaskswitcher/mobiletaskswitchereffect.cpp index c420ae26..54bae031 100644 --- a/kwin/mobiletaskswitcher/mobiletaskswitchereffect.cpp +++ b/kwin/mobiletaskswitcher/mobiletaskswitchereffect.cpp @@ -4,6 +4,9 @@ #include "mobiletaskswitchereffect.h" +#include +#include +#include #include #include #include @@ -151,6 +154,7 @@ void MobileTaskSwitcherEffect::activate() m_status = Status::Active; setRunning(true); + setDBusState(true); } void MobileTaskSwitcherEffect::deactivate(bool deactivateInstantly) @@ -165,6 +169,8 @@ void MobileTaskSwitcherEffect::deactivate(bool deactivateInstantly) setGestureInProgress(false); setPartialActivationFactor(0.0); + + setDBusState(false); } void MobileTaskSwitcherEffect::partialActivate(qreal factor) @@ -249,4 +255,14 @@ void MobileTaskSwitcherEffect::setPartialActivationFactor(qreal factor) Q_EMIT partialActivationFactorChanged(); } } + +void MobileTaskSwitcherEffect::setDBusState(bool active) +{ + QDBusMessage request = QDBusMessage::createMethodCall(QStringLiteral("org.kde.plasmashell"), + QStringLiteral("/Mobile"), + QStringLiteral("org.kde.plasmashell"), + QStringLiteral("setIsTaskSwitcherVisible")); + request.setArguments({active}); + const QDBusReply response = QDBusConnection::sessionBus().call(request); +} } diff --git a/kwin/mobiletaskswitcher/mobiletaskswitchereffect.h b/kwin/mobiletaskswitcher/mobiletaskswitchereffect.h index 73c705c6..dc22212e 100644 --- a/kwin/mobiletaskswitcher/mobiletaskswitchereffect.h +++ b/kwin/mobiletaskswitcher/mobiletaskswitchereffect.h @@ -43,6 +43,8 @@ public: void reconfigure(ReconfigureFlags flags) override; void grabbedKeyboardEvent(QKeyEvent *keyEvent) override; + void setDBusState(bool active); + public Q_SLOTS: void activate(); void realDeactivate(); diff --git a/kwin/mobiletaskswitcher/qml/TaskSwitcher.qml b/kwin/mobiletaskswitcher/qml/TaskSwitcher.qml index 822ce34d..059d7843 100644 --- a/kwin/mobiletaskswitcher/qml/TaskSwitcher.qml +++ b/kwin/mobiletaskswitcher/qml/TaskSwitcher.qml @@ -10,6 +10,7 @@ import org.kde.plasma.core as PlasmaCore import org.kde.plasma.components 3.0 as PlasmaComponents import org.kde.plasma.extras as PlasmaExtras import org.kde.plasma.private.mobileshell as MobileShell +import org.kde.plasma.private.mobileshell.state as MobileShellState import org.kde.kwin 3.0 as KWinComponents import org.kde.kwin.private.effects 1.0 @@ -73,7 +74,6 @@ FocusScope { Component.onCompleted: { taskList.jumpToFirstVisibleWindow(); taskList.minimizeAll(); - taskSwitcherState.currentlyBeingOpened = true; // fully open the panel (if this is a button press, not gesture) @@ -101,10 +101,6 @@ FocusScope { taskSwitcherState.openApp(index, window); } - function setSingleActiveWindow(id) { - instantHide(); - } - Connections { target: root.effect diff --git a/kwin/mobiletaskswitcher/qml/TaskSwitcherState.qml b/kwin/mobiletaskswitcher/qml/TaskSwitcherState.qml index 9123ad9f..14506b67 100644 --- a/kwin/mobiletaskswitcher/qml/TaskSwitcherState.qml +++ b/kwin/mobiletaskswitcher/qml/TaskSwitcherState.qml @@ -227,10 +227,6 @@ QtObject { root.currentlyBeingOpened = false; scrollingTasks = false; taskSwitcher.instantHide(); - - if (root.wasInActiveTask) { - taskSwitcher.setSingleActiveWindow(root.currentTaskIndex); - } } } @@ -246,7 +242,6 @@ QtObject { onFinished: { root.currentlyBeingClosed = false; root.currentlyBeingOpened = false; - taskSwitcher.setSingleActiveWindow(root.currentTaskIndex); taskSwitcher.instantHide(); } }