Use Header color group for decoration colours

master
Carson Black 2020-05-27 17:00:26 -04:00 committed by Jan Blackquill
parent 02b1e11758
commit fbab964e98
2 changed files with 107 additions and 52 deletions

View File

@ -5,6 +5,7 @@
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
SPDX-FileCopyrightText: 2014 Hugo Pereira Da Costa <hugo.pereira@free.fr> SPDX-FileCopyrightText: 2014 Hugo Pereira Da Costa <hugo.pereira@free.fr>
SPDX-FileCopyrightText: 2015 Mika Allan Rauhala <mika.allan.rauhala@gmail.com> SPDX-FileCopyrightText: 2015 Mika Allan Rauhala <mika.allan.rauhala@gmail.com>
SPDX-FileCopyrightText: 2020 Carson Black <uhhadd@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later SPDX-License-Identifier: GPL-2.0-or-later
*/ */
@ -26,32 +27,23 @@ namespace Decoration
{ {
DecorationPalette::DecorationPalette(const QString &colorScheme) DecorationPalette::DecorationPalette(const QString &colorScheme)
: m_colorScheme(QFileInfo(colorScheme).isAbsolute() : m_colorScheme(colorScheme != QStringLiteral("kdeglobals") ? colorScheme : QString() )
? colorScheme
: QStandardPaths::locate(QStandardPaths::GenericConfigLocation, colorScheme))
{ {
if (!m_colorScheme.startsWith(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)) && colorScheme == QStringLiteral("kdeglobals")) { if (m_colorScheme.isEmpty()) {
// kdeglobals doesn't exist so create it. This is needed to monitor it using QFileSystemWatcher. m_colorSchemeConfig = KSharedConfig::openConfig(m_colorScheme, KConfig::FullConfig);
auto config = KSharedConfig::openConfig(colorScheme, KConfig::SimpleConfig); } else {
KConfigGroup wmConfig(config, QStringLiteral("WM")); m_colorSchemeConfig = KSharedConfig::openConfig(m_colorScheme, KConfig::SimpleConfig);
wmConfig.writeEntry("FakeEntryToKeepThisGroup", true);
config->sync();
m_colorScheme = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, colorScheme);
} }
m_watcher.addPath(m_colorScheme); m_watcher = KConfigWatcher::create(m_colorSchemeConfig);
connect(&m_watcher, &QFileSystemWatcher::fileChanged, [this]() {
m_watcher.addPath(m_colorScheme); connect(m_watcher.data(), &KConfigWatcher::configChanged, this, &DecorationPalette::update);
update();
emit changed();
});
update(); update();
} }
bool DecorationPalette::isValid() const bool DecorationPalette::isValid() const
{ {
return m_activeTitleBarColor.isValid(); return true;
} }
QColor DecorationPalette::color(KDecoration2::ColorGroup group, KDecoration2::ColorRole role) const QColor DecorationPalette::color(KDecoration2::ColorGroup group, KDecoration2::ColorRole role) const
@ -59,33 +51,69 @@ QColor DecorationPalette::color(KDecoration2::ColorGroup group, KDecoration2::Co
using KDecoration2::ColorRole; using KDecoration2::ColorRole;
using KDecoration2::ColorGroup; using KDecoration2::ColorGroup;
if (m_legacyPalette.has_value()) {
switch (role) {
case ColorRole::Frame:
switch (group) {
case ColorGroup::Active:
return m_legacyPalette->activeFrameColor;
case ColorGroup::Inactive:
return m_legacyPalette->inactiveFrameColor;
default:
return QColor();
}
case ColorRole::TitleBar:
switch (group) {
case ColorGroup::Active:
return m_legacyPalette->activeTitleBarColor;
case ColorGroup::Inactive:
return m_legacyPalette->inactiveTitleBarColor;
default:
return QColor();
}
case ColorRole::Foreground:
switch (group) {
case ColorGroup::Active:
return m_legacyPalette->activeForegroundColor;
case ColorGroup::Inactive:
return m_legacyPalette->inactiveForegroundColor;
case ColorGroup::Warning:
return m_legacyPalette->warningForegroundColor;
default:
return QColor();
}
default:
return QColor();
}
}
switch (role) { switch (role) {
case ColorRole::Frame: case ColorRole::Frame:
switch (group) { switch (group) {
case ColorGroup::Active: case ColorGroup::Active:
return m_activeFrameColor; return m_palette.active.background().color();
case ColorGroup::Inactive: case ColorGroup::Inactive:
return m_inactiveFrameColor; return m_palette.inactive.background().color();
default: default:
return QColor(); return QColor();
} }
case ColorRole::TitleBar: case ColorRole::TitleBar:
switch (group) { switch (group) {
case ColorGroup::Active: case ColorGroup::Active:
return m_activeTitleBarColor; return m_palette.active.background().color();
case ColorGroup::Inactive: case ColorGroup::Inactive:
return m_inactiveTitleBarColor; return m_palette.inactive.background().color();
default: default:
return QColor(); return QColor();
} }
case ColorRole::Foreground: case ColorRole::Foreground:
switch (group) { switch (group) {
case ColorGroup::Active: case ColorGroup::Active:
return m_activeForegroundColor; return m_palette.active.foreground().color();
case ColorGroup::Inactive: case ColorGroup::Inactive:
return m_inactiveForegroundColor; return m_palette.inactive.foreground().color();
case ColorGroup::Warning: case ColorGroup::Warning:
return m_warningForegroundColor; return m_palette.inactive.foreground(KColorScheme::ForegroundRole::NegativeText).color();
default: default:
return QColor(); return QColor();
} }
@ -96,31 +124,41 @@ QColor DecorationPalette::color(KDecoration2::ColorGroup group, KDecoration2::Co
QPalette DecorationPalette::palette() const QPalette DecorationPalette::palette() const
{ {
return m_palette; return m_legacyPalette ? m_legacyPalette->palette : KColorScheme::createApplicationPalette(m_colorSchemeConfig);
} }
void DecorationPalette::update() void DecorationPalette::update()
{ {
auto config = KSharedConfig::openConfig(m_colorScheme, KConfig::SimpleConfig); m_colorSchemeConfig->sync();
KConfigGroup wmConfig(config, QStringLiteral("WM"));
if (!wmConfig.exists() && !m_colorScheme.endsWith(QStringLiteral("/kdeglobals"))) { if (!KColorScheme::isColorSetSupported(m_colorSchemeConfig, KColorScheme::Header)) {
qCWarning(KWIN_DECORATIONS) << "Invalid color scheme" << m_colorScheme << "lacks WM group"; KConfigGroup wmConfig(m_colorSchemeConfig, QStringLiteral("WM"));
return;
if (!wmConfig.exists()) {
m_palette.active = KColorScheme(QPalette::Normal, KColorScheme::Header, m_colorSchemeConfig);
m_palette.inactive = KColorScheme(QPalette::Inactive, KColorScheme::Header, m_colorSchemeConfig);
m_legacyPalette.reset();
return;
}
m_legacyPalette = LegacyPalette{};
m_legacyPalette->palette = KColorScheme::createApplicationPalette(m_colorSchemeConfig);
m_legacyPalette->activeFrameColor = wmConfig.readEntry("frame", m_legacyPalette->palette.color(QPalette::Active, QPalette::Window));
m_legacyPalette->inactiveFrameColor = wmConfig.readEntry("inactiveFrame", m_legacyPalette->activeFrameColor);
m_legacyPalette->activeTitleBarColor = wmConfig.readEntry("activeBackground", m_legacyPalette->palette.color(QPalette::Active, QPalette::Highlight));
m_legacyPalette->inactiveTitleBarColor = wmConfig.readEntry("inactiveBackground", m_legacyPalette->inactiveTitleBarColor);
m_legacyPalette->activeForegroundColor = wmConfig.readEntry("activeForeground", m_legacyPalette->palette.color(QPalette::Active, QPalette::HighlightedText));
m_legacyPalette->inactiveForegroundColor = wmConfig.readEntry("inactiveForeground", m_legacyPalette->activeForegroundColor.darker());
KConfigGroup windowColorsConfig(m_colorSchemeConfig, QStringLiteral("Colors:Window"));
m_legacyPalette->warningForegroundColor = windowColorsConfig.readEntry("ForegroundNegative", QColor(237, 21, 2));
} else {
m_palette.active = KColorScheme(QPalette::Normal, KColorScheme::Header, m_colorSchemeConfig);
m_palette.inactive = KColorScheme(QPalette::Inactive, KColorScheme::Header, m_colorSchemeConfig);
m_legacyPalette.reset();
} }
m_palette = KColorScheme::createApplicationPalette(config); Q_EMIT changed();
m_activeFrameColor = wmConfig.readEntry("frame", m_palette.color(QPalette::Active, QPalette::Window));
m_inactiveFrameColor = wmConfig.readEntry("inactiveFrame", m_activeFrameColor);
m_activeTitleBarColor = wmConfig.readEntry("activeBackground", m_palette.color(QPalette::Active, QPalette::Highlight));
m_inactiveTitleBarColor = wmConfig.readEntry("inactiveBackground", m_inactiveFrameColor);
m_activeForegroundColor = wmConfig.readEntry("activeForeground", m_palette.color(QPalette::Active, QPalette::HighlightedText));
m_inactiveForegroundColor = wmConfig.readEntry("inactiveForeground", m_activeForegroundColor.darker());
KConfigGroup windowColorsConfig(config, QStringLiteral("Colors:Window"));
m_warningForegroundColor = windowColorsConfig.readEntry("ForegroundNegative", QColor(237, 21, 2));
} }
} }

View File

@ -15,6 +15,11 @@
#include <KDecoration2/DecorationSettings> #include <KDecoration2/DecorationSettings>
#include <QFileSystemWatcher> #include <QFileSystemWatcher>
#include <QPalette> #include <QPalette>
#include <KSharedConfig>
#include <KColorScheme>
#include <KConfigWatcher>
#include <optional>
namespace KWin namespace KWin
{ {
@ -38,19 +43,31 @@ private:
void update(); void update();
QString m_colorScheme; QString m_colorScheme;
QFileSystemWatcher m_watcher; KConfigWatcher::Ptr m_watcher;
QPalette m_palette; struct LegacyPalette {
QPalette palette;
QColor m_activeTitleBarColor; QColor activeTitleBarColor;
QColor m_inactiveTitleBarColor; QColor inactiveTitleBarColor;
QColor m_activeFrameColor; QColor activeFrameColor;
QColor m_inactiveFrameColor; QColor inactiveFrameColor;
QColor m_activeForegroundColor; QColor activeForegroundColor;
QColor m_inactiveForegroundColor; QColor inactiveForegroundColor;
QColor m_warningForegroundColor; QColor warningForegroundColor;
};
struct ModernPalette {
KColorScheme active;
KColorScheme inactive;
};
std::optional<LegacyPalette> m_legacyPalette;
KSharedConfig::Ptr m_colorSchemeConfig;
ModernPalette m_palette;
}; };
} }