improve/support BackgroundTracker in app
--the new implementation is much improved and easy to support. No workaround and direct use of the librariespull/15/head
parent
63187ce5b4
commit
deb9c244ff
@ -1,104 +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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "commontools.h"
|
||||
|
||||
// Qt
|
||||
#include <QFileInfo>
|
||||
#include <QStandardPaths>
|
||||
#include <QtMath>
|
||||
|
||||
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 "";
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef COMMONTOOLS_H
|
||||
#define COMMONTOOLS_H
|
||||
|
||||
// Qt
|
||||
#include <QColor>
|
||||
|
||||
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
|
@ -1,6 +0,0 @@
|
||||
set(lattecoreplugin_SRCS
|
||||
${lattecoreplugin_SRCS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/backgroundcache.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/screenpool.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
@ -1,137 +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/>.
|
||||
*/
|
||||
|
||||
#include "screenpool.h"
|
||||
|
||||
// Qt
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QGuiApplication>
|
||||
#include <QScreen>
|
||||
|
||||
// KDE
|
||||
#include <KConfigGroup>
|
||||
#include <KDirWatch>
|
||||
#include <KSharedConfig>
|
||||
|
||||
#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<int, QString> connectorForId = m_connectorForId;
|
||||
QHash<QString, int> 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,66 +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/>.
|
||||
*/
|
||||
|
||||
#ifndef PLASMASCREENPOOL_H
|
||||
#define PLASMASCREENPOOL_H
|
||||
|
||||
// Qt
|
||||
#include <QHash>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
|
||||
// KDE
|
||||
#include <KConfigGroup>
|
||||
|
||||
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<int, QString> m_screens;
|
||||
|
||||
//order is important
|
||||
QMap<int, QString> m_connectorForId;
|
||||
QHash<QString, int> m_idForConnector;
|
||||
|
||||
KConfigGroup m_screensGroup;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 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 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue