remove qml BackgroundTracker

--move to the new liblatte2 BackgroundTracker
which is also multi-screen aware
pull/4/head
Michail Vourlakos
parent 095048223a
commit fabd989146

@ -1,83 +0,0 @@
/*
* Copyright 2018 Michail Vourlakos <mvourlakos@gmail.com>
*
* This file is part of Latte-Dock
*
* Latte-Dock is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* Latte-Dock is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.7
import QtGraphicalEffects 1.0
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
Item{
id: tracker
property real currentBackgroundLuminas: -1000;
Connections{
target: plasmoid
onLocationChanged:{
tracker.currentBackgroundLuminas = universalSettings.luminasFromFile(activitiesList.currentLayoutBackground, plasmoid.location);
}
}
Repeater {
id: activitiesList
model: universalSettings ? universalSettings.runningActivitiesModel : null
property string currentLayoutBackground: ""
onCurrentLayoutBackgroundChanged: {
tracker.currentBackgroundLuminas = universalSettings.luminasFromFile(currentLayoutBackground, plasmoid.location);
}
Item {
id: activityItem
visible: false
property string activityId: model.id
property string title: model.name
property string background: model.background
property bool current: model.isCurrent
Component.onCompleted: {
if (managedLayout && forceColorizer && managedLayout.lastUsedActivity === activityId) {
activitiesList.currentLayoutBackground = background;
}
}
onBackgroundChanged: {
if (managedLayout && forceColorizer && managedLayout.lastUsedActivity === activityId) {
activitiesList.currentLayoutBackground = background;
}
}
Connections{
target: managedLayout
onLastUsedActivityChanged:{
if (managedLayout && forceColorizer && managedLayout.lastUsedActivity === activityItem.activityId) {
activitiesList.currentLayoutBackground = activityItem.background;
}
}
}
}
}
}

@ -47,7 +47,7 @@ Loader{
&& (plasmoid.configuration.solidBackgroundForMaximized || plasmoid.configuration.backgroundOnlyOnMaximized)
&& !root.editMode && Latte.WindowSystem.compositingActive
property real currentBackgroundLuminas: item ? item.currentBackgroundLuminas : -1000
property real currentBackgroundLuminas: item ? item.currentLuminas : -1000
property QtObject applyTheme: {
if (forceSolidnessAndColorize && latteView.visibility.touchingWindowScheme) {
@ -94,5 +94,11 @@ Loader{
return applyTheme.schemeFile;
}
sourceComponent: BackgroundTracker{}
sourceComponent: Latte.BackgroundTracker {
activity: managedLayout ? managedLayout.lastUsedActivity : ""
location: plasmoid.location
screenName: latteView && latteView.positioner ? latteView.positioner.currentScreenName : ""
onCurrentLuminasChanged: console.log("CURRENT LUMINAS !!! " + currentLuminas);
}
}

@ -27,12 +27,39 @@ BackgroundTracker::BackgroundTracker(QObject *parent)
: QObject(parent)
{
m_cache = PlasmaExtended::BackgroundCache::self();
connect(this, &BackgroundTracker::activityChanged, this, &BackgroundTracker::update);
connect(this, &BackgroundTracker::locationChanged, this, &BackgroundTracker::update);
connect(this, &BackgroundTracker::screenNameChanged, this, &BackgroundTracker::update);
}
BackgroundTracker::~BackgroundTracker()
{
}
int BackgroundTracker::location() const
{
return m_location;
}
void BackgroundTracker::setLocation(int location)
{
Plasma::Types::Location pLocation = static_cast<Plasma::Types::Location>(location);
if (m_location == pLocation) {
return;
}
m_location = pLocation;
emit locationChanged();
}
float BackgroundTracker::currentLuminas() const
{
return m_luminas;
}
QString BackgroundTracker::activity() const
{
return m_activity;
@ -65,4 +92,15 @@ void BackgroundTracker::setScreenName(QString name)
emit screenNameChanged();
}
void BackgroundTracker::update()
{
if (m_activity.isEmpty() || m_screenName.isEmpty()) {
return;
}
m_luminas = m_cache->luminasFor(m_activity, m_screenName, m_location);
emit currentLuminasChanged();
}
}

@ -33,6 +33,10 @@ class BackgroundTracker: public QObject
{
Q_OBJECT
Q_PROPERTY(int location READ location WRITE setLocation NOTIFY locationChanged)
Q_PROPERTY(float currentLuminas READ currentLuminas NOTIFY currentLuminasChanged)
Q_PROPERTY(QString activity READ activity WRITE setActivity NOTIFY activityChanged)
Q_PROPERTY(QString screenName READ screenName WRITE setScreenName NOTIFY screenNameChanged)
@ -40,6 +44,11 @@ public:
BackgroundTracker(QObject *parent = nullptr);
virtual ~BackgroundTracker();
int location() const;
void setLocation(int location);
float currentLuminas() const;
QString activity() const;
void setActivity(QString id);
@ -48,13 +57,25 @@ public:
signals:
void activityChanged();
void currentLuminasChanged();
void locationChanged();
void screenNameChanged();
private slots:
void update();
private:
// local
float m_luminas{-1000};
PlasmaExtended::BackgroundCache *m_cache{nullptr};
// Qt
QString m_activity;
QString m_screenName;
PlasmaExtended::BackgroundCache *m_cache{nullptr};
// Plasma
Plasma::Types::Location m_location{Plasma::Types::BottomEdge};
};
}

@ -21,6 +21,7 @@
#include "latteplugin.h"
// local
#include "backgroundtracker.h"
#include "iconitem.h"
#include "quickwindowsystem.h"
#include "types.h"
@ -32,6 +33,7 @@ void LattePlugin::registerTypes(const char *uri)
{
Q_ASSERT(uri == QLatin1String("org.kde.latte"));
qmlRegisterUncreatableType<Latte::Types>(uri, 0, 2, "Types", "Latte Types uncreatable");
qmlRegisterType<Latte::BackgroundTracker>(uri, 0, 2, "BackgroundTracker");
qmlRegisterType<Latte::IconItem>(uri, 0, 2, "IconItem");
qmlRegisterSingletonType<Latte::QuickWindowSystem>(uri, 0, 2, "WindowSystem", &Latte::windowsystem_qobject_singletontype_provider);
}

@ -23,21 +23,42 @@
#include "commontools.h"
// Qt
#include <QDebug>
#include <QImage>
#include <QRgb>
// Plasma
#include <Plasma>
// KDE
#include <KConfigGroup>
#include <KDirWatch>
#define PLASMACONFIG "plasma-org.kde.plasma.desktop-appletsrc"
#define DEFAULTWALLPAPER "/usr/share/wallpapers/Next/contents/images/1920x1080.png"
namespace Latte{
namespace PlasmaExtended {
BackgroundCache::BackgroundCache(QObject *parent)
: QObject(parent)
: QObject(parent),
m_initialized(false),
m_plasmaConfig(KSharedConfig::openConfig(PLASMACONFIG))
{
const auto configFile = QStandardPaths::writableLocation(
QStandardPaths::GenericConfigLocation) +
QLatin1Char('/') + PLASMACONFIG;
KDirWatch::self()->addFile(configFile);
connect(KDirWatch::self(), &KDirWatch::dirty, this, &BackgroundCache::settingsFileChanged);
connect(KDirWatch::self(), &KDirWatch::created, this, &BackgroundCache::settingsFileChanged);
if (!m_pool) {
m_pool = new ScreenPool(this);
}
reload();
}
BackgroundCache::~BackgroundCache()
@ -53,11 +74,93 @@ BackgroundCache *BackgroundCache::self()
return &cache;
}
float BackgroundCache::luminasFromFile(QString imageFile, int edge)
void BackgroundCache::settingsFileChanged(const QString &file) {
if (!file.endsWith(PLASMACONFIG)) {
return;
}
if (m_initialized) {
m_plasmaConfig->reparseConfiguration();
reload();
}
}
QString BackgroundCache::backgroundFromConfig(const KConfigGroup &config) const {
auto wallpaperPlugin = config.readEntry("wallpaperplugin");
auto wallpaperConfig = config.group("Wallpaper").group(wallpaperPlugin).group("General");
if (wallpaperConfig.hasKey("Image")) {
// Trying for the wallpaper
auto wallpaper = wallpaperConfig.readEntry("Image", QString());
if (!wallpaper.isEmpty()) {
return wallpaper;
}
}
if (wallpaperConfig.hasKey("Color")) {
auto backgroundColor = wallpaperConfig.readEntry("Color", QColor(0, 0, 0));
return backgroundColor.name();
}
return QString();
}
void BackgroundCache::reload() {
// Traversing through all containments in search for
// containments that define activities in plasma
KConfigGroup plasmaConfigContainments = m_plasmaConfig->group("Containments");
for (const auto &containmentId : plasmaConfigContainments.groupList()) {
const auto containment = plasmaConfigContainments.group(containmentId);
const auto lastScreen = containment.readEntry("lastScreen", 0);
const auto activity = containment.readEntry("activityId", QString());
// Ignore the containment if the activity is not defined
if (activity.isEmpty()) continue;
const auto returnedBackground = backgroundFromConfig(containment);
QString background = returnedBackground;
if (background.startsWith("file://")) {
background = returnedBackground.mid(7);
}
if (background.isEmpty()) continue;
m_backgrounds[activity][m_pool->connector(lastScreen)] = background;
}
m_initialized = true;
qDebug() << m_backgrounds;
}
QString BackgroundCache::background(QString activity, QString screen)
{
QImage image(imageFile);
if (m_backgrounds.contains(activity) && m_backgrounds[activity].contains(screen)) {
return m_backgrounds[activity][screen];
} else {
return DEFAULTWALLPAPER;
}
}
float BackgroundCache::luminasFor(QString activity, QString screen, Plasma::Types::Location location)
{
QString assignedBackground = background(activity, screen);
if (!assignedBackground.isEmpty()) {
return luminasFromFile(assignedBackground, location);
}
Plasma::Types::Location location = static_cast<Plasma::Types::Location>(edge);
return -1000;
}
float BackgroundCache::luminasFromFile(QString imageFile, Plasma::Types::Location location)
{
QImage image(imageFile);
if (m_luminasCache.keys().contains(imageFile)) {
if (m_luminasCache[imageFile].keys().contains(location)) {

@ -30,6 +30,10 @@
// Plasma
#include <Plasma>
// KDE
#include <KConfigGroup>
#include <KSharedConfig>
typedef QHash<Plasma::Types::Location, float> EdgesHash;
namespace Latte {
@ -43,19 +47,31 @@ public:
static BackgroundCache *self();
~BackgroundCache() override;
float luminasFromFile(QString imageFile, int edge);
float luminasFor(QString activity, QString screen, Plasma::Types::Location location);
QString background(QString activity, QString screen);
private slots:
void reload();
void settingsFileChanged(const QString &file);
private:
BackgroundCache(QObject *parent = nullptr);
float luminasFromFile(QString imageFile, Plasma::Types::Location location);
QString backgroundFromConfig(const KConfigGroup &config) const;
private:
bool m_initialized{false};
ScreenPool *m_pool{nullptr};
//! screen aware backgrounds: activity id, screen name, backgroundfile
QHash<QString, QHash<QString, QString>> m_backgrounds;
//! image file and luminas per edge
QHash<QString, EdgesHash> m_luminasCache;
ScreenPool *m_pool{nullptr};
KSharedConfig::Ptr m_plasmaConfig;
};
}

Loading…
Cancel
Save