diff --git a/app/lattecorona.cpp b/app/lattecorona.cpp index 2741a72cd..7607df23c 100644 --- a/app/lattecorona.cpp +++ b/app/lattecorona.cpp @@ -907,6 +907,11 @@ void Corona::aboutApplication() aboutDialog->show(); } +void Corona::loadDefaultLayout() +{ + //disabled +} + int Corona::screenForContainment(const Plasma::Containment *containment) const { //FIXME: indexOf is not a proper way to support multi-screen @@ -1030,61 +1035,6 @@ void Corona::alternativesVisibilityChanged(bool visible) } } -void Corona::addViewForLayout(QString layoutName) -{ - qDebug() << "loading default layout"; - //! Setting mutable for create a containment - setImmutability(Plasma::Types::Mutable); - QVariantList args; - auto defaultContainment = createContainmentDelayed("org.kde.latte.containment", args); - defaultContainment->setContainmentType(Plasma::Types::PanelContainment); - defaultContainment->init(); - - if (!defaultContainment || !defaultContainment->kPackage().isValid()) { - qWarning() << "the requested containment plugin can not be located or loaded"; - return; - } - - auto config = defaultContainment->config(); - defaultContainment->restore(config); - - using Plasma::Types; - QList edges{Types::BottomEdge, Types::LeftEdge, - Types::TopEdge, Types::RightEdge}; - - Layout::GenericLayout *currentLayout = m_layoutsManager->synchronizer()->layout(layoutName); - - if (currentLayout) { - edges = currentLayout->freeEdges(defaultContainment->screen()); - } - - if ((edges.count() > 0)) { - defaultContainment->setLocation(edges.at(0)); - } else { - defaultContainment->setLocation(Plasma::Types::BottomEdge); - } - - if (m_layoutsManager->memoryUsage() == MemoryUsage::MultipleLayouts) { - config.writeEntry("layoutId", layoutName); - } - - defaultContainment->updateConstraints(Plasma::Types::StartupCompletedConstraint); - - defaultContainment->save(config); - requestConfigSync(); - - defaultContainment->flushPendingConstraintsEvents(); - emit containmentAdded(defaultContainment); - emit containmentCreated(defaultContainment); - - defaultContainment->createApplet(QStringLiteral("org.kde.latte.plasmoid")); -} - -void Corona::loadDefaultLayout() -{ - // addViewForLayout(m_layoutsManager->currentLayoutsNames()); -} - QStringList Corona::containmentsIds() { QStringList ids; diff --git a/app/lattecorona.h b/app/lattecorona.h index 7c738b7f6..91818c395 100644 --- a/app/lattecorona.h +++ b/app/lattecorona.h @@ -163,7 +163,6 @@ public: public slots: void aboutApplication(); - void addViewForLayout(QString layoutName); void activateLauncherMenu(); void loadDefaultLayout() override; void setBackgroundFromBroadcast(QString activity, QString screenName, QString filename); diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index d4d59e561..b30b1aa86 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -768,16 +768,6 @@ void GenericLayout::renameLayout(QString newName) } } -void GenericLayout::addNewView() -{ - if (!m_corona) { - return; - } - - m_corona->addViewForLayout(name()); - emit viewEdgeChanged(); -} - void GenericLayout::addView(Plasma::Containment *containment, bool forceOnPrimary, int explicitScreen, Layout::ViewsMap *occupied) { qDebug() << "Layout :::: " << m_layoutName << " ::: addView was called... m_containments :: " << m_containments.size(); @@ -1685,6 +1675,24 @@ void GenericLayout::copyView(Plasma::Containment *containment) emit viewEdgeChanged(); } +void GenericLayout::newView(const QString &templateFile) +{ + //! Don't create LatteView when the containment is created because we must update its screen settings first + setBlockAutomaticLatteViewCreation(true); + + Layouts::ViewDelayedCreationData result = Layouts::Storage::self()->newView(this, templateFile); + if (result.containment) { + addView(result.containment, result.forceOnPrimary, result.explicitScreen); + + if (result.reactToScreenChange) { + result.containment->reactToScreenChange(); + } + } + + setBlockAutomaticLatteViewCreation(false); + emit viewEdgeChanged(); +} + void GenericLayout::importToCorona() { Layouts::Storage::self()->importToCorona(this); diff --git a/app/layout/genericlayout.h b/app/layout/genericlayout.h index 0e19f331c..65f45cce4 100644 --- a/app/layout/genericlayout.h +++ b/app/layout/genericlayout.h @@ -146,7 +146,7 @@ public: QList viewsScreens(); public slots: - Q_INVOKABLE void addNewView(); + Q_INVOKABLE void newView(const QString &templateFile); Q_INVOKABLE int viewsWithTasks() const; virtual Q_INVOKABLE QList qmlFreeEdges(int screen) const; //change to types diff --git a/app/layouts/storage.cpp b/app/layouts/storage.cpp index f870e9724..3f44968f9 100644 --- a/app/layouts/storage.cpp +++ b/app/layouts/storage.cpp @@ -544,19 +544,23 @@ ViewDelayedCreationData Storage::newView(const Layout::GenericLayout *destinatio Plasma::Containment *newContainment = (importedViews.size() == 1 ? importedViews[0] : nullptr); if (!newContainment || !newContainment->kPackage().isValid()) { - qWarning() << "the requested containment plugin can not be located or loaded"; + qWarning() << "the requested containment plugin can not be located or loaded from:" << templateFile; return ViewDelayedCreationData(); } auto config = newContainment->config(); int primaryScrId = destination->corona()->screenPool()->primaryScreenId(); - QList edges = destination->freeEdges(newContainment->screen()); + QList edges = destination->freeEdges(primaryScrId); + qDebug() << "org.kde.latte current template edge : " << newContainment->location() << " free edges :: " << edges; - if (edges.count() > 0) { - newContainment->setLocation(edges.at(0)); - } else { - newContainment->setLocation(Plasma::Types::BottomEdge); + //! if selected template screen edge is not free + if (!edges.contains(newContainment->location())) { + if (edges.count() > 0) { + newContainment->setLocation(edges.at(0)); + } else { + newContainment->setLocation(Plasma::Types::BottomEdge); + } } config.writeEntry("onPrimary", true); diff --git a/shell/package/contents/configuration/LatteDockConfiguration.qml b/shell/package/contents/configuration/LatteDockConfiguration.qml index acf3f1397..d07a9dbcf 100644 --- a/shell/package/contents/configuration/LatteDockConfiguration.qml +++ b/shell/package/contents/configuration/LatteDockConfiguration.qml @@ -530,7 +530,7 @@ Loader { var item = actionsModel.get(index); if (item.actionId === "new:") { - + latteView.layout.newView(item.templateId); } else if (item.actionId === "copy:") { latteView.copyView(); } else if (item.actionId === "move:") { @@ -552,7 +552,7 @@ Loader { Connections{ target: actionsComboBtn.button - onClicked: latteView.layout.addNewView(); + onClicked: latteView.layout.newView(layoutsManager.viewTemplateIds()[0]) } Connections{ diff --git a/shell/package/contents/templates/Panel.view.latte b/shell/package/contents/templates/Panel.view.latte index 090503cce..08883e21b 100644 --- a/shell/package/contents/templates/Panel.view.latte +++ b/shell/package/contents/templates/Panel.view.latte @@ -7,7 +7,7 @@ formfactor=2 immutability=1 isPreferredForShortcuts=false lastScreen=-1 -location=4 +location=3 onPrimary=true plugin=org.kde.latte.containment raiseOnActivityChange=false