This adds an option to set the accent color from the current wallpaper. The way it works is that it exposes some DBus calls; if a wallpaper plugin supports wallpaper accent colors then it should say so by this DBus call when starting up and also should say which wallpaper is being currently used (for the purpose of extracting an accent color from it) or set an accent color itself. After that it should keep declaring the wallpaper or set accent color whenever wallpaper changes or whenever the plugin author thinks it is appropriate to say so. There is already an implementation of the color extracting algorithm which the plugin can either use, or else set whatever accent color it wants. The necessary DBus calls for the official image and wallpaper plugin are implemented, so they should work out of the box. BUG: 444676 FIXED-IN: 5.25wilder-5.25
parent
94b9a03ce2
commit
6eb2b52945
15 changed files with 284 additions and 9 deletions
@ -0,0 +1,47 @@ |
||||
#include <KPluginFactory> |
||||
#include <QDBusConnection> |
||||
|
||||
#include "../../kcms-common_p.h" |
||||
#include "accentColorService.h" |
||||
#include "accentcolor_service_adaptor.h" |
||||
#include "colorsapplicator.h" |
||||
|
||||
K_PLUGIN_CLASS_WITH_JSON(AccentColorService, "accentColorService.json") |
||||
|
||||
AccentColorService::AccentColorService(QObject *parent, const QList<QVariant> &) |
||||
: KDEDModule(parent) |
||||
, m_settings(new ColorsSettings(this)) |
||||
, m_model(new ColorsModel(this)) |
||||
{ |
||||
new AccentColorServiceAdaptor(this); |
||||
QDBusConnection dbus = QDBusConnection::sessionBus(); |
||||
dbus.registerObject("/AccentColor", this); |
||||
dbus.registerService("org.kde.plasmashell.accentColor"); |
||||
} |
||||
|
||||
void AccentColorService::setAccentColor(const QString &accentColor) |
||||
{ |
||||
m_settings->load(); |
||||
if (QColor::isValidColor(accentColor) && m_settings->accentColorFromWallpaper()) { |
||||
m_model->load(); |
||||
m_model->setSelectedScheme(m_settings->colorScheme()); |
||||
const QString path = |
||||
QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("color-schemes/%1.colors").arg(m_model->selectedScheme())); |
||||
|
||||
auto msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.KWin"), |
||||
QStringLiteral("/org/kde/KWin/BlendChanges"), |
||||
QStringLiteral("org.kde.KWin.BlendChanges"), |
||||
QStringLiteral("start")); |
||||
msg << 300; |
||||
// This is deliberately blocking so that we ensure Kwin has processed the
|
||||
// animation start event before we potentially trigger client side changes
|
||||
QDBusConnection::sessionBus().call(msg); |
||||
|
||||
m_settings->setAccentColor(accentColor); |
||||
m_settings->save(); |
||||
applyScheme(path, m_settings->config(), KConfig::Notify); |
||||
notifyKcmChange(GlobalChangeType::PaletteChanged); |
||||
} |
||||
} |
||||
|
||||
#include "accentColorService.moc" |
||||
@ -0,0 +1,22 @@ |
||||
|
||||
#pragma once |
||||
|
||||
#include "colorsmodel.h" |
||||
#include "colorssettings.h" |
||||
|
||||
#include <kdedmodule.h> |
||||
|
||||
class AccentColorService : public KDEDModule |
||||
{ |
||||
Q_OBJECT |
||||
Q_CLASSINFO("D-Bus Interface", "org.kde.plasmashell.accentColor") |
||||
public: |
||||
explicit AccentColorService(QObject *parent, const QList<QVariant> &); |
||||
|
||||
public Q_SLOTS: |
||||
void setAccentColor(const QString &color); |
||||
|
||||
private: |
||||
ColorsSettings *m_settings; |
||||
ColorsModel *m_model; |
||||
}; |
||||
@ -0,0 +1,8 @@ |
||||
{ |
||||
"KPlugin": { |
||||
"Description": "Applies extracted accent color from wallpaper on dbus request", |
||||
"Name": "accentColorService" |
||||
}, |
||||
"X-KDE-FactoryName": "accentColorService", |
||||
"X-KDE-Kded-autoload": true |
||||
} |
||||
Loading…
Reference in new issue