Use Header color group for decoration colours
This commit is contained in:
parent
02b1e11758
commit
fbab964e98
2 changed files with 107 additions and 52 deletions
|
@ -5,6 +5,7 @@
|
|||
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
|
||||
SPDX-FileCopyrightText: 2014 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
||||
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
|
||||
*/
|
||||
|
@ -26,32 +27,23 @@ namespace Decoration
|
|||
{
|
||||
|
||||
DecorationPalette::DecorationPalette(const QString &colorScheme)
|
||||
: m_colorScheme(QFileInfo(colorScheme).isAbsolute()
|
||||
? colorScheme
|
||||
: QStandardPaths::locate(QStandardPaths::GenericConfigLocation, colorScheme))
|
||||
: m_colorScheme(colorScheme != QStringLiteral("kdeglobals") ? colorScheme : QString() )
|
||||
{
|
||||
if (!m_colorScheme.startsWith(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)) && colorScheme == QStringLiteral("kdeglobals")) {
|
||||
// kdeglobals doesn't exist so create it. This is needed to monitor it using QFileSystemWatcher.
|
||||
auto config = KSharedConfig::openConfig(colorScheme, KConfig::SimpleConfig);
|
||||
KConfigGroup wmConfig(config, QStringLiteral("WM"));
|
||||
wmConfig.writeEntry("FakeEntryToKeepThisGroup", true);
|
||||
config->sync();
|
||||
|
||||
m_colorScheme = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, colorScheme);
|
||||
if (m_colorScheme.isEmpty()) {
|
||||
m_colorSchemeConfig = KSharedConfig::openConfig(m_colorScheme, KConfig::FullConfig);
|
||||
} else {
|
||||
m_colorSchemeConfig = KSharedConfig::openConfig(m_colorScheme, KConfig::SimpleConfig);
|
||||
}
|
||||
m_watcher.addPath(m_colorScheme);
|
||||
connect(&m_watcher, &QFileSystemWatcher::fileChanged, [this]() {
|
||||
m_watcher.addPath(m_colorScheme);
|
||||
update();
|
||||
emit changed();
|
||||
});
|
||||
m_watcher = KConfigWatcher::create(m_colorSchemeConfig);
|
||||
|
||||
connect(m_watcher.data(), &KConfigWatcher::configChanged, this, &DecorationPalette::update);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
bool DecorationPalette::isValid() const
|
||||
{
|
||||
return m_activeTitleBarColor.isValid();
|
||||
return true;
|
||||
}
|
||||
|
||||
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::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) {
|
||||
case ColorRole::Frame:
|
||||
switch (group) {
|
||||
case ColorGroup::Active:
|
||||
return m_activeFrameColor;
|
||||
return m_palette.active.background().color();
|
||||
case ColorGroup::Inactive:
|
||||
return m_inactiveFrameColor;
|
||||
return m_palette.inactive.background().color();
|
||||
default:
|
||||
return QColor();
|
||||
}
|
||||
case ColorRole::TitleBar:
|
||||
switch (group) {
|
||||
case ColorGroup::Active:
|
||||
return m_activeTitleBarColor;
|
||||
return m_palette.active.background().color();
|
||||
case ColorGroup::Inactive:
|
||||
return m_inactiveTitleBarColor;
|
||||
return m_palette.inactive.background().color();
|
||||
default:
|
||||
return QColor();
|
||||
}
|
||||
case ColorRole::Foreground:
|
||||
switch (group) {
|
||||
case ColorGroup::Active:
|
||||
return m_activeForegroundColor;
|
||||
return m_palette.active.foreground().color();
|
||||
case ColorGroup::Inactive:
|
||||
return m_inactiveForegroundColor;
|
||||
return m_palette.inactive.foreground().color();
|
||||
case ColorGroup::Warning:
|
||||
return m_warningForegroundColor;
|
||||
return m_palette.inactive.foreground(KColorScheme::ForegroundRole::NegativeText).color();
|
||||
default:
|
||||
return QColor();
|
||||
}
|
||||
|
@ -96,31 +124,41 @@ QColor DecorationPalette::color(KDecoration2::ColorGroup group, KDecoration2::Co
|
|||
|
||||
QPalette DecorationPalette::palette() const
|
||||
{
|
||||
return m_palette;
|
||||
return m_legacyPalette ? m_legacyPalette->palette : KColorScheme::createApplicationPalette(m_colorSchemeConfig);
|
||||
}
|
||||
|
||||
void DecorationPalette::update()
|
||||
{
|
||||
auto config = KSharedConfig::openConfig(m_colorScheme, KConfig::SimpleConfig);
|
||||
KConfigGroup wmConfig(config, QStringLiteral("WM"));
|
||||
m_colorSchemeConfig->sync();
|
||||
|
||||
if (!wmConfig.exists() && !m_colorScheme.endsWith(QStringLiteral("/kdeglobals"))) {
|
||||
qCWarning(KWIN_DECORATIONS) << "Invalid color scheme" << m_colorScheme << "lacks WM group";
|
||||
return;
|
||||
if (!KColorScheme::isColorSetSupported(m_colorSchemeConfig, KColorScheme::Header)) {
|
||||
KConfigGroup wmConfig(m_colorSchemeConfig, QStringLiteral("WM"));
|
||||
|
||||
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);
|
||||
|
||||
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));
|
||||
|
||||
Q_EMIT changed();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,11 @@
|
|||
#include <KDecoration2/DecorationSettings>
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QPalette>
|
||||
#include <KSharedConfig>
|
||||
#include <KColorScheme>
|
||||
#include <KConfigWatcher>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
@ -38,19 +43,31 @@ private:
|
|||
void update();
|
||||
|
||||
QString m_colorScheme;
|
||||
QFileSystemWatcher m_watcher;
|
||||
KConfigWatcher::Ptr m_watcher;
|
||||
|
||||
QPalette m_palette;
|
||||
struct LegacyPalette {
|
||||
QPalette palette;
|
||||
|
||||
QColor m_activeTitleBarColor;
|
||||
QColor m_inactiveTitleBarColor;
|
||||
QColor activeTitleBarColor;
|
||||
QColor inactiveTitleBarColor;
|
||||
|
||||
QColor m_activeFrameColor;
|
||||
QColor m_inactiveFrameColor;
|
||||
QColor activeFrameColor;
|
||||
QColor inactiveFrameColor;
|
||||
|
||||
QColor m_activeForegroundColor;
|
||||
QColor m_inactiveForegroundColor;
|
||||
QColor m_warningForegroundColor;
|
||||
QColor activeForegroundColor;
|
||||
QColor inactiveForegroundColor;
|
||||
QColor warningForegroundColor;
|
||||
};
|
||||
|
||||
struct ModernPalette {
|
||||
KColorScheme active;
|
||||
KColorScheme inactive;
|
||||
};
|
||||
|
||||
std::optional<LegacyPalette> m_legacyPalette;
|
||||
KSharedConfig::Ptr m_colorSchemeConfig;
|
||||
|
||||
ModernPalette m_palette;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue