Commit 85fc6be6 authored by Tanbir Jishan's avatar Tanbir Jishan 💬 Committed by Fushan Wen
Browse files

kcms/colors: Fix color previews not updating until apply is pressed

The reason colors are not updating correctly because there is no color(valid) to show in the first place. The color generation was later disabled when setting is not from wallpaper after the feature being implemented, I guess for efficiency. So we need to temporarily turn on the color engine, take the color and then again disable it. There is two reason for which we should always return a valid color for primary desktop:
1. We need to show the preview when asked.
2. There is a public dbus api which was added so that any third party code can get the correct wallpaper accent color any moment, regardless of setting. This may be useful, for example some app which always want to show some ui element in the wallpaper color.

BUG: 456835
FIXED-IN: 5.26

(cherry picked from commit 5b7c5a20)
parent 7da4de5c
Pipeline #242401 passed with stage
in 6 minutes and 11 seconds
......@@ -1503,13 +1503,52 @@ void ShellCorona::toggleDashboard()
void ShellCorona::handleColorRequestedFromDBus(const QDBusMessage &msg)
m_accentColorFromWallpaperEnabled = true;
Q_EMIT accentColorFromWallpaperEnabledChanged();
m_fakeColorRequestConn = connect(this, &ShellCorona::colorChanged, this, [this, msg] {
const QRgb color = m_desktopViewForScreen[m_screenPool->primaryScreen()]->accentColor().rgba();
m_accentColorFromWallpaperEnabled = false;
Q_EMIT accentColorFromWallpaperEnabledChanged();
const QDBusMessage reply = msg.createReply(color);
QRgb ShellCorona::color() const
// Colors from wallpaper are not generated when they are turned off in the settings.
// To return a color we need to fake that the setting is on, and then take the color,
// turn off the setting again(or the color engine will keep runnig) and return the color.
// Note that whenever a color is generated, it is also set as accent color. When we fake the
// setting, we should not apply the generated color. The color applying kded module take care
// of that by checking for the original state of the setting, so it is important that the check
// may not be removed accidentally.
static QRgb defaultColor = QColor(Qt::transparent).rgba();
auto const primaryDesktopViewExists = m_desktopViewForScreen.contains(m_screenPool->primaryScreen());
if (primaryDesktopViewExists) {
if (!primaryDesktopViewExists) {
return defaultColor;
if (m_accentColorFromWallpaperEnabled) {
return m_desktopViewForScreen[m_screenPool->primaryScreen()]->accentColor().rgba();
} else if (calledFromDBus()) {
if (m_fakeColorRequestConn) {
const_cast<ShellCorona *>(this)->handleColorRequestedFromDBus(message());
return QColor(Qt::transparent).rgba();
return defaultColor;
QString ShellCorona::evaluateScript(const QString &script)
......@@ -254,6 +254,7 @@ private:
void executeSetupPlasmoidScript(Plasma::Containment *containment, Plasma::Applet *applet);
void checkAllDesktopsUiReady(bool ready);
void activateLauncherMenu(const QString &screenName);
void handleColorRequestedFromDBus(const QDBusMessage &msg);
#ifndef NDEBUG
void screenInvariants() const;
......@@ -267,6 +268,7 @@ private:
// Accent color setting
KConfigWatcher::Ptr m_accentColorConfigWatcher;
bool m_accentColorFromWallpaperEnabled = false;
QMetaObject::Connection m_fakeColorRequestConn;
ScreenPool *m_screenPool;
QString m_shell;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment