diff --git a/app/lattecorona.cpp b/app/lattecorona.cpp index 652b4de75..80b4fdf64 100644 --- a/app/lattecorona.cpp +++ b/app/lattecorona.cpp @@ -36,6 +36,8 @@ #include "layouts/launcherssignals.h" #include "shortcuts/globalshortcuts.h" #include "package/lattepackage.h" +#include "plasma/extended/backgroundcache.h" +#include "plasma/extended/backgroundtracker.h" #include "plasma/extended/screengeometries.h" #include "plasma/extended/screenpool.h" #include "plasma/extended/theme.h" @@ -148,12 +150,6 @@ Corona::Corona(bool defaultLayoutOnStartup, QString layoutNameOnStartUp, int use m_viewsScreenSyncTimer.setInterval(m_universalSettings->screenTrackerInterval()); }); - //! initialize the background tracer for broadcasted backgrounds - m_backgroundTracer = new KDeclarative::QmlObjectSharedEngine(this); - m_backgroundTracer->setInitializationDelayed(true); - m_backgroundTracer->setSource(kPackage().filePath("backgroundTracer")); - m_backgroundTracer->completeInitialization(); - //! Dbus adaptor initialization new LatteDockAdaptor(this); QDBusConnection dbus = QDBusConnection::sessionBus(); @@ -198,7 +194,6 @@ Corona::~Corona() m_screenPool->deleteLater(); m_universalSettings->deleteLater(); m_plasmaScreenPool->deleteLater(); - m_backgroundTracer->deleteLater(); m_themeExtended->deleteLater(); m_indicatorFactory->deleteLater(); @@ -1245,20 +1240,12 @@ void Corona::setBackgroundFromBroadcast(QString activity, QString screenName, QS filename = filename.remove(0,7); } - QMetaObject::invokeMethod(m_backgroundTracer->rootObject(), - "setBackgroundFromBroadcast", - Q_ARG(QVariant, activity), - Q_ARG(QVariant, screenName), - Q_ARG(QVariant, filename)); + PlasmaExtended::BackgroundCache::self()->setBackgroundFromBroadcast(activity, screenName, filename); } void Corona::setBroadcastedBackgroundsEnabled(QString activity, QString screenName, bool enabled) { - QMetaObject::invokeMethod(m_backgroundTracer->rootObject(), - "setBroadcastedBackgroundsEnabled", - Q_ARG(QVariant, activity), - Q_ARG(QVariant, screenName), - Q_ARG(QVariant, enabled)); + PlasmaExtended::BackgroundCache::self()->setBroadcastedBackgroundsEnabled(activity, screenName, enabled); } void Corona::toggleHiddenState(QString layoutName, QString screenName, int screenEdge) @@ -1284,6 +1271,9 @@ inline void Corona::qmlRegisterTypes() const "Settings", // name in QML "Error: only enums of latte app settings"); + qmlRegisterType("org.kde.latte.private.app", 0, 1, "BackgroundTracker"); + + #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) qmlRegisterType(); qmlRegisterType(); diff --git a/app/lattecorona.h b/app/lattecorona.h index ad1127fa1..b46d6ed77 100644 --- a/app/lattecorona.h +++ b/app/lattecorona.h @@ -220,8 +220,6 @@ private: QList m_alternativesObjects; - KDeclarative::QmlObjectSharedEngine *m_backgroundTracer; - QTimer m_viewsScreenSyncTimer; KActivities::Consumer *m_activitiesConsumer; diff --git a/app/package/lattepackage.cpp b/app/package/lattepackage.cpp index eabc9522e..3fba4d020 100644 --- a/app/package/lattepackage.cpp +++ b/app/package/lattepackage.cpp @@ -64,8 +64,6 @@ void Package::initPackage(KPackage::Package *package) package->addFileDefinition("preset4", QStringLiteral("presets/Extended.layout.latte"), i18n("extended preset file")); package->addFileDefinition("preset10", QStringLiteral("presets/multiple-layouts_hidden.layout.latte"), i18n("multiple layouts hidden file")); - package->addFileDefinition("backgroundTracer", QStringLiteral("scripting/BackgroundTracer.qml"), i18n("a qml file that is used to publish broadcasted backgrounds")); - package->setFallbackPackage(fallback); qDebug() << "package is valid" << package->isValid(); } diff --git a/app/plasma/extended/CMakeLists.txt b/app/plasma/extended/CMakeLists.txt index eee265dda..b78c64661 100644 --- a/app/plasma/extended/CMakeLists.txt +++ b/app/plasma/extended/CMakeLists.txt @@ -1,5 +1,7 @@ set(lattedock-app_SRCS ${lattedock-app_SRCS} + ${CMAKE_CURRENT_SOURCE_DIR}/backgroundcache.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/backgroundtracker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/screengeometries.cpp ${CMAKE_CURRENT_SOURCE_DIR}/screenpool.cpp ${CMAKE_CURRENT_SOURCE_DIR}/theme.cpp diff --git a/declarativeimports/core/plasma/extended/backgroundcache.cpp b/app/plasma/extended/backgroundcache.cpp similarity index 99% rename from declarativeimports/core/plasma/extended/backgroundcache.cpp rename to app/plasma/extended/backgroundcache.cpp index 51585c422..f7267c75f 100644 --- a/declarativeimports/core/plasma/extended/backgroundcache.cpp +++ b/app/plasma/extended/backgroundcache.cpp @@ -20,7 +20,7 @@ #include "backgroundcache.h" // local -#include "../../commontools.h" +#include "../../tools/commontools.h" // Qt #include diff --git a/declarativeimports/core/plasma/extended/backgroundcache.h b/app/plasma/extended/backgroundcache.h similarity index 100% rename from declarativeimports/core/plasma/extended/backgroundcache.h rename to app/plasma/extended/backgroundcache.h diff --git a/declarativeimports/core/backgroundtracker.cpp b/app/plasma/extended/backgroundtracker.cpp similarity index 87% rename from declarativeimports/core/backgroundtracker.cpp rename to app/plasma/extended/backgroundtracker.cpp index 1a4e3d3dd..d176ba3f3 100644 --- a/declarativeimports/core/backgroundtracker.cpp +++ b/app/plasma/extended/backgroundtracker.cpp @@ -119,14 +119,4 @@ void BackgroundTracker::update() emit isBusyChanged(); } -void BackgroundTracker::setBackgroundFromBroadcast(QString activity, QString screen, QString filename) -{ - PlasmaExtended::BackgroundCache::self()->setBackgroundFromBroadcast(activity, screen, filename); -} - -void BackgroundTracker::setBroadcastedBackgroundsEnabled(QString activity, QString screen, bool enabled) -{ - PlasmaExtended::BackgroundCache::self()->setBroadcastedBackgroundsEnabled(activity, screen, enabled); -} - } diff --git a/declarativeimports/core/backgroundtracker.h b/app/plasma/extended/backgroundtracker.h similarity index 91% rename from declarativeimports/core/backgroundtracker.h rename to app/plasma/extended/backgroundtracker.h index b82697647..d0215826b 100644 --- a/declarativeimports/core/backgroundtracker.h +++ b/app/plasma/extended/backgroundtracker.h @@ -59,10 +59,6 @@ public: QString screenName() const; void setScreenName(QString name); -public slots: - Q_INVOKABLE void setBackgroundFromBroadcast(QString activity, QString screen, QString filename); - Q_INVOKABLE void setBroadcastedBackgroundsEnabled(QString activity, QString screen, bool enabled); - signals: void activityChanged(); void currentBrightnessChanged(); diff --git a/containment/package/contents/ui/colorizer/Manager.qml b/containment/package/contents/ui/colorizer/Manager.qml index b98344a7f..0628bb6d6 100644 --- a/containment/package/contents/ui/colorizer/Manager.qml +++ b/containment/package/contents/ui/colorizer/Manager.qml @@ -23,6 +23,7 @@ import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.latte.core 0.2 as LatteCore +import org.kde.latte.private.app 0.1 as LatteApp import org.kde.latte.private.containment 0.1 as LatteContainment import "../../code/ColorizerTools.js" as ColorizerTools @@ -198,7 +199,7 @@ Loader{ return applyTheme.schemeFile; } - sourceComponent: LatteCore.BackgroundTracker { + sourceComponent: LatteApp.BackgroundTracker { activity: viewLayout ? viewLayout.lastUsedActivity : "" location: plasmoid.location screenName: latteView && latteView.positioner ? latteView.positioner.currentScreenName : "" diff --git a/declarativeimports/core/CMakeLists.txt b/declarativeimports/core/CMakeLists.txt index 63109b0a3..40d326569 100644 --- a/declarativeimports/core/CMakeLists.txt +++ b/declarativeimports/core/CMakeLists.txt @@ -2,16 +2,12 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-latte-lib.h.cmake ${CMAKE_CURR set(lattecoreplugin_SRCS lattecoreplugin.cpp - backgroundtracker.cpp environment.cpp - commontools.cpp iconitem.cpp quickwindowsystem.cpp types.h ) -add_subdirectory(plasma/extended) - add_library(lattecoreplugin SHARED ${lattecoreplugin_SRCS}) target_link_libraries(lattecoreplugin diff --git a/declarativeimports/core/commontools.cpp b/declarativeimports/core/commontools.cpp deleted file mode 100644 index a963c1aa9..000000000 --- a/declarativeimports/core/commontools.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2018 Michail Vourlakos - * - * 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 . - * - */ - -#include "commontools.h" - -// Qt -#include -#include -#include - -namespace Latte { - -float colorBrightness(QColor color) -{ - return colorBrightness(color.red(), color.green(), color.blue()); -} - -float colorBrightness(QRgb rgb) -{ - return colorBrightness(qRed(rgb), qGreen(rgb), qBlue(rgb)); -} - -float colorBrightness(float r, float g, float b) -{ - float brightness = (r * 299 + g * 587 + b * 114) / 1000; - - return brightness; -} - - -float colorLumina(QRgb rgb) -{ - float r = (float)(qRed(rgb)) / 255; - float g = (float)(qGreen(rgb)) / 255; - float b = (float)(qBlue(rgb)) / 255; - - return colorLumina(r, g, b); -} - -float colorLumina(QColor color) -{ - return colorLumina(color.redF(), color.greenF(), color.blueF()); -} - -float colorLumina(float r, float g, float b) -{ - // formula for luminance according to: - // https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef - - float rS = (r <= 0.03928 ? r / 12.92 : qPow(((r + 0.055) / 1.055), 2.4)); - float gS = (g <= 0.03928 ? g / 12.92 : qPow(((g + 0.055) / 1.055), 2.4)); - float bS = (b <= 0.03928 ? b / 12.92 : qPow(((b + 0.055) / 1.055), 2.4)); - - float luminosity = 0.2126 * rS + 0.7152 * gS + 0.0722 * bS; - - return luminosity; -} - -QString standardPath(QString subPath, bool localfirst) -{ - QStringList paths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); - - if (localfirst) { - for (const auto &pt : paths) { - QString ptF = pt + "/" +subPath; - if (QFileInfo(ptF).exists()) { - return ptF; - } - } - } else { - for (int i=paths.count()-1; i>=0; i--) { - QString ptF = paths[i] + "/" +subPath; - if (QFileInfo(ptF).exists()) { - return ptF; - } - } - } - - //! in any case that above fails - if (QFileInfo("/usr/share/"+subPath).exists()) { - return "/usr/share/"+subPath; - } - - return ""; -} - -} diff --git a/declarativeimports/core/commontools.h b/declarativeimports/core/commontools.h deleted file mode 100644 index 1da1cb3f3..000000000 --- a/declarativeimports/core/commontools.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2018 Michail Vourlakos - * - * 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 . - * - */ - -#ifndef COMMONTOOLS_H -#define COMMONTOOLS_H - -// Qt -#include - -namespace Latte { - -float colorBrightness(QColor color); -float colorBrightness(QRgb rgb); -float colorBrightness(float r, float g, float b); - -float colorLumina(QColor color); -float colorLumina(QRgb rgb); -float colorLumina(float r, float g, float b); - -//! returns the standard path found that contains the subPath -//! local paths have higher priority by default -QString standardPath(QString subPath, bool localFirst = true); -} - -#endif diff --git a/declarativeimports/core/lattecoreplugin.cpp b/declarativeimports/core/lattecoreplugin.cpp index 19e07408f..78f53bcf9 100644 --- a/declarativeimports/core/lattecoreplugin.cpp +++ b/declarativeimports/core/lattecoreplugin.cpp @@ -21,7 +21,6 @@ #include "lattecoreplugin.h" // local -#include "backgroundtracker.h" #include "environment.h" #include "iconitem.h" #include "quickwindowsystem.h" @@ -36,7 +35,6 @@ void LatteCorePlugin::registerTypes(const char *uri) { Q_ASSERT(uri == QLatin1String("org.kde.latte.core")); qmlRegisterUncreatableType(uri, 0, 2, "Types", "Latte Types uncreatable"); - qmlRegisterType(uri, 0, 2, "BackgroundTracker"); qmlRegisterType(uri, 0, 2, "IconItem"); qmlRegisterSingletonType(uri, 0, 2, "Environment", &Latte::environment_qobject_singletontype_provider); qmlRegisterSingletonType(uri, 0, 2, "WindowSystem", &Latte::windowsystem_qobject_singletontype_provider); diff --git a/declarativeimports/core/plasma/extended/CMakeLists.txt b/declarativeimports/core/plasma/extended/CMakeLists.txt deleted file mode 100644 index 904394b37..000000000 --- a/declarativeimports/core/plasma/extended/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -set(lattecoreplugin_SRCS - ${lattecoreplugin_SRCS} - ${CMAKE_CURRENT_SOURCE_DIR}/backgroundcache.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/screenpool.cpp - PARENT_SCOPE -) diff --git a/declarativeimports/core/plasma/extended/screenpool.cpp b/declarativeimports/core/plasma/extended/screenpool.cpp deleted file mode 100644 index 84d4fca7c..000000000 --- a/declarativeimports/core/plasma/extended/screenpool.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* -* Copyright 2018 Michail Vourlakos -* -* 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 . -*/ - -#include "screenpool.h" - -// Qt -#include -#include -#include -#include - -// KDE -#include -#include -#include - -#define PLASMARC "plasmashellrc" - -namespace Latte { -namespace PlasmaExtended { - -ScreenPool::ScreenPool(QObject *parent) - : QObject(parent) -{ - KSharedConfigPtr plasmaPtr = KSharedConfig::openConfig(PLASMARC); - m_screensGroup = KConfigGroup(plasmaPtr, "ScreenConnectors"); - - load(); - - QString plasmaSettingsFile = QDir::homePath() + "/.config/" + PLASMARC; - - KDirWatch::self()->addFile(plasmaSettingsFile); - - connect(KDirWatch::self(), &KDirWatch::dirty, this, [ &, plasmaSettingsFile](const QString & path) { - if (path == plasmaSettingsFile) { - load(); - } - }); - - connect(KDirWatch::self(), &KDirWatch::created, this, [ &, plasmaSettingsFile](const QString & path) { - if (path == plasmaSettingsFile) { - load(); - } - }); -} - - -ScreenPool::~ScreenPool() -{ -} - -void ScreenPool::load() -{ - QMap connectorForId = m_connectorForId; - QHash idForConnector = m_idForConnector; - - m_connectorForId.clear(); - m_idForConnector.clear(); - - bool updated{false}; - - for (const auto &screenId : m_screensGroup.keyList()) { - QString screenName = m_screensGroup.readEntry(screenId, QString()); - if (screenId != 0) { - int scrId = screenId.toInt(); - insertScreenMapping(scrId, screenName); - - if (!connectorForId.contains(scrId) || connectorForId[scrId] != m_connectorForId[scrId]) { - updated = true; - } - } - } - - //! If there are changes then print the new plasma screen ids and send a relevant signal - if (connectorForId.count() != m_connectorForId.count()) { - updated = true; - } - - if (updated) { - qDebug() << "---------------- Plasma Screen Ids ------------------"; - for (const auto &id : m_connectorForId.keys()) { - qDebug() << id << " __ " << m_connectorForId[id]; - } - qDebug() << "---------------- --------------- ------------------"; - - emit idsChanged(); - } -} - -void ScreenPool::insertScreenMapping(int id, const QString &connector) -{ - if (id==0 || connector.startsWith(":")) { - return; - } - - m_connectorForId[id] = connector; - m_idForConnector[connector] = id; -} - -int ScreenPool::id(const QString &connector) const -{ - if (!m_idForConnector.contains(connector)) { - //! return 0 for primary screen, -1 for not found - return qGuiApp->primaryScreen()->name() == connector ? 0 : -1; - } - - return m_idForConnector.value(connector); -} - -QString ScreenPool::connector(int id) const -{ - if (!m_connectorForId.contains(id)) { - return id == 0 ? qGuiApp->primaryScreen()->name() : QString(); - } - - return m_connectorForId.value(id); -} - - -} -} diff --git a/declarativeimports/core/plasma/extended/screenpool.h b/declarativeimports/core/plasma/extended/screenpool.h deleted file mode 100644 index 87a6aaa6a..000000000 --- a/declarativeimports/core/plasma/extended/screenpool.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -* Copyright 2018 Michail Vourlakos -* -* 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 . -*/ - -#ifndef PLASMASCREENPOOL_H -#define PLASMASCREENPOOL_H - -// Qt -#include -#include -#include - -// KDE -#include - -namespace Latte { -namespace PlasmaExtended { - -class ScreenPool: public QObject -{ - Q_OBJECT - -public: - ScreenPool(QObject *parent = nullptr); - ~ScreenPool() override; - - int id(const QString &connector) const; - QString connector(int id) const; - -signals: - void idsChanged(); - -private slots: - void load(); - void insertScreenMapping(int id, const QString &connector); - -private: - QHash m_screens; - - //order is important - QMap m_connectorForId; - QHash m_idForConnector; - - KConfigGroup m_screensGroup; -}; - -} -} - - -#endif diff --git a/shell/package/contents/scripting/BackgroundTracer.qml b/shell/package/contents/scripting/BackgroundTracer.qml deleted file mode 100644 index 80b6c06ae..000000000 --- a/shell/package/contents/scripting/BackgroundTracer.qml +++ /dev/null @@ -1,39 +0,0 @@ -/* -* Copyright 2019 Michail Vourlakos -* -* 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 . -*/ - -import QtQuick 2.7 -import org.kde.latte.core 0.2 as LatteCore - -Item{ - LatteCore.BackgroundTracker { - id: backgroundTracker - } - - function setBackgroundFromBroadcast(activity, screen, filename) { - console.log(" Background Tracer set image ::: " + activity + " _ " + screen + " _ " + filename); - backgroundTracker.setBackgroundFromBroadcast(activity, screen, filename); - } - - function setBroadcastedBackgroundsEnabled(activity, screen, enabled) { - console.log(" Background Tracer State ::: " + activity + " _ " + screen + " _ " + enabled); - backgroundTracker.setBroadcastedBackgroundsEnabled(activity, screen, enabled); - } - - -}