diff --git a/app/lattecorona.cpp b/app/lattecorona.cpp index 42cfb6d80..f045d255d 100644 --- a/app/lattecorona.cpp +++ b/app/lattecorona.cpp @@ -925,7 +925,6 @@ int Corona::screenForContainment(const Plasma::Containment *containment) const // screen:0 and primaryScreen //case in which this containment is child of an applet, hello systray :) - if (Plasma::Applet *parentApplet = qobject_cast(containment->parent())) { if (Plasma::Containment *cont = parentApplet->containment()) { return screenForContainment(cont); @@ -935,29 +934,13 @@ int Corona::screenForContainment(const Plasma::Containment *containment) const } Plasma::Containment *c = const_cast(containment); - Latte::View *view = m_layoutsManager->synchronizer()->viewForContainment(c); - - if (view && view->screen()) { - return m_screenPool->id(view->screen()->name()); - } + int scrId = m_layoutsManager->synchronizer()->screenForContainment(c); - //Failed? fallback on lastScreen() - //lastScreen() is the correct screen for panels - //It is also correct for desktops *that have the correct activity()* - //a containment with lastScreen() == 0 but another activity, - //won't be associated to a screen - // qDebug() << "ShellCorona screenForContainment: " << containment << " Last screen is " << containment->lastScreen(); - - for (auto screen : qGuiApp->screens()) { - // containment->lastScreen() == m_screenPool->id(screen->name()) to check if the lastScreen refers to a screen that exists/it's known - if (containment->lastScreen() == m_screenPool->id(screen->name()) && - (containment->activity() == m_activitiesConsumer->currentActivity() || - containment->containmentType() == Plasma::Types::PanelContainment || containment->containmentType() == Plasma::Types::CustomPanelContainment)) { - return containment->lastScreen(); - } + if (scrId >= 0) { + return scrId; } - return -1; + return containment->lastScreen(); } void Corona::showAlternativesForApplet(Plasma::Applet *applet) diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index ca6b9de94..46feeda90 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -393,6 +393,45 @@ Plasma::Containment *GenericLayout::containmentForId(uint id) const return nullptr; } +bool GenericLayout::contains(Plasma::Containment *containment) const +{ + return m_containments.contains(containment); +} + +int GenericLayout::screenForContainment(Plasma::Containment *containment) +{ + if (!containment) { + return -1; + } + + //! there is a pending update + QString containmentid = QString::number(containment->id()); + if (m_pendingContainmentUpdates.containsId(containmentid)) { + if (m_corona && m_pendingContainmentUpdates[containmentid].onPrimary) { + return m_corona->screenPool()->primaryScreenId(); + } else { + return m_pendingContainmentUpdates[containmentid].screen; + } + } + + //! there is a view present + Latte::View *view{nullptr}; + + if (m_latteViews.contains(containment)) { + view = m_latteViews[containment]; + } else if (m_waitingLatteViews.contains(containment)) { + view = m_waitingLatteViews[containment]; + } + + if (view && view->screen()) { + return m_corona->screenPool()->id(view->screen()->name()); + } + + //! fallback scenario + return containment->lastScreen(); +} + + Latte::View *GenericLayout::viewForContainment(Plasma::Containment *containment) const { if (m_containments.contains(containment) && m_latteViews.contains(containment)) { @@ -1322,6 +1361,25 @@ void GenericLayout::syncLatteViewsToScreens(Layout::ViewsMap *occupiedMap) qDebug() << "LAYOUT ::: " << name(); qDebug() << "screen count changed -+-+ " << qGuiApp->screens().size(); + //! Clear up pendingContainmentUpdates when no-needed any more + QStringList clearpendings; + for(int i=0; ilastScreen() == m_corona->screenPool()->primaryScreenId()) + || (!viewdata.onPrimary && containment->lastScreen() == viewdata.screen)) { + clearpendings << viewdata.id; + } + } + } + + for(auto pendingid : clearpendings) { + m_pendingContainmentUpdates.remove(pendingid); + } + + //! use valid views map based on active screens Layout::ViewsMap viewsMap = validViewsMap(occupiedMap); if (occupiedMap != nullptr) { @@ -1528,9 +1586,16 @@ void GenericLayout::updateView(const Latte::Data::View &viewData) //! active -> inactiveinmemory [viewscenario] auto containment = containmentForId(viewData.id.toUInt()); if (containment) { - qDebug() << " #$%#$%#%#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"; Layouts::Storage::self()->updateView(containment->config(), viewData); - qDebug() << " #22222222222222222222222%%%%%2222222222222%%%%"; + + //! by using pendingContainmentUpdates we make sure that when containment->screen() will be + //! called though reactToScreenChange() the proper screen will be returned + if (!m_pendingContainmentUpdates.containsId(viewData.id)) { + m_pendingContainmentUpdates << viewData; + } else { + m_pendingContainmentUpdates[viewData.id] = viewData; + } + containment->reactToScreenChange(); } //! complete update circle and inform the others about the changes diff --git a/app/layout/genericlayout.h b/app/layout/genericlayout.h index a629940de..dcc680aea 100644 --- a/app/layout/genericlayout.h +++ b/app/layout/genericlayout.h @@ -89,6 +89,9 @@ public: virtual Types::ViewType latteViewType(uint containmentId) const; const QList *containments() const; + bool contains(Plasma::Containment *containment) const; + int screenForContainment(Plasma::Containment *containment); + Latte::View *highestPriorityView(); Latte::View *viewForContainment(uint id) const; Latte::View *viewForContainment(Plasma::Containment *containment) const; @@ -207,6 +210,9 @@ private: //! try to avoid crashes from recreating the same views all the time QList m_viewsToRecreate; + //! Containments that are pending screen/state updates + Latte::Data::ViewsTable m_pendingContainmentUpdates; + friend class Latte::View; }; diff --git a/app/layouts/synchronizer.cpp b/app/layouts/synchronizer.cpp index 705e34671..bf4ba15fb 100644 --- a/app/layouts/synchronizer.cpp +++ b/app/layouts/synchronizer.cpp @@ -377,6 +377,17 @@ Layout::GenericLayout *Synchronizer::layout(QString layoutname) const return l; } +int Synchronizer::screenForContainment(Plasma::Containment *containment) +{ + for (auto layout : m_centralLayouts) { + if (layout->contains(containment)) { + return layout->screenForContainment(containment); + } + } + + return -1; +} + Latte::View *Synchronizer::viewForContainment(uint id) { for (auto layout : m_centralLayouts) { diff --git a/app/layouts/synchronizer.h b/app/layouts/synchronizer.h index 6e309e67f..14d5e0ac8 100644 --- a/app/layouts/synchronizer.h +++ b/app/layouts/synchronizer.h @@ -102,6 +102,7 @@ public: QStringList freeRunningActivities(); //! These are activities that haven't been assigned to specific layout QStringList validActivities(const QStringList &layoutActivities); + int screenForContainment(Plasma::Containment *containment); Latte::View *viewForContainment(Plasma::Containment *containment); Latte::View *viewForContainment(uint id);