From be0f9dc0bafc3ce072d28f34ea6de9ef367221f6 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Sun, 21 Jan 2018 13:52:33 +0200 Subject: [PATCH] remember the last used activity per layout --- app/layout.cpp | 25 +++++++++++++++++++++++++ app/layout.h | 10 +++++++--- app/layoutmanager.cpp | 7 +++++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/app/layout.cpp b/app/layout.cpp index 3a51d6dfd..d9221789c 100644 --- a/app/layout.cpp +++ b/app/layout.cpp @@ -26,6 +26,8 @@ #include #include +#include + namespace Latte { const QString Layout::MultipleLayoutsName = ".multiple-layouts_hidden"; @@ -164,7 +166,12 @@ void Layout::initToCorona(DockCorona *corona) qDebug() << "Layout ::::: " << name() << " added contaiments ::: " << m_containments.size(); + updateLastUsedActivity(); + connect(m_corona, &Plasma::Corona::containmentAdded, this, &Layout::addContainment); + + connect(m_corona->m_activityConsumer, &KActivities::Consumer::currentActivityChanged, + this, &Layout::updateLastUsedActivity); } int Layout::version() const @@ -512,6 +519,24 @@ const QStringList Layout::appliedActivities() } } +QString Layout::lastUsedActivityId() +{ + return m_lastUsedActivityId; +} + +void Layout::updateLastUsedActivity() +{ + if (!m_corona) { + return; + } + + QString currentId = m_corona->activitiesConsumer()->currentActivity(); + + if (appliedActivities().contains(currentId)) { + m_lastUsedActivityId = currentId; + } +} + void Layout::destroyedChanged(bool destroyed) { if (!m_corona) { diff --git a/app/layout.h b/app/layout.h index b251ee1e1..8e1db28e7 100644 --- a/app/layout.h +++ b/app/layout.h @@ -68,12 +68,14 @@ public: int version() const; void setVersion(int ver); - QString name() const; - QString file() const; - QString color() const; void setColor(QString color); + QString lastUsedActivityId(); + + QString name() const; + QString file() const; + QStringList activities() const; void setActivities(QStringList activities); @@ -124,6 +126,7 @@ private slots: void appletCreated(Plasma::Applet *applet); void destroyedChanged(bool destroyed); void containmentDestroyed(QObject *cont); + void updateLastUsedActivity(); private: void importLocalLayout(QString file); @@ -145,6 +148,7 @@ private: int m_version{2}; QString m_color; + QString m_lastUsedActivityId{"0"}; //the last used activity for this layout QString m_layoutFile; QString m_layoutName; QStringList m_activities; diff --git a/app/layoutmanager.cpp b/app/layoutmanager.cpp index c8c6d1408..cdf805e70 100644 --- a/app/layoutmanager.cpp +++ b/app/layoutmanager.cpp @@ -604,10 +604,13 @@ bool LayoutManager::switchToLayout(QString layoutName, int previousMemoryUsage) Layout *layout = activeLayout(layoutName); if (layout) { - QStringList appliedActivities = layout->appliedActivities(); + QStringList appliedActivities = layout->appliedActivities(); + QString nextActivity = layout->lastUsedActivityId() != "0" ? layout->lastUsedActivityId() : appliedActivities[0]; + + //! it means we are at a foreign activity if (!appliedActivities.contains(m_corona->activitiesConsumer()->currentActivity())) { - m_activitiesController->setCurrentActivity(appliedActivities[0]); + m_activitiesController->setCurrentActivity(nextActivity); return true; } }