make Multiple mode work correctly

pull/20/head
Michail Vourlakos 5 years ago
parent caf9bf7b78
commit 2e120f9446

@ -230,49 +230,45 @@ void Corona::load()
connect(this, &Corona::availableScreenRectChangedFrom, this, &Plasma::Corona::availableScreenRectChanged);
connect(this, &Corona::availableScreenRegionChangedFrom, this, &Plasma::Corona::availableScreenRegionChanged);
connect(qGuiApp, &QGuiApplication::primaryScreenChanged, this, &Corona::primaryOutputChanged, Qt::UniqueConnection);
connect(m_screenPool, &ScreenPool::primaryPoolChanged, this, &Corona::screenCountChanged);
QString assignedLayout = m_layoutsManager->synchronizer()->shouldSwitchToLayout(m_activitiesConsumer->currentActivity());
QString loadLayoutName = "";
if (m_userSetMemoryUsage != -1) {
MemoryUsage::LayoutsMemory usage = static_cast<MemoryUsage::LayoutsMemory>(m_userSetMemoryUsage);
m_universalSettings->setLayoutsMemoryUsage(usage);
}
if (!m_defaultLayoutOnStartup && m_layoutNameOnStartUp.isEmpty()) {
if (!assignedLayout.isEmpty() && assignedLayout != m_universalSettings->currentLayoutName()) {
loadLayoutName = assignedLayout;
if (m_universalSettings->layoutsMemoryUsage() == MemoryUsage::MultipleLayouts) {
loadLayoutName = "";
} else {
loadLayoutName = m_universalSettings->currentLayoutName();
}
if (!m_layoutsManager->synchronizer()->layoutExists(loadLayoutName)) {
//! If chosen layout does not exist, force Default layout loading
QString defaultLayoutTemplateName = i18n(Templates::DEFAULTLAYOUTTEMPLATENAME);
loadLayoutName = defaultLayoutTemplateName;
if (!m_layoutsManager->synchronizer()->layoutExists(loadLayoutName)) {
//! If chosen layout does not exist, force Default layout loading
QString defaultLayoutTemplateName = i18n(Templates::DEFAULTLAYOUTTEMPLATENAME);
loadLayoutName = defaultLayoutTemplateName;
if (!m_layoutsManager->synchronizer()->layoutExists(defaultLayoutTemplateName)) {
//! If Default layout does not exist at all, create it
m_templatesManager->newLayout("", defaultLayoutTemplateName);
if (!m_layoutsManager->synchronizer()->layoutExists(defaultLayoutTemplateName)) {
//! If Default layout does not exist at all, create it
m_templatesManager->newLayout("", defaultLayoutTemplateName);
}
}
}
} else if (m_defaultLayoutOnStartup) {
//! force loading a NEW default layout even though a default layout may already exists
QString newDefaultLayoutPath = m_templatesManager->newLayout("", i18n(Templates::DEFAULTLAYOUTTEMPLATENAME));
loadLayoutName = Layout::AbstractLayout::layoutName(newDefaultLayoutPath);
m_universalSettings->setLayoutsMemoryUsage(MemoryUsage::SingleLayout);
} else {
loadLayoutName = m_layoutNameOnStartUp;
}
if (m_userSetMemoryUsage != -1) {
MemoryUsage::LayoutsMemory usage = static_cast<MemoryUsage::LayoutsMemory>(m_userSetMemoryUsage);
m_universalSettings->setLayoutsMemoryUsage(usage);
m_universalSettings->setLayoutsMemoryUsage(MemoryUsage::SingleLayout);
}
m_layoutsManager->loadLayoutOnStartup(loadLayoutName);
//! load screens signals such screenGeometryChanged in order to support
//! plasmoid.screenGeometry properly
for (QScreen *screen : qGuiApp->screens()) {

@ -207,7 +207,9 @@ const QStringList CentralLayout::appliedActivities()
return {};
}
if (m_activities.isEmpty()) {
if (isOnAllActivities() || m_corona->layoutsManager()->memoryUsage() == MemoryUsage::SingleLayout ) {
return QStringList(Data::Layout::ALLACTIVITIESID);
} else if (isForFreeActivities()) {
return m_corona->layoutsManager()->synchronizer()->freeActivities();
} else {
return m_activities;

@ -23,6 +23,7 @@
#include "importer.h"
#include "manager.h"
#include "../apptypes.h"
#include "../data/layoutdata.h"
#include "../lattecorona.h"
#include "../layout/centrallayout.h"
#include "../layout/genericlayout.h"
@ -51,12 +52,6 @@ Synchronizer::Synchronizer(QObject *parent)
{
m_manager = qobject_cast<Manager *>(parent);
//! Dynamic Switching
m_dynamicSwitchTimer.setSingleShot(true);
updateDynamicSwitchInterval();
connect(m_manager->corona()->universalSettings(), &UniversalSettings::showInfoWindowChanged, this, &Synchronizer::updateDynamicSwitchInterval);
connect(&m_dynamicSwitchTimer, &QTimer::timeout, this, &Synchronizer::confirmDynamicSwitch);
//! KActivities tracking
connect(m_manager->corona()->activitiesConsumer(), &KActivities::Consumer::currentActivityChanged,
this, &Synchronizer::currentActivityChanged);
@ -98,9 +93,15 @@ bool Synchronizer::layoutExists(QString layoutName) const
}
bool Synchronizer::layoutIsAssigned(QString layoutName)
bool Synchronizer::isAssigned(QString layoutName) const
{
return m_assignedLayouts.values().contains(layoutName);
for(auto activityid : m_assignedLayouts.keys()) {
if (m_assignedLayouts[activityid].contains(layoutName)) {
return true;
}
}
return false;
}
int Synchronizer::centralLayoutPos(QString id) const
@ -226,32 +227,6 @@ void Synchronizer::setMenuLayouts(QStringList layouts)
emit menuLayoutsChanged();
}
QString Synchronizer::shouldSwitchToLayout(QString activityId)
{
if (m_assignedLayouts.contains(activityId) && m_assignedLayouts[activityId] != currentLayoutName()) {
return m_assignedLayouts[activityId];
} else if (!m_assignedLayouts.contains(activityId)
&& !m_manager->corona()->universalSettings()->lastNonAssignedLayoutName().isEmpty()
&& m_manager->corona()->universalSettings()->lastNonAssignedLayoutName() != currentLayoutName()) {
return m_manager->corona()->universalSettings()->lastNonAssignedLayoutName();
}
return QString();
}
QStringList Synchronizer::validActivities(QStringList currentList)
{
QStringList validIds;
for (const auto &activity : currentList) {
if (activities().contains(activity)) {
validIds.append(activity);
}
}
return validIds;
}
CentralLayout *Synchronizer::centralLayout(QString id) const
{
for (int i = 0; i < m_centralLayouts.size(); ++i) {
@ -315,41 +290,9 @@ void Synchronizer::addLayout(CentralLayout *layout)
}
}
void Synchronizer::confirmDynamicSwitch()
{
QString tempShouldSwitch = shouldSwitchToLayout(m_manager->corona()->activitiesConsumer()->currentActivity());
if (tempShouldSwitch.isEmpty()) {
return;
}
if (m_shouldSwitchToLayout == tempShouldSwitch && m_shouldSwitchToLayout != currentLayoutName()) {
qDebug() << "dynamic switch to layout :: " << m_shouldSwitchToLayout;
emit currentLayoutIsSwitching(currentLayoutName());
if (m_manager->corona()->universalSettings()->showInfoWindow()) {
m_manager->showInfoWindow(i18n("Switching to layout <b>%0</b> ...").arg(m_shouldSwitchToLayout), 4000);
}
QTimer::singleShot(500, [this, tempShouldSwitch]() {
switchToLayout(tempShouldSwitch);
});
} else {
m_shouldSwitchToLayout = tempShouldSwitch;
m_dynamicSwitchTimer.start();
}
}
void Synchronizer::currentActivityChanged(const QString &id)
{
if (m_manager->memoryUsage() == MemoryUsage::SingleLayout) {
m_shouldSwitchToLayout = shouldSwitchToLayout(id);
qDebug() << "activity changed :: " << id;
qDebug() << "should switch to layout :: " << m_shouldSwitchToLayout;
m_dynamicSwitchTimer.start();
} else if (m_manager->memoryUsage() == MemoryUsage::MultipleLayouts) {
if (m_manager->memoryUsage() == MemoryUsage::MultipleLayouts) {
updateCurrentLayoutNameInMultiEnvironment();
}
}
@ -457,11 +400,12 @@ void Synchronizer::onLayoutAdded(const QString &layout)
{
CentralLayout centralLayout(this, layout);
QStringList validActivityIds = validActivities(centralLayout.activities());
centralLayout.setActivities(validActivityIds);
for (const auto &activity : validActivityIds) {
m_assignedLayouts[activity] = centralLayout.name();
for (const auto &activity : centralLayout.activities()) {
if (m_assignedLayouts.contains(activity)) {
m_assignedLayouts[activity] << centralLayout.name();
} else {
m_assignedLayouts[activity] = QStringList(centralLayout.name());
}
}
m_layouts.append(centralLayout.name());
@ -507,15 +451,6 @@ void Synchronizer::updateCurrentLayoutNameInMultiEnvironment()
}
}
void Synchronizer::updateDynamicSwitchInterval()
{
if (m_manager->corona()->universalSettings()->showInfoWindow()) {
m_dynamicSwitchTimer.setInterval(1800);
} else {
m_dynamicSwitchTimer.setInterval(2300);
}
}
bool Synchronizer::switchToLayout(QString layoutName, int previousMemoryUsage)
{
if (m_centralLayouts.size() > 0 && currentLayoutName() == layoutName && previousMemoryUsage == -1) {
@ -528,7 +463,6 @@ bool Synchronizer::switchToLayout(QString layoutName, int previousMemoryUsage)
CentralLayout *layout = centralLayout(layoutName);
if (layout) {
QStringList appliedActivities = layout->appliedActivities();
QString nextActivity = !layout->lastUsedActivity().isEmpty() ? layout->lastUsedActivity() : appliedActivities[0];
@ -551,30 +485,11 @@ bool Synchronizer::switchToLayout(QString layoutName, int previousMemoryUsage)
QString lPath = layoutPath(layoutName);
if (lPath.isEmpty() && layoutName == i18nc("alternative layout", "Alternative")) {
lPath = m_manager->corona()->templatesManager()->newLayout(i18nc("alternative layout", "Alternative"), i18n(Templates::DEFAULTLAYOUTTEMPLATENAME));
}
if (!lPath.isEmpty()) {
if ((m_manager->memoryUsage() == MemoryUsage::SingleLayout && !lPath.isEmpty()) || m_manager->memoryUsage() == MemoryUsage::MultipleLayouts) {
if (m_manager->memoryUsage() == MemoryUsage::SingleLayout) {
// emit currentLayoutIsSwitching(currentLayoutName());
emit currentLayoutIsSwitching(currentLayoutName());
} else if (m_manager->memoryUsage() == MemoryUsage::MultipleLayouts && layoutName != Layout::MULTIPLELAYOUTSHIDDENNAME) {
CentralLayout toLayout(this, lPath);
QStringList toActivities = toLayout.activities();
CentralLayout *centralForFreeActivities{nullptr};
for (const auto fromLayout : m_centralLayouts) {
if (fromLayout->activities().isEmpty()) {
centralForFreeActivities = fromLayout;
break;
}
}
if (toActivities.isEmpty() && centralForFreeActivities && (toLayout.name() != centralForFreeActivities->name())) {
emit currentLayoutIsSwitching(centralForFreeActivities->name());
}
//! do nothing
}
//! this code must be called asynchronously because it is called
@ -587,21 +502,16 @@ bool Synchronizer::switchToLayout(QString layoutName, int previousMemoryUsage)
QString fixedLPath = lPath;
QString fixedLayoutName = layoutName;
bool initializingMultipleLayouts{false};
if (m_manager->memoryUsage() == MemoryUsage::MultipleLayouts && !m_multipleModeInitialized) {
initializingMultipleLayouts = true;
}
bool initializingMultipleLayouts{(m_manager->memoryUsage() == MemoryUsage::MultipleLayouts) && !m_multipleModeInitialized};
if (m_manager->memoryUsage() == MemoryUsage::SingleLayout || initializingMultipleLayouts || previousMemoryUsage == MemoryUsage::MultipleLayouts) {
unloadLayouts();
//! load the main layout/corona file
if (initializingMultipleLayouts) {
fixedLayoutName = QString(Layout::MULTIPLELAYOUTSHIDDENNAME);
fixedLPath = layoutPath(fixedLayoutName);
}
if (fixedLayoutName != Layout::MULTIPLELAYOUTSHIDDENNAME) {
} else if (fixedLayoutName != Layout::MULTIPLELAYOUTSHIDDENNAME) {
CentralLayout *newLayout = new CentralLayout(this, fixedLPath, fixedLayoutName);
addLayout(newLayout);
}
@ -616,72 +526,12 @@ bool Synchronizer::switchToLayout(QString layoutName, int previousMemoryUsage)
}
if (m_manager->memoryUsage() == MemoryUsage::MultipleLayouts) {
if (!initializingMultipleLayouts && !centralLayout(layoutName)) {
//! When we are in Multiple Layouts Environment and the user activates
//! a Layout that is assigned to specific activities but this
//! layout isnt loaded (this means neither of its activities are running)
//! is such case we just activate these Activities
CentralLayout layout(this, Importer::layoutUserFilePath(layoutName));
int i = 0;
bool lastUsedActivityFound{false};
QString lastUsedActivity = layout.lastUsedActivity();
bool freeActivitiesLayout = !layoutIsAssigned(layoutName);
QStringList assignedActivities = freeActivitiesLayout ? freeActivities() : layout.activities();
if (!freeActivitiesLayout) {
for (const auto &assignedActivity : assignedActivities) {
//! Starting the activities must be done asynchronous because otherwise
//! the activity manager cant close multiple activities
QTimer::singleShot(i * 1000, [this, assignedActivity, lastUsedActivity]() {
m_activitiesController->startActivity(assignedActivity);
if (lastUsedActivity == assignedActivity) {
m_activitiesController->setCurrentActivity(lastUsedActivity);
}
});
if (lastUsedActivity == assignedActivity) {
lastUsedActivityFound = true;
}
i = i + 1;
}
} else {
//! free activities layout
for (const auto &assignedActivity : assignedActivities) {
if (lastUsedActivity == assignedActivity) {
lastUsedActivityFound = true;
}
}
if ((!lastUsedActivityFound && assignedActivities.count() == 0)
|| !assignedActivities.contains(m_manager->corona()->activitiesConsumer()->currentActivity())) {
//! Starting the activities must be done asynchronous because otherwise
//! the activity manager cant close multiple activities
QTimer::singleShot(1000, [this, lastUsedActivity, lastUsedActivityFound]() {
m_activitiesController->startActivity(lastUsedActivity);
m_activitiesController->setCurrentActivity(lastUsedActivity);
});
}
}
if (freeActivitiesLayout) {
syncMultipleLayoutsToActivities(layoutName);
} else if (!freeActivitiesLayout && !lastUsedActivityFound) {
m_activitiesController->setCurrentActivity(layout.activities()[0]);
}
} else {
syncMultipleLayoutsToActivities(layoutName);
}
syncMultipleLayoutsToActivities();
}
m_manager->corona()->universalSettings()->setCurrentLayoutName(layoutName);
if (!layoutIsAssigned(layoutName)) {
if (!isAssigned(layoutName)) {
m_manager->corona()->universalSettings()->setLastNonAssignedLayoutName(layoutName);
}
});
@ -692,7 +542,7 @@ bool Synchronizer::switchToLayout(QString layoutName, int previousMemoryUsage)
return true;
}
void Synchronizer::syncMultipleLayoutsToActivities(QString layoutForFreeActivities)
void Synchronizer::syncMultipleLayoutsToActivities()
{
qDebug() << " ---- --------- ------ syncMultipleLayoutsToActivities ------- ";
qDebug() << " ---- --------- ------ ------------------------------- ------- ";
@ -700,13 +550,17 @@ void Synchronizer::syncMultipleLayoutsToActivities(QString layoutForFreeActiviti
QStringList layoutsToUnload;
QStringList layoutsToLoad;
bool layoutForFreeActivitiesIsNeeded{false};
//! discover OnAllActivities layouts
if (m_assignedLayouts.contains(Data::Layout::ALLACTIVITIESID)) {
layoutsToLoad << m_assignedLayouts[Data::Layout::ALLACTIVITIESID];
}
if (layoutForFreeActivities.isEmpty() || m_assignedLayouts.values().contains(layoutForFreeActivities)) {
layoutForFreeActivities = m_manager->corona()->universalSettings()->lastNonAssignedLayoutName();
//! discover ForFreeActivities layouts
if (m_assignedLayouts.contains(Data::Layout::FREEACTIVITIESID)) {
layoutsToLoad << m_assignedLayouts[Data::Layout::FREEACTIVITIESID];
}
//! discover layouts that are needed based on running activities
//! discover layouts assigned to explicit activities based on running activities
for (const auto &activity : runningActivities()) {
if (KWindowSystem::isPlatformWayland() && (m_activitiesController->currentActivity() != activity)){
//! Wayland Protection: Plasma wayland does not support yet Activities for windows
@ -715,31 +569,28 @@ void Synchronizer::syncMultipleLayoutsToActivities(QString layoutForFreeActiviti
}
if (m_assignedLayouts.contains(activity)) {
if (!layoutsToLoad.contains(m_assignedLayouts[activity])) {
layoutsToLoad.append(m_assignedLayouts[activity]);
}
} else {
layoutForFreeActivitiesIsNeeded = true;
layoutsToLoad << m_assignedLayouts[activity];
}
}
//! discover layouts that must be unloaded because of running activities changes
for (const auto layout : m_centralLayouts) {
QString tempLayoutName;
if (!layoutsToLoad.contains(layout->name()) && layout->name() != layoutForFreeActivities) {
tempLayoutName = layout->name();
} else if (layout->activities().isEmpty() && !layoutForFreeActivitiesIsNeeded) {
//! in such case the layout for free_activities must be unloaded
tempLayoutName = layout->name();
if (!layoutsToLoad.contains(layout->name())) {
layoutsToUnload << layout->name();
}
}
if (!tempLayoutName.isEmpty() && !layoutsToUnload.contains(tempLayoutName)) {
layoutsToUnload << tempLayoutName;
}
QString defaultForcedLayout;
//! Safety
if (layoutsToLoad.isEmpty()) {
//! If no layout is found then force loading Default Layout
QString layoutPath = m_manager->corona()->templatesManager()->newLayout("", i18n(Templates::DEFAULTLAYOUTTEMPLATENAME));
layoutsToLoad << Layout::AbstractLayout::layoutName(layoutPath);
defaultForcedLayout = layoutsToLoad[0];
}
//! Add needed Layouts based on Activities
//! Add needed Layouts based on Activities settings
for (const auto &layoutName : layoutsToLoad) {
if (!centralLayout(layoutName)) {
CentralLayout *newLayout = new CentralLayout(this, QString(layoutPath(layoutName)), layoutName);
@ -749,6 +600,10 @@ void Synchronizer::syncMultipleLayoutsToActivities(QString layoutForFreeActiviti
addLayout(newLayout);
newLayout->importToCorona();
if (!defaultForcedLayout.isEmpty() && newLayout->name() == defaultForcedLayout) {
newLayout->setActivities(QStringList(Data::Layout::ALLACTIVITIESID));
}
if (m_manager->corona()->universalSettings()->showInfoWindow()) {
m_manager->showInfoWindow(i18n("Activating layout: <b>%0</b> ...").arg(newLayout->name()), 5000, newLayout->appliedActivities());
}
@ -756,20 +611,6 @@ void Synchronizer::syncMultipleLayoutsToActivities(QString layoutForFreeActiviti
}
}
//! Add Layout for free activities
if (layoutForFreeActivitiesIsNeeded) {
if (!centralLayout(layoutForFreeActivities)) {
//! CENTRAL Layout for FreeActivities is not loaded
CentralLayout *newLayout = new CentralLayout(this, layoutPath(layoutForFreeActivities), layoutForFreeActivities);
if (newLayout) {
qDebug() << "ACTIVATING FREE ACTIVITIES LAYOUT ::::: " << layoutForFreeActivities;
addLayout(newLayout);
newLayout->importToCorona();
}
}
}
//! Unload no needed Layouts
for (const auto &layoutName : layoutsToUnload) {
CentralLayout *layout = centralLayout(layoutName);

@ -50,7 +50,7 @@ namespace Layouts {
//! This is a Layouts map in the following structure:
//! ACTIVITY ID -> Layout Names for that activity
typedef QHash<const QString, QStringList> AssignedLayoutsHash;
typedef QHash<QString, QStringList> AssignedLayoutsHash;
//! Layouts::Synchronizer is a very IMPORTANT class which is responsible
//! for all ACTIVE layouts, meaning layouts that have been loaded
@ -75,7 +75,7 @@ public:
void pauseLayout(QString layoutName);
void syncActiveLayoutsToOriginalFiles();
void syncLatteViewsToScreens();
void syncMultipleLayoutsToActivities(QString layoutForFreeActivities = QString());
void syncMultipleLayoutsToActivities();
bool latteViewExists(Latte::View *view) const;
bool layoutExists(QString layoutName) const;
@ -89,8 +89,6 @@ public:
QString currentLayoutNameInMultiEnvironment() const;
void setCurrentLayoutNameInMultiEnvironment(const QString &name);
QString shouldSwitchToLayout(QString activityId);
QStringList centralLayoutsNames();
QStringList layouts() const;
QStringList menuLayouts() const;
@ -118,8 +116,6 @@ signals:
void currentLayoutIsSwitching(QString layoutName);
private slots:
void confirmDynamicSwitch();
void updateDynamicSwitchInterval();
void updateCurrentLayoutNameInMultiEnvironment();
void currentActivityChanged(const QString &id);
@ -130,25 +126,20 @@ private:
void addLayout(CentralLayout *layout);
void unloadCentralLayout(CentralLayout *layout);
bool layoutIsAssigned(QString layoutName);
bool isAssigned(QString layoutName) const;
QString layoutPath(QString layoutName);
QStringList validActivities(QStringList currentList);
private:
bool m_multipleModeInitialized{false};
bool m_isLoaded{false};
QString m_currentLayoutNameInMultiEnvironment;
QString m_shouldSwitchToLayout;
QStringList m_layouts;
QStringList m_menuLayouts;
QHash<const QString, QString> m_assignedLayouts;
QTimer m_dynamicSwitchTimer;
AssignedLayoutsHash m_assignedLayouts;
QList<CentralLayout *> m_centralLayouts;

@ -773,7 +773,7 @@ void Layouts::save()
m_handler->corona()->layoutsManager()->switchToLayout(m_model->layoutNameForFreeActivities(), previousMemoryUsage);
} else {
if (m_handler->corona()->layoutsManager()->memoryUsage() == MemoryUsage::MultipleLayouts) {
m_handler->corona()->layoutsManager()->synchronizer()->syncMultipleLayoutsToActivities(m_model->layoutNameForFreeActivities());
m_handler->corona()->layoutsManager()->synchronizer()->syncMultipleLayoutsToActivities();
} else {
m_handler->corona()->layoutsManager()->switchToLayout(m_model->layoutNameForFreeActivities());
}

@ -30,6 +30,7 @@
#include "settings/viewsettingsfactory.h"
#include "../apptypes.h"
#include "../lattecorona.h"
#include "../data/layoutdata.h"
#include "../declarativeimports/interfaces.h"
#include "../indicator/factory.h"
#include "../layout/genericlayout.h"
@ -1017,7 +1018,7 @@ void View::setFontPixelSize(int size)
bool View::isOnAllActivities() const
{
return m_activities.isEmpty() || m_activities[0] == "0";
return m_activities.isEmpty() || m_activities[0] == Data::Layout::ALLACTIVITIESID;
}
bool View::isOnActivity(const QString &activity) const

Loading…
Cancel
Save