From e303130ef6d736b77b76da8e17ea507fb2f3e976 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Tue, 19 Feb 2019 20:58:48 +0200 Subject: [PATCH] release broadcasted backgrounds when not needed --an example could be when the user decides to change wallpaper plugin for its desktop from a slideshow to other wallpaper plugins --- liblatte2/plasma/extended/backgroundcache.cpp | 21 ++++++++++++++++--- liblatte2/plasma/extended/backgroundcache.h | 12 ++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/liblatte2/plasma/extended/backgroundcache.cpp b/liblatte2/plasma/extended/backgroundcache.cpp index dc509ed2f..37fb23ac9 100644 --- a/liblatte2/plasma/extended/backgroundcache.cpp +++ b/liblatte2/plasma/extended/backgroundcache.cpp @@ -88,8 +88,7 @@ void BackgroundCache::settingsFileChanged(const QString &file) { } } -QString BackgroundCache::backgroundFromConfig(const KConfigGroup &config) const { - auto wallpaperPlugin = config.readEntry("wallpaperplugin"); +QString BackgroundCache::backgroundFromConfig(const KConfigGroup &config, QString wallpaperPlugin) const { auto wallpaperConfig = config.group("Wallpaper").group(wallpaperPlugin).group("General"); if (wallpaperConfig.hasKey("Image")) { @@ -131,6 +130,7 @@ void BackgroundCache::reload() for (const auto &containmentId : plasmaConfigContainments.groupList()) { const auto containment = plasmaConfigContainments.group(containmentId); + const auto wallpaperPlugin = containment.readEntry("wallpaperplugin", QString()); const auto lastScreen = containment.readEntry("lastScreen", 0); const auto activity = containment.readEntry("activityId", QString()); @@ -138,7 +138,7 @@ void BackgroundCache::reload() //! the containment is not a plasma desktop if (activity.isEmpty() || !isDesktopContainment(containment)) continue; - const auto returnedBackground = backgroundFromConfig(containment); + const auto returnedBackground = backgroundFromConfig(containment, wallpaperPlugin); QString background = returnedBackground; @@ -152,6 +152,16 @@ void BackgroundCache::reload() QString screenName = m_pool->connector(lastScreen); + //! Take case of broadcasted backgrounds, when their plugin is changed they should be disabled + if (pluginExistsFor(activity,screenName) + && m_plugins[activity][screenName] != wallpaperPlugin + && backgroundIsBroadcasted(activity, screenName)){ + //! in such case the Desktop changed wallpaper plugin and the broadcasted wallpapers should be removed + setBroadcastedBackgroundsEnabled(activity, screenName, false); + } + + m_plugins[activity][screenName] = wallpaperPlugin; + if (backgroundIsBroadcasted(activity, screenName)) { continue; } @@ -428,5 +438,10 @@ bool BackgroundCache::backgroundIsBroadcasted(QString activity, QString screenNa return m_broadcasted.contains(activity) && m_broadcasted[activity].contains(screenName); } +bool BackgroundCache::pluginExistsFor(QString activity, QString screenName) +{ + return m_plugins.contains(activity) && m_plugins[activity].contains(screenName); +} + } } diff --git a/liblatte2/plasma/extended/backgroundcache.h b/liblatte2/plasma/extended/backgroundcache.h index f3fe35bd4..3cea0989d 100644 --- a/liblatte2/plasma/extended/backgroundcache.h +++ b/liblatte2/plasma/extended/backgroundcache.h @@ -71,13 +71,14 @@ private: BackgroundCache(QObject *parent = nullptr); bool backgroundIsBroadcasted(QString activity, QString screenName); + bool pluginExistsFor(QString activity, QString screenName); bool areaIsBusy(float bright1, float bright2); bool busyForFile(QString imageFile, Plasma::Types::Location location); bool isDesktopContainment(const KConfigGroup &containment) const; float brightnessForFile(QString imageFile, Plasma::Types::Location location); float brightnessFromArea(QImage &image, int firstRow, int firstColumn, int endRow, int endColumn); - QString backgroundFromConfig(const KConfigGroup &config) const; + QString backgroundFromConfig(const KConfigGroup &config, QString wallpaperPlugin) const; void updateImageCalculations(QString imageFile, Plasma::Types::Location location); @@ -88,9 +89,14 @@ private: //! screen aware backgrounds: activity id, screen name, backgroundfile QHash> m_backgrounds; - //! backgrounds that are broadcasted (not found through plasma files) - //! for specific: activity id, screen names tracked + + //! plugin names tracked: activity id, screen name, pluginName + QHash> m_plugins; + + //! backgrounds that are broadcasted (not found through plasma files): + //! and have higher priority: activity id, screen names QHash> m_broadcasted; + //! image file and brightness per edge QHash m_hintsCache;