diff --git a/app/lattecorona.cpp b/app/lattecorona.cpp index 3dbba2e86..6696afaf6 100644 --- a/app/lattecorona.cpp +++ b/app/lattecorona.cpp @@ -30,6 +30,7 @@ #include "indicator/factory.h" #include "layout/activelayout.h" #include "layout/genericlayout.h" +#include "layout/toplayout.h" #include "shortcuts/globalshortcuts.h" #include "package/lattepackage.h" #include "plasma/extended/screenpool.h" @@ -473,8 +474,24 @@ QRegion Corona::availableScreenRegionWithCriteria(int id, QString forLayout) con Latte::ActiveLayout *currentLayout = m_layoutManager->currentLayout(); views = currentLayout->latteViews(); } else { - Latte::ActiveLayout *activeLayout = m_layoutManager->activeLayout(forLayout); - views = activeLayout->latteViews(); + Layout::GenericLayout *generic = m_layoutManager->activeLayout(forLayout); + + if (!generic) { + //! identify best active layout to be used for metrics + //! active layouts are always considering their top layouts + //! for their metrics + TopLayout *topLayout = m_layoutManager->topLayout(forLayout); + + if (topLayout) { + generic = topLayout->currentActiveLayout(); + } + } + + if (!generic) { + generic = m_layoutManager->currentLayout(); + } + + views = generic->latteViews(); } QRegion available(screen->geometry()); diff --git a/app/layout/activelayout.cpp b/app/layout/activelayout.cpp index 21c6771b3..3df64cc80 100644 --- a/app/layout/activelayout.cpp +++ b/app/layout/activelayout.cpp @@ -421,13 +421,9 @@ QList ActiveLayout::freeEdges(int screen) const QList ActiveLayout::sortedLatteViews(QList views) { - QList combined = latteViews(); + QList vws = latteViews(); - if (m_topLayout) { - combined << m_topLayout->latteViews(); - } - - return Layout::GenericLayout::sortedLatteViews(combined); + return Layout::GenericLayout::sortedLatteViews(vws); } QList ActiveLayout::viewsWithPlasmaShortcuts() diff --git a/app/layout/toplayout.cpp b/app/layout/toplayout.cpp index 44383e883..1e7773ccd 100644 --- a/app/layout/toplayout.cpp +++ b/app/layout/toplayout.cpp @@ -22,6 +22,7 @@ // local #include "activelayout.h" #include "../lattecorona.h" +#include "../layoutmanager.h" #include "../screenpool.h" #include "../view/view.h" @@ -31,7 +32,11 @@ TopLayout::TopLayout(ActiveLayout *assigned, QObject *parent, QString layoutFile : Layout::GenericLayout (parent, layoutFile, layoutName) { initToCorona(assigned->corona()); + + connect(m_corona->layoutManager(), &LayoutManager::currentLayoutNameChanged, this, &TopLayout::updateLastUsedActiveLayout); + addActiveLayout(assigned); + updateLastUsedActiveLayout(); } @@ -65,14 +70,32 @@ const QStringList TopLayout::appliedActivities() return activities; } +void TopLayout::updateLastUsedActiveLayout() +{ + for (const auto &layout : m_activeLayouts) { + if (layout->isCurrent()) { + m_lastUsedActiveLayout = layout->name(); + break; + } + } +} + ActiveLayout *TopLayout::currentActiveLayout() const { + //! first the current active one for (const auto &layout : m_activeLayouts) { if (layout->isCurrent()) { return layout; } } + //! the last used + for (const auto &layout : m_activeLayouts) { + if (layout->name() == m_lastUsedActiveLayout) { + return layout; + } + } + return nullptr; } @@ -204,12 +227,10 @@ QList TopLayout::freeEdges(int screen) const QList TopLayout::sortedLatteViews(QList views) { - QList combined = latteViews(); - ActiveLayout *current = currentActiveLayout(); if (current) { - return current->latteViews(); + return current->sortedLatteViews(); } return Layout::GenericLayout::sortedLatteViews(); diff --git a/app/layout/toplayout.h b/app/layout/toplayout.h index da505dcfa..7c8495e25 100644 --- a/app/layout/toplayout.h +++ b/app/layout/toplayout.h @@ -47,6 +47,7 @@ public: ~TopLayout() override; const QStringList appliedActivities(); + ActiveLayout *currentActiveLayout() const; //! OVERRIDE GeneralLayout implementations bool isCurrent() const override; @@ -67,10 +68,12 @@ public slots: void addActiveLayout(ActiveLayout *layout); void removeActiveLayout(ActiveLayout *layout); -private: - ActiveLayout *currentActiveLayout() const; +private slots: + void updateLastUsedActiveLayout(); private: + QString m_lastUsedActiveLayout; + QList m_activeLayouts; }; diff --git a/shell/package/contents/configuration/LatteDockConfiguration.qml b/shell/package/contents/configuration/LatteDockConfiguration.qml index b19fc8eeb..12cef4541 100644 --- a/shell/package/contents/configuration/LatteDockConfiguration.qml +++ b/shell/package/contents/configuration/LatteDockConfiguration.qml @@ -479,7 +479,7 @@ FocusScope { function updateEnabled() { var screenFreeEdges = latteView.managedLayout.qmlFreeEdges(latteView.positioner.currentScreenId); - actionsComboBtn.buttonEnabled = latteView.managedLayout.viewsCount<4 && screenFreeEdges.length > 0 + actionsComboBtn.buttonEnabled = screenFreeEdges.length > 0; if (actionsModel.count > 0) { actionsModel.get(0).enabled = actionsComboBtn.buttonEnabled; }