diff --git a/src/plasma/corona.h b/src/plasma/corona.h --- a/src/plasma/corona.h +++ b/src/plasma/corona.h @@ -122,11 +122,29 @@ Containment *createContainment(const QString &name, const QVariantList &args = QVariantList()); /** + * Returns the Containment for a given physical screen and desktop, creating one + * if none exists + * + * @param screen number of the physical screen to locate + * @param activity the activity id of the containment we want, + * and empty string if the activity is not important + * @param defaultPluginIfNonExistent the plugin to load by default; "null" won't + * create it and "default" creates the default plugin + * @param defaultArgs optional arguments to pass in when creating a Containment if needed + * @since 5.45 + */ + Containment *containmentForScreen(int screen, + const QString &activity, + const QString &defaultPluginIfNonExistent, + const QVariantList &defaultArgs = QVariantList()); + + //TODO KF6: add activity here, can't be done now as the overload would get confused + /** * Returns the Containment, if any, for a given physical screen * * @param screen number of the physical screen to locate */ - Containment *containmentForScreen(int screen) const; + PLASMA_DEPRECATED Containment *containmentForScreen(int screen) const; /** * Returns the Containment for a given physical screen and desktop, creating one @@ -137,11 +155,27 @@ * Containment and "default" creates the default plugin * @param defaultArgs optional arguments to pass in when creating a Containment if needed */ - Containment *containmentForScreen(int screen, + PLASMA_DEPRECATED PLASMA_DEPRECATED Containment *containmentForScreen(int screen, const QString &defaultPluginIfNonExistent, const QVariantList &defaultArgs = QVariantList()); /** + * Returns all containments which match a particular activity, for any screen + * @param activity the activity id we want + * @returns the list of matching containments if any, empty if activity is an empty string + * @since 5.45 + */ + QList containmentsForActivity(const QString &activity); + + /** + * Returns all containments which match a particular screen, for any activity + * @param screen the screen number we want + * @returns the list of matching containments if any, empty if screen is < 0 + * @since 5.45 + */ + QList containmentsForScreen(int screen); + + /** * Returns the number of screens available to plasma. * Subclasses should override this method as the default * implementation returns a meaningless value. diff --git a/src/plasma/corona.cpp b/src/plasma/corona.cpp --- a/src/plasma/corona.cpp +++ b/src/plasma/corona.cpp @@ -196,8 +196,8 @@ { foreach (Containment *containment, d->containments) { if (containment->screen() == screen && - (containment->containmentType() == Plasma::Types::DesktopContainment || - containment->containmentType() == Plasma::Types::CustomContainment)) { + (containment->containmentType() == Plasma::Types::DesktopContainment || + containment->containmentType() == Plasma::Types::CustomContainment)) { return containment; } } @@ -208,13 +208,30 @@ Containment *Corona::containmentForScreen(int screen, const QString &defaultPluginIfNonExistent, const QVariantList &defaultArgs) { - Containment *containment = containmentForScreen(screen); + return containmentForScreen(screen, QString(), defaultPluginIfNonExistent, defaultArgs); +} + +Containment *Corona::containmentForScreen(int screen, + const QString &activity, + const QString &defaultPluginIfNonExistent, const QVariantList &defaultArgs) +{ + Containment *containment = nullptr; + + foreach (Containment *cont, d->containments) { + if (cont->lastScreen() == screen && + (cont->activity().isEmpty() || cont->activity() == activity) && + (cont->containmentType() == Plasma::Types::DesktopContainment || + cont->containmentType() == Plasma::Types::CustomContainment)) { + containment = cont; + } + } + if (!containment && !defaultPluginIfNonExistent.isEmpty()) { // screen requests are allowed to bypass immutability if (screen >= 0) { Plasma::Types::ImmutabilityType imm = d->immutability; d->immutability = Types::Mutable; - containment = d->addContainment(defaultPluginIfNonExistent, defaultArgs, 0, false); + containment = d->addContainment(defaultPluginIfNonExistent, defaultArgs, 0, screen, false); if (containment) { // containment->setScreen(screen); } @@ -225,6 +242,42 @@ return containment; } +QList Corona::containmentsForActivity(const QString &activity) +{ + QList conts; + + if (activity.isEmpty()) { + return conts; + } + + std::copy_if(d->containments.begin(), + d->containments.end(), + std::back_inserter(conts), + [activity](Containment *cont) { return cont->activity() == activity && + (cont->containmentType() == Plasma::Types::DesktopContainment || + cont->containmentType() == Plasma::Types::CustomContainment);} ); + + return conts; +} + +QList Corona::containmentsForScreen(int screen) +{ + QList conts; + + if (screen < 0) { + return conts; + } + + std::copy_if(d->containments.begin(), + d->containments.end(), + std::back_inserter(conts), + [screen](Containment *cont) { return cont->lastScreen() == screen && + (cont->containmentType() == Plasma::Types::DesktopContainment || + cont->containmentType() == Plasma::Types::CustomContainment);} ); + + return conts; +} + QList Corona::containments() const { return d->containments; @@ -247,16 +300,16 @@ Containment *Corona::createContainment(const QString &name, const QVariantList &args) { if (d->immutability == Types::Mutable || args.contains(QVariant::fromValue(QStringLiteral("org.kde.plasma:force-create")))) { - return d->addContainment(name, args, 0); + return d->addContainment(name, args, -1, false); } return 0; } Containment *Corona::createContainmentDelayed(const QString &name, const QVariantList &args) { if (d->immutability == Types::Mutable) { - return d->addContainment(name, args, 0, true); + return d->addContainment(name, args, 0, -1, true); } return 0; @@ -447,7 +500,7 @@ emit q->configSynced(); } -Containment *CoronaPrivate::addContainment(const QString &name, const QVariantList &args, uint id, bool delayedInit) +Containment *CoronaPrivate::addContainment(const QString &name, const QVariantList &args, uint id, int lastScreen, bool delayedInit) { QString pluginName = name; Containment *containment = 0; @@ -485,6 +538,9 @@ delete applet; } applet = containment = new Containment(q, {}, id); + if (lastScreen >= 0) { + containment->d->lastScreen = lastScreen; + } //if it's a dummy containment, just say its ui is ready, not blocking the corona applet->updateConstraints(Plasma::Types::UiReadyConstraint); @@ -574,7 +630,7 @@ #ifndef NDEBUG // qCDebug(LOG_PLASMA) << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Adding Containment" << containmentConfig.readEntry("plugin", QString()); #endif - Containment *c = addContainment(containmentConfig.readEntry("plugin", QString()), QVariantList(), cid); + Containment *c = addContainment(containmentConfig.readEntry("plugin", QString()), QVariantList(), cid, -1); if (!c) { continue; } diff --git a/src/plasma/private/corona_p.h b/src/plasma/private/corona_p.h --- a/src/plasma/private/corona_p.h +++ b/src/plasma/private/corona_p.h @@ -47,7 +47,7 @@ void syncConfig(); void notifyContainmentsReady(); void containmentReady(bool ready); - Containment *addContainment(const QString &name, const QVariantList &args, uint id, bool delayedInit = false); + Containment *addContainment(const QString &name, const QVariantList &args, uint id, int lastScreen, bool delayedInit = false); QList importLayout(const KConfigGroup &conf, bool mergeConfig); Corona *q;