diff --git a/app/lattecorona.cpp b/app/lattecorona.cpp index 5b2186496..72c16152c 100644 --- a/app/lattecorona.cpp +++ b/app/lattecorona.cpp @@ -507,14 +507,8 @@ CentralLayout *Corona::centralLayout(QString name) const { CentralLayout *result{nullptr}; - if (name.isEmpty()) { - result = m_layoutsManager->currentLayout(); - } else { - CentralLayout *tempCentral = m_layoutsManager->synchronizer()->centralLayout(name); - - if (tempCentral) { - result = tempCentral; - } + if (!name.isEmpty()) { + result = m_layoutsManager->synchronizer()->centralLayout(name); } return result; @@ -524,14 +518,8 @@ Layout::GenericLayout *Corona::layout(QString name) const { Layout::GenericLayout *result{nullptr}; - if (name.isEmpty()) { - result = m_layoutsManager->currentLayout(); - } else { + if (!name.isEmpty()) { result = m_layoutsManager->synchronizer()->layout(name); - - if (!result) { - result = m_layoutsManager->currentLayout(); - } } return result; @@ -543,14 +531,14 @@ QRegion Corona::availableScreenRegion(int id) const } QRegion Corona::availableScreenRegionWithCriteria(int id, - QString forLayout, + QString layoutName, QList ignoreModes, QList ignoreEdges, bool ignoreExternalPanels, bool desktopUse) const { const QScreen *screen = m_screenPool->screenForId(id); - CentralLayout *layout = centralLayout(forLayout); + bool inCurrentLayouts{layoutName.isEmpty()}; if (!screen) { return {}; @@ -558,7 +546,7 @@ QRegion Corona::availableScreenRegionWithCriteria(int id, QRegion available = ignoreExternalPanels ? screen->geometry() : screen->availableGeometry(); - if (!layout) { + if (!centralLayout(layoutName) && !inCurrentLayouts) { return available; } @@ -572,7 +560,14 @@ QRegion Corona::availableScreenRegionWithCriteria(int id, } bool allEdges = ignoreEdges.isEmpty(); - QList views = layout->latteViews(); + QList views; + + if (inCurrentLayouts) { + views = m_layoutsManager->synchronizer()->currentViews(); + } else { + CentralLayout *central = centralLayout(layoutName); + views = central->latteViews(); + } for (const auto *view : views) { if (view && view->containment() && view->screen() == screen @@ -730,14 +725,14 @@ QRect Corona::availableScreenRect(int id) const } QRect Corona::availableScreenRectWithCriteria(int id, - QString forLayout, + QString layoutName, QList ignoreModes, QList ignoreEdges, bool ignoreExternalPanels, bool desktopUse) const { const QScreen *screen = m_screenPool->screenForId(id); - CentralLayout *layout = centralLayout(forLayout); + bool inCurrentLayouts{layoutName.isEmpty()}; if (!screen) { return {}; @@ -745,7 +740,7 @@ QRect Corona::availableScreenRectWithCriteria(int id, QRect available = ignoreExternalPanels ? screen->geometry() : screen->availableGeometry(); - if (!layout) { + if (!centralLayout(layoutName) && !inCurrentLayouts) { return available; } @@ -759,7 +754,14 @@ QRect Corona::availableScreenRectWithCriteria(int id, } bool allEdges = ignoreEdges.isEmpty(); - QList views = layout->latteViews(); + QList views; + + if (inCurrentLayouts) { + views = m_layoutsManager->synchronizer()->currentViews(); + } else { + CentralLayout *central = centralLayout(layoutName); + views = central->latteViews(); + } for (const auto *view : views) { if (view && view->containment() && view->screen() == screen @@ -1194,11 +1196,10 @@ QStringList Corona::contextMenuData() { QStringList data; Types::ViewType viewType{Types::DockView}; + auto view = m_layoutsManager->synchronizer()->viewForContainment(m_contextMenuViewId); - Latte::CentralLayout *currentLayout = m_layoutsManager->currentLayout(); - - if (currentLayout) { - viewType = currentLayout->latteViewType(m_contextMenuViewId); + if (view) { + viewType = view->type(); } data << QString::number((int)m_layoutsManager->memoryUsage()); @@ -1234,10 +1235,16 @@ void Corona::setBroadcastedBackgroundsEnabled(QString activity, QString screenNa void Corona::toggleHiddenState(QString layoutName, QString screenName, int screenEdge) { - Layout::GenericLayout *gLayout = layout(layoutName); + if (layoutName.isEmpty()) { + for(auto layout : m_layoutsManager->currentLayouts()) { + layout->toggleHiddenState(screenName, (Plasma::Types::Location)screenEdge); + } + } else { + Layout::GenericLayout *gLayout = layout(layoutName); - if (gLayout) { - gLayout->toggleHiddenState(screenName, (Plasma::Types::Location)screenEdge); + if (gLayout) { + gLayout->toggleHiddenState(screenName, (Plasma::Types::Location)screenEdge); + } } } diff --git a/app/lattecorona.h b/app/lattecorona.h index a5c9bae9e..78ef7f8b8 100644 --- a/app/lattecorona.h +++ b/app/lattecorona.h @@ -117,14 +117,14 @@ public: //! arguments mean that all choices are accepted in calculations. ignoreExternalPanels means that //! external panels should be not considered in the calculations QRect availableScreenRectWithCriteria(int id, - QString forLayout = QString(), + QString layoutName = QString(), QList ignoreModes = QList(), QList ignoreEdges = QList(), bool ignoreExternalPanels = true, bool desktopUse = false) const; QRegion availableScreenRegionWithCriteria(int id, - QString forLayout = QString(), + QString layoutName = QString(), QList ignoreModes = QList(), QList ignoreEdges = QList(), bool ignoreExternalPanels = true, diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index 7f182bfc6..844474772 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -370,6 +370,17 @@ void GenericLayout::setLastConfigViewFor(Latte::View *view) emit lastConfigViewForChanged(view); } +Latte::View *GenericLayout::viewForContainment(uint id) const +{ + for(auto view : m_latteViews) { + if (view && view->containment()->id() == id) { + return view; + } + } + + return nullptr; +} + Latte::View *GenericLayout::viewForContainment(Plasma::Containment *containment) const { if (m_containments.contains(containment) && m_latteViews.contains(containment)) { @@ -384,9 +395,14 @@ QList GenericLayout::latteViews() return m_latteViews.values(); } +QList GenericLayout::sortedLatteViews() +{ + return sortedLatteViews(latteViews()); +} + QList GenericLayout::sortedLatteViews(QList views) { - QList sortedViews = views.isEmpty() ? latteViews() : views; + QList sortedViews = views; qDebug() << " -------- "; diff --git a/app/layout/genericlayout.h b/app/layout/genericlayout.h index ebabe1716..efa3a92a2 100644 --- a/app/layout/genericlayout.h +++ b/app/layout/genericlayout.h @@ -98,8 +98,14 @@ public: const QList *containments() const; Latte::View *highestPriorityView(); + Latte::View *viewForContainment(uint id) const; Latte::View *viewForContainment(Plasma::Containment *containment) const; - virtual QList sortedLatteViews(QList views = QList()); + + static bool viewAtLowerScreenPriority(Latte::View *test, Latte::View *base); + static bool viewAtLowerEdgePriority(Latte::View *test, Latte::View *base); + static QList sortedLatteViews(QList views); + + QList sortedLatteViews(); virtual QList viewsWithPlasmaShortcuts(); virtual QList latteViews(); ViewsMap validViewsMap(ViewsMap *occupiedMap = nullptr); @@ -184,9 +190,6 @@ private: bool explicitDockOccupyEdge(int screen, Plasma::Types::Location location) const; bool primaryDockOccupyEdge(Plasma::Types::Location location) const; - bool viewAtLowerScreenPriority(Latte::View *test, Latte::View *base); - bool viewAtLowerEdgePriority(Latte::View *test, Latte::View *base); - bool viewDataAtLowerEdgePriority(const ViewData &test, const ViewData &base) const; bool viewDataAtLowerScreenPriority(const ViewData &test, const ViewData &base) const; bool viewDataAtLowerStatePriority(const ViewData &test, const ViewData &base) const; diff --git a/app/layouts/manager.cpp b/app/layouts/manager.cpp index a25ed0e74..9e7cf7de8 100644 --- a/app/layouts/manager.cpp +++ b/app/layouts/manager.cpp @@ -178,9 +178,9 @@ QStringList Manager::centralLayoutsNames() return m_synchronizer->centralLayoutsNames(); } -CentralLayout *Manager::currentLayout() const +QList Manager::currentLayouts() const { - return m_synchronizer->currentLayout(); + return m_synchronizer->currentLayouts(); } bool Manager::switchToLayout(QString layoutName, int previousMemoryUsage) diff --git a/app/layouts/manager.h b/app/layouts/manager.h index 9340a8784..774ae8904 100644 --- a/app/layouts/manager.h +++ b/app/layouts/manager.h @@ -98,7 +98,7 @@ public: void setMemoryUsage(MemoryUsage::LayoutsMemory memoryUsage); //! returns the current and central layout based on activities and user preferences - CentralLayout *currentLayout() const; + QListcurrentLayouts() const; LaunchersSignals *launchersSignals() const; Synchronizer *synchronizer() const; diff --git a/app/layouts/synchronizer.cpp b/app/layouts/synchronizer.cpp index 6a7e7c1a4..4f9aa2573 100644 --- a/app/layouts/synchronizer.cpp +++ b/app/layouts/synchronizer.cpp @@ -241,25 +241,49 @@ CentralLayout *Synchronizer::centralLayout(QString id) const return nullptr; } -CentralLayout *Synchronizer::currentLayout() const +QList Synchronizer::currentLayouts() const { + QList layouts; if (m_manager->memoryUsage() == MemoryUsage::SingleLayout) { - return m_centralLayouts.at(0); + layouts << m_centralLayouts.at(0); } else { for (auto layout : m_centralLayouts) { - if (layout->activities().contains(m_manager->corona()->activitiesConsumer()->currentActivity())) { - return layout; - } - } - - for (auto layout : m_centralLayouts) { - if (layout->activities().isEmpty()) { - return layout; + if (layout->isOnAllActivities() || layout->appliedActivities().contains(m_manager->corona()->activitiesConsumer()->currentActivity())) { + layouts << layout; } } } - return nullptr; + return layouts; +} + +QList Synchronizer::currentViews() const +{ + QList views; + + for(auto layout : currentLayouts()) { + views << layout->latteViews(); + } + + return views; +} + +QList Synchronizer::currentViewsWithPlasmaShortcuts() const +{ + QList views; + + for(auto layout : currentLayouts()) { + views << layout->viewsWithPlasmaShortcuts(); + } + + return views; +} + +QList Synchronizer::sortedCurrentViews() const +{ + QList views = currentViews(); + + return Layout::GenericLayout::sortedLatteViews(views); } Layout::GenericLayout *Synchronizer::layout(QString id) const @@ -269,6 +293,19 @@ Layout::GenericLayout *Synchronizer::layout(QString id) const return l; } +Latte::View *Synchronizer::viewForContainment(uint id) +{ + for (auto layout : m_centralLayouts) { + Latte::View *view = layout->viewForContainment(id); + + if (view) { + return view; + } + } + + return nullptr; +} + Latte::View *Synchronizer::viewForContainment(Plasma::Containment *containment) { for (auto layout : m_centralLayouts) { diff --git a/app/layouts/synchronizer.h b/app/layouts/synchronizer.h index ea4526318..7dabef2a2 100644 --- a/app/layouts/synchronizer.h +++ b/app/layouts/synchronizer.h @@ -99,8 +99,13 @@ public: QStringList freeActivities(); //! These are activities that haven't been assigned to specific layout Latte::View *viewForContainment(Plasma::Containment *containment); + Latte::View *viewForContainment(uint id); + + QList currentLayouts() const; + QList currentViews() const; + QList currentViewsWithPlasmaShortcuts() const; + QList sortedCurrentViews() const; - CentralLayout *currentLayout() const; CentralLayout *centralLayout(QString id) const; Layout::GenericLayout *layout(QString id) const; diff --git a/app/shortcuts/globalshortcuts.cpp b/app/shortcuts/globalshortcuts.cpp index 4dbc30c0f..e9cc1f9c0 100644 --- a/app/shortcuts/globalshortcuts.cpp +++ b/app/shortcuts/globalshortcuts.cpp @@ -244,12 +244,7 @@ void GlobalShortcuts::activateLauncherMenu() return; } - QList sortedViews; - CentralLayout *currentLayout = m_corona->layoutsManager()->currentLayout(); - - if (currentLayout) { - sortedViews = currentLayout->sortedLatteViews(); - } + QList sortedViews = m_corona->layoutsManager()->synchronizer()->sortedCurrentViews(); Latte::View *highestPriorityView = highestApplicationLauncherView(sortedViews); @@ -356,12 +351,7 @@ void GlobalShortcuts::activateEntry(int index, Qt::Key modifier) { m_lastInvokedAction = dynamic_cast(sender()); - QList sortedViews; - CentralLayout *currentLayout = m_corona->layoutsManager()->currentLayout(); - - if (currentLayout) { - sortedViews = currentLayout->sortedLatteViews(); - } + QList sortedViews = m_corona->layoutsManager()->synchronizer()->sortedCurrentViews(); Latte::View *highest{nullptr}; @@ -386,12 +376,7 @@ void GlobalShortcuts::activateEntry(int index, Qt::Key modifier) //! update badge for specific view item void GlobalShortcuts::updateViewItemBadge(QString identifier, QString value) { - CentralLayout *currentLayout = m_corona->layoutsManager()->currentLayout(); - QList views; - - if (currentLayout) { - views = currentLayout->latteViews(); - } + QList views = m_corona->layoutsManager()->synchronizer()->currentViews(); // update badges in all Latte Tasks plasmoids for (const auto &view : views) { @@ -407,12 +392,7 @@ void GlobalShortcuts::showViews() m_lastInvokedAction = m_singleMetaAction; } - QList sortedViews; - CentralLayout *currentLayout = m_corona->layoutsManager()->currentLayout(); - - if (currentLayout) { - sortedViews = currentLayout->sortedLatteViews(); - } + QList sortedViews = m_corona->layoutsManager()->synchronizer()->sortedCurrentViews(); Latte::View *viewWithTasks{nullptr}; Latte::View *viewWithMeta{nullptr}; @@ -469,11 +449,7 @@ void GlobalShortcuts::showViews() } //! show all the rest views that contain plasma shortcuts - QList viewsWithShortcuts; - - if (currentLayout) { - viewsWithShortcuts = currentLayout->viewsWithPlasmaShortcuts(); - } + QList viewsWithShortcuts = m_corona->layoutsManager()->synchronizer()->currentViewsWithPlasmaShortcuts(); if (viewsWithShortcuts.count() > 0) { viewFound = true; @@ -514,12 +490,7 @@ bool GlobalShortcuts::viewsToHideAreValid() void GlobalShortcuts::showSettings() { - QList sortedViews; - CentralLayout *currentLayout = m_corona->layoutsManager()->currentLayout(); - - if (currentLayout) { - sortedViews = currentLayout->sortedLatteViews(); - } + QList sortedViews = m_corona->layoutsManager()->synchronizer()->sortedCurrentViews(); //! find which is the next view to show its settings if (sortedViews.count() > 0) { @@ -527,8 +498,14 @@ void GlobalShortcuts::showSettings() //! find last view that showed its config view for (int i = 0; i < sortedViews.size(); ++i) { - if (sortedViews[i] == currentLayout->lastConfigViewFor()) { - openSettings = i; + for (auto currentLayout : m_corona->layoutsManager()->currentLayouts()) { + if (sortedViews[i] == currentLayout->lastConfigViewFor()) { + openSettings = i; + break; + } + } + + if (openSettings >= 0) { break; } }