Verified Commit 52393639 authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

shell: add new property `usedInAccentColor`

It will be used to indicate whether the desktop is used in accent color
extraction.

CCBUG: 456038
parent 17774bc4
Pipeline #197398 passed with stage
in 7 minutes and 34 seconds
......@@ -56,9 +56,8 @@ DesktopView::DesktopView(Plasma::Corona *corona, QScreen *targetScreen)
setTitle(corona->kPackage().metadata().name());
rootContext()->setContextProperty(QStringLiteral("desktop"), this);
setSource(corona->kPackage().fileUrl("views", QStringLiteral("Desktop.qml")));
connect(this, &ContainmentView::containmentChanged, this, &DesktopView::slotContainmentChanged);
connect(this, &QWindow::screenChanged, this, &DesktopView::adaptToScreen);
connect(this, &DesktopView::accentColorChanged, this, &DesktopView::setAccentColorFromWallpaper);
QObject::connect(corona, &Plasma::Corona::kPackageChanged, this, &DesktopView::coronaPackageChanged);
......@@ -78,6 +77,16 @@ DesktopView::DesktopView(Plasma::Corona *corona, QScreen *targetScreen)
m_activateKRunnerWhenTypingOnDesktop = group.readEntry("ActivateWhenTypingOnDesktop", true);
}
});
// Accent color setting
connect(static_cast<ShellCorona *>(corona), &ShellCorona::accentColorFromWallpaperEnabledChanged, this, &DesktopView::usedInAccentColorChanged);
connect(this, &DesktopView::usedInAccentColorChanged, this, [this] {
if (!usedInAccentColor()) {
m_accentColor = QStringLiteral("transparent");
Q_EMIT accentColorChanged(m_accentColor);
}
});
connect(this, &ContainmentView::containmentChanged, this, &DesktopView::slotContainmentChanged);
}
DesktopView::~DesktopView()
......@@ -129,6 +138,20 @@ void DesktopView::adaptToScreen()
m_oldScreen = m_screenToFollow;
}
bool DesktopView::usedInAccentColor() const
{
if (!m_containment) {
return false;
}
const bool notPrimaryDisplay = m_containment->screen() != 0;
if (notPrimaryDisplay) {
return false;
}
return static_cast<ShellCorona *>(corona())->accentColorFromWallpaperEnabled();
}
QString DesktopView::accentColor() const
{
return m_accentColor;
......@@ -136,10 +159,17 @@ QString DesktopView::accentColor() const
void DesktopView::setAccentColor(const QString &accentColor)
{
if (accentColor != m_accentColor) {
m_accentColor = accentColor;
Q_EMIT accentColorChanged(m_accentColor);
if (accentColor == m_accentColor) {
return;
}
m_accentColor = accentColor;
Q_EMIT accentColorChanged(m_accentColor);
if (usedInAccentColor()) {
Q_EMIT static_cast<ShellCorona *>(corona())->colorChanged(m_accentColor);
}
setAccentColorFromWallpaper(m_accentColor);
}
DesktopView::WindowType DesktopView::windowType() const
......@@ -352,6 +382,30 @@ void DesktopView::showConfigurationInterface(Plasma::Applet *applet)
m_configView->requestActivate();
}
void DesktopView::slotContainmentChanged()
{
if (m_containment) {
disconnect(m_containment, &Plasma::Containment::screenChanged, this, &DesktopView::slotScreenChanged);
}
m_containment = containment();
if (m_containment) {
connect(m_containment, &Plasma::Containment::screenChanged, this, &DesktopView::slotScreenChanged);
slotScreenChanged(m_containment->screen());
}
}
void DesktopView::slotScreenChanged(int newId)
{
if (m_containmentScreenId == newId) {
return;
}
m_containmentScreenId = newId;
Q_EMIT usedInAccentColorChanged();
}
void DesktopView::screenGeometryChanged()
{
const QRect geo = m_screenToFollow->geometry();
......@@ -392,8 +446,7 @@ void DesktopView::setupWaylandIntegration()
void DesktopView::setAccentColorFromWallpaper(const QString &accentColor)
{
auto const notPrimaryDisplay = containment()->screen() != 0;
if (notPrimaryDisplay) {
if (!usedInAccentColor()) {
return;
}
QDBusMessage applyAccentColor = QDBusMessage::createMethodCall("org.kde.plasmashell.accentColor", "/AccentColor", "", "setAccentColor");
......
......@@ -30,6 +30,16 @@ class DesktopView : public PlasmaQuick::ContainmentView
Q_PROPERTY(SessionType sessionType READ sessionType CONSTANT)
Q_PROPERTY(QVariantMap candidateContainments READ candidateContainmentsGraphicItems NOTIFY candidateContainmentsChanged)
/**
* Whether the desktop is used in accent color extraction
*
* @note When usedInAccentColor becomes @c true, \Kirigami.ImageColors
* will be loaded and update the accent color, and \setAccentColor will
* be called
*/
Q_PROPERTY(bool usedInAccentColor READ usedInAccentColor NOTIFY usedInAccentColorChanged)
Q_PROPERTY(QString accentColor READ accentColor WRITE setAccentColor NOTIFY accentColorChanged)
public:
......@@ -58,6 +68,9 @@ public:
void adaptToScreen();
void showEvent(QShowEvent *) override;
bool usedInAccentColor() const;
QString accentColor() const;
void setAccentColor(const QString &);
......@@ -81,6 +94,8 @@ protected Q_SLOTS:
void showConfigurationInterface(Plasma::Applet *applet) override;
private Q_SLOTS:
void slotContainmentChanged();
void slotScreenChanged(int newId);
void screenGeometryChanged();
Q_SIGNALS:
......@@ -88,6 +103,7 @@ Q_SIGNALS:
void windowTypeChanged();
void candidateContainmentsChanged();
void geometryChanged();
void usedInAccentColorChanged();
void accentColorChanged(const QString &accentColor);
private:
......@@ -108,4 +124,8 @@ private:
// KRunner config
KConfigWatcher::Ptr m_configWatcher;
bool m_activateKRunnerWhenTypingOnDesktop;
// Accent color config
Plasma::Containment *m_containment = nullptr;
int m_containmentScreenId = -1;
};
......@@ -102,6 +102,22 @@ ShellCorona::ShellCorona(QObject *parent)
KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE");
const QString packageName = cg.readEntry("LookAndFeelPackage", QString());
m_lookAndFeelPackage = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel"), packageName);
// Accent color setting
KSharedConfigPtr globalConfig = KSharedConfig::openConfig();
KConfigGroup accentColorConfigGroup(globalConfig, "General");
m_accentColorFromWallpaperEnabled = accentColorConfigGroup.readEntry("accentColorFromWallpaper", false);
m_accentColorConfigWatcher = KConfigWatcher::create(globalConfig);
connect(m_accentColorConfigWatcher.data(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group, const QByteArrayList &names) {
if (names.contains(QByteArrayLiteral("accentColorFromWallpaper"))) {
const bool result = group.readEntry("accentColorFromWallpaper", false);
if (m_accentColorFromWallpaperEnabled != result) {
m_accentColorFromWallpaperEnabled = result;
Q_EMIT accentColorFromWallpaperEnabledChanged();
}
}
});
}
void ShellCorona::init()
......@@ -743,7 +759,6 @@ void ShellCorona::load()
connect(m_screenPool, &ScreenPool::screenAdded, this, &ShellCorona::addOutput, Qt::UniqueConnection);
connect(m_screenPool, &ScreenPool::screenRemoved, this, &ShellCorona::handleScreenRemoved, Qt::UniqueConnection);
connect(m_screenPool, &ScreenPool::primaryScreenChanged, this, &ShellCorona::primaryScreenChanged, Qt::UniqueConnection);
connect(m_desktopViewForScreen[m_screenPool->primaryScreen()], &DesktopView::accentColorChanged, this, &ShellCorona::colorChanged);
if (!m_waitingPanels.isEmpty()) {
m_waitingPanelsTimer.start();
......@@ -787,10 +802,6 @@ void ShellCorona::primaryScreenChanged(QScreen *oldPrimary, QScreen *newPrimary)
// can't do the screen invariant here as reconsideroutputs wasn't executed yet
// CHECK_SCREEN_INVARIANTS
// refresh the accent color signal binding
disconnect(m_desktopViewForScreen.value(oldPrimary), &DesktopView::accentColorChanged, this, &ShellCorona::colorChanged);
connect(m_desktopViewForScreen.value(newPrimary), &DesktopView::accentColorChanged, this, &ShellCorona::colorChanged);
}
#ifndef NDEBUG
......@@ -2021,6 +2032,11 @@ QString ShellCorona::containmentPreviewPath(Plasma::Containment *containment) co
}
}
bool ShellCorona::accentColorFromWallpaperEnabled() const
{
return m_accentColorFromWallpaperEnabled;
}
void ShellCorona::nextActivity()
{
m_activityController->nextActivity();
......
......@@ -16,6 +16,7 @@
#include <QSet>
#include <QTimer>
#include <KConfigWatcher>
#include <KPackage/Package>
class DesktopView;
......@@ -126,10 +127,16 @@ public:
// If a containment preview has been grabbed, for this containment, return its path
QString containmentPreviewPath(Plasma::Containment *containment) const;
/**
* Whether "accent color from wallpaper" option is enabled in global settings
*/
bool accentColorFromWallpaperEnabled() const;
Q_SIGNALS:
void glInitializationFailed();
// A preview for this containment has been rendered and saved to disk
void containmentPreviewReady(Plasma::Containment *containment, const QString &path);
void accentColorFromWallpaperEnabledChanged();
void colorChanged(const QString &color);
public Q_SLOTS:
......@@ -248,6 +255,10 @@ private:
KSharedConfig::Ptr m_config;
QString m_configPath;
// Accent color setting
KConfigWatcher::Ptr m_accentColorConfigWatcher;
bool m_accentColorFromWallpaperEnabled = false;
ScreenPool *m_screenPool;
QString m_shell;
KActivities::Controller *m_activityController;
......
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