From bfa19dbc8fc7700187d867ea35c7b62e7d165cda Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 30 Mar 2018 13:06:15 +0200 Subject: [PATCH] add a version containmentForScreen with activity Summary: add a version of containmentForScreen which it has the activity. which is correct as the activity id of containments in in libplasma side. this ensure the correctness of shellCorona createContainmentForActivity as now it works also for activities different from the current one. to make multimonitor a tad safer with it, when creating containments for an activity, initialize their lastScreen to the asked screen. Test Plan: tried with an old plasmashell and is perfectly retrocompatible Reviewers: #plasma, davidedmundson Reviewed By: #plasma, davidedmundson Subscribers: davidedmundson, #frameworks Tags: #frameworks Differential Revision: https://phabricator.kde.org/D11361 --- src/plasma/corona.cpp | 72 +++++++++++++++++++++++++++++++---- src/plasma/corona.h | 38 +++++++++++++++++- src/plasma/private/corona_p.h | 2 +- 3 files changed, 101 insertions(+), 11 deletions(-) diff --git a/src/plasma/corona.cpp b/src/plasma/corona.cpp index 8ea0682a2..8ebe8bf05 100644 --- a/src/plasma/corona.cpp +++ b/src/plasma/corona.cpp @@ -196,8 +196,8 @@ Containment *Corona::containmentForScreen(int screen) const { 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 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 @@ Containment *Corona::containmentForScreen(int screen, 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,7 +300,7 @@ KSharedConfigPtr Corona::config() const 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 nullptr; @@ -256,7 +309,7 @@ Containment *Corona::createContainment(const QString &name, const QVariantList & 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 nullptr; @@ -447,7 +500,7 @@ void CoronaPrivate::syncConfig() 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 = nullptr; @@ -485,6 +538,9 @@ Containment *CoronaPrivate::addContainment(const QString &name, const QVariantLi 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 @@ QList CoronaPrivate::importLayout(const KConfigGroup &con #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/corona.h b/src/plasma/corona.h index 6a5d004bd..2464d9733 100644 --- a/src/plasma/corona.h +++ b/src/plasma/corona.h @@ -121,12 +121,30 @@ public: */ 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,10 +155,26 @@ public: * 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 diff --git a/src/plasma/private/corona_p.h b/src/plasma/private/corona_p.h index d556baf36..36a455e9f 100644 --- a/src/plasma/private/corona_p.h +++ b/src/plasma/private/corona_p.h @@ -47,7 +47,7 @@ public: 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;