diff --git a/decorations/decorationpalette.cpp b/decorations/decorationpalette.cpp index f2350177c..3d9a867c0 100644 --- a/decorations/decorationpalette.cpp +++ b/decorations/decorationpalette.cpp @@ -1,138 +1,124 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright 2014 Martin Gräßlin Copyright 2014 Hugo Pereira Da Costa Copyright 2015 Mika Allan Rauhala This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "decorationpalette.h" #include "decorations_logging.h" #include #include #include #include #include #include namespace KWin { namespace Decoration { DecorationPalette::DecorationPalette(const QString &colorScheme) : m_colorScheme(QFileInfo(colorScheme).isAbsolute() ? colorScheme : QStandardPaths::locate(QStandardPaths::GenericConfigLocation, colorScheme)) { 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); } m_watcher.addPath(m_colorScheme); connect(&m_watcher, &QFileSystemWatcher::fileChanged, [this]() { m_watcher.addPath(m_colorScheme); update(); emit changed(); }); update(); } bool DecorationPalette::isValid() const { - return m_activeTitleBarColor.isValid(); + return true; } +#define ColorSchemeColor(qpalette, colorset, kind) KColorScheme(QPalette::qpalette, KColorScheme::ColorSet::colorset, m_colorSchemeConfig).kind().color() +#define ColorSchemeColorWithForegroundKind(qpalette, colorset, kind, foreground) KColorScheme(QPalette::qpalette, KColorScheme::ColorSet::colorset, m_colorSchemeConfig).kind(KColorScheme::ForegroundRole::foreground).color() +#define ColorSchemeColorWithShade(qpalette, colorset, shadekind) KColorScheme(QPalette::qpalette, KColorScheme::ColorSet::colorset, m_colorSchemeConfig).shade(KColorScheme::ShadeRole::shadekind) + QColor DecorationPalette::color(KDecoration2::ColorGroup group, KDecoration2::ColorRole role) const { using KDecoration2::ColorRole; using KDecoration2::ColorGroup; switch (role) { case ColorRole::Frame: switch (group) { case ColorGroup::Active: - return m_activeFrameColor; + return ColorSchemeColorWithShade(Normal, Header, ShadowShade); case ColorGroup::Inactive: - return m_inactiveFrameColor; + return ColorSchemeColorWithShade(Inactive, Header, ShadowShade); default: return QColor(); } case ColorRole::TitleBar: switch (group) { case ColorGroup::Active: - return m_activeTitleBarColor; + return ColorSchemeColor(Normal, Header, background); case ColorGroup::Inactive: - return m_inactiveTitleBarColor; + return ColorSchemeColor(Inactive, Header, background); default: return QColor(); } case ColorRole::Foreground: switch (group) { case ColorGroup::Active: - return m_activeForegroundColor; + return ColorSchemeColor(Normal, Header, foreground); case ColorGroup::Inactive: - return m_inactiveForegroundColor; + return ColorSchemeColor(Inactive, Header, foreground); case ColorGroup::Warning: - return m_warningForegroundColor; + return ColorSchemeColorWithForegroundKind(Inactive, Header, foreground, NegativeText); default: return QColor(); } default: return QColor(); } } QPalette DecorationPalette::palette() const { return m_palette; } void DecorationPalette::update() { - auto config = KSharedConfig::openConfig(m_colorScheme, KConfig::SimpleConfig); - KConfigGroup wmConfig(config, QStringLiteral("WM")); - - if (!wmConfig.exists() && !m_colorScheme.endsWith(QStringLiteral("/kdeglobals"))) { - qCWarning(KWIN_DECORATIONS) << "Invalid color scheme" << m_colorScheme << "lacks WM group"; - return; - } - - 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)); - + m_colorSchemeConfig = KSharedConfig::openConfig(m_colorScheme, KConfig::SimpleConfig); + m_palette = KColorScheme::createApplicationPalette(m_colorSchemeConfig); } } } diff --git a/decorations/decorationpalette.h b/decorations/decorationpalette.h index f652c4e33..381944c3f 100644 --- a/decorations/decorationpalette.h +++ b/decorations/decorationpalette.h @@ -1,70 +1,63 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright 2014 Martin Gräßlin Copyright 2014 Hugo Pereira Da Costa Copyright 2015 Mika Allan Rauhala This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #ifndef KWIN_DECORATION_PALETTE_H #define KWIN_DECORATION_PALETTE_H #include #include #include +#include namespace KWin { namespace Decoration { class DecorationPalette : public QObject { Q_OBJECT public: DecorationPalette(const QString &colorScheme); bool isValid() const; QColor color(KDecoration2::ColorGroup group, KDecoration2::ColorRole role) const; QPalette palette() const; Q_SIGNALS: void changed(); private: void update(); QString m_colorScheme; QFileSystemWatcher m_watcher; - QPalette m_palette; - - QColor m_activeTitleBarColor; - QColor m_inactiveTitleBarColor; + KSharedConfig::Ptr m_colorSchemeConfig; - QColor m_activeFrameColor; - QColor m_inactiveFrameColor; - - QColor m_activeForegroundColor; - QColor m_inactiveForegroundColor; - QColor m_warningForegroundColor; + QPalette m_palette; }; } } #endif