diff --git a/decorations/decorationpalette.cpp b/decorations/decorationpalette.cpp index 5d7916d25..0ac54bfc1 100644 --- a/decorations/decorationpalette.cpp +++ b/decorations/decorationpalette.cpp @@ -1,138 +1,138 @@ /******************************************************************** 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.isEmpty() && 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(); } 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; case ColorGroup::Inactive: return m_inactiveFrameColor; default: return QColor(); } case ColorRole::TitleBar: switch (group) { case ColorGroup::Active: return m_activeTitleBarColor; case ColorGroup::Inactive: return m_inactiveTitleBarColor; default: return QColor(); } case ColorRole::Foreground: switch (group) { case ColorGroup::Active: return m_activeForegroundColor; case ColorGroup::Inactive: return m_inactiveForegroundColor; case ColorGroup::Warning: return m_warningForegroundColor; 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.dark()); + m_inactiveForegroundColor = wmConfig.readEntry("inactiveForeground", m_activeForegroundColor.darker()); KConfigGroup windowColorsConfig(config, QStringLiteral("Colors:Window")); m_warningForegroundColor = windowColorsConfig.readEntry("ForegroundNegative", QColor(237, 21, 2)); } } } diff --git a/plugins/kdecorations/aurorae/src/decorationoptions.cpp b/plugins/kdecorations/aurorae/src/decorationoptions.cpp index cc21d9c8b..055175ee8 100644 --- a/plugins/kdecorations/aurorae/src/decorationoptions.cpp +++ b/plugins/kdecorations/aurorae/src/decorationoptions.cpp @@ -1,269 +1,269 @@ /******************************************************************** Copyright (C) 2012 Martin Gräßlin 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 "decorationoptions.h" #include #include #include #include #include #include namespace KWin { ColorSettings::ColorSettings(const QPalette &pal) { init(pal); } void ColorSettings::update(const QPalette &pal) { init(pal); } void ColorSettings::init(const QPalette &pal) { m_palette = pal; KConfigGroup wmConfig(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), QStringLiteral("WM")); m_activeFrameColor = wmConfig.readEntry("frame", pal.color(QPalette::Active, QPalette::Window)); m_inactiveFrameColor = wmConfig.readEntry("inactiveFrame", m_activeFrameColor); m_activeTitleBarColor = wmConfig.readEntry("activeBackground", pal.color(QPalette::Active, QPalette::Highlight)); m_inactiveTitleBarColor = wmConfig.readEntry("inactiveBackground", m_inactiveFrameColor); - m_activeTitleBarBlendColor = wmConfig.readEntry("activeBlend", m_activeTitleBarColor.dark(110)); - m_inactiveTitleBarBlendColor = wmConfig.readEntry("inactiveBlend", m_inactiveTitleBarColor.dark(110)); + m_activeTitleBarBlendColor = wmConfig.readEntry("activeBlend", m_activeTitleBarColor.darker(110)); + m_inactiveTitleBarBlendColor = wmConfig.readEntry("inactiveBlend", m_inactiveTitleBarColor.darker(110)); m_activeFontColor = wmConfig.readEntry("activeForeground", pal.color(QPalette::Active, QPalette::HighlightedText)); - m_inactiveFontColor = wmConfig.readEntry("inactiveForeground", m_activeFontColor.dark()); - m_activeButtonColor = wmConfig.readEntry("activeTitleBtnBg", m_activeFrameColor.light(130)); - m_inactiveButtonColor = wmConfig.readEntry("inactiveTitleBtnBg", m_inactiveFrameColor.light(130)); + m_inactiveFontColor = wmConfig.readEntry("inactiveForeground", m_activeFontColor.darker()); + m_activeButtonColor = wmConfig.readEntry("activeTitleBtnBg", m_activeFrameColor.lighter(130)); + m_inactiveButtonColor = wmConfig.readEntry("inactiveTitleBtnBg", m_inactiveFrameColor.lighter(130)); m_activeHandle = wmConfig.readEntry("handle", m_activeFrameColor); m_inactiveHandle = wmConfig.readEntry("inactiveHandle", m_activeHandle); } DecorationOptions::DecorationOptions(QObject *parent) : QObject(parent) , m_active(true) , m_decoration(nullptr) , m_colors(ColorSettings(QPalette())) { connect(this, &DecorationOptions::decorationChanged, this, &DecorationOptions::slotActiveChanged); connect(this, &DecorationOptions::decorationChanged, this, &DecorationOptions::colorsChanged); connect(this, &DecorationOptions::decorationChanged, this, &DecorationOptions::fontChanged); connect(this, &DecorationOptions::decorationChanged, this, &DecorationOptions::titleButtonsChanged); } DecorationOptions::~DecorationOptions() { } QColor DecorationOptions::borderColor() const { return m_active ? m_colors.activeFrame() : m_colors.inactiveFrame(); } QColor DecorationOptions::buttonColor() const { return m_active ? m_colors.activeButtonColor() : m_colors.inactiveButtonColor(); } QColor DecorationOptions::fontColor() const { return m_active ? m_colors.activeFont() : m_colors.inactiveFont(); } QColor DecorationOptions::resizeHandleColor() const { return m_active ? m_colors.activeHandle() : m_colors.inactiveHandle(); } QColor DecorationOptions::titleBarBlendColor() const { return m_active ? m_colors.activeTitleBarBlendColor() : m_colors.inactiveTitleBarBlendColor(); } QColor DecorationOptions::titleBarColor() const { return m_active ? m_colors.activeTitleBarColor() : m_colors.inactiveTitleBarColor(); } QFont DecorationOptions::titleFont() const { return m_decoration ? m_decoration->settings()->font() : QFont(); } static int decorationButton(KDecoration2::DecorationButtonType type) { switch (type) { case KDecoration2::DecorationButtonType::Menu: return DecorationOptions::DecorationButtonMenu; case KDecoration2::DecorationButtonType::ApplicationMenu: return DecorationOptions::DecorationButtonApplicationMenu; case KDecoration2::DecorationButtonType::OnAllDesktops: return DecorationOptions::DecorationButtonOnAllDesktops; case KDecoration2::DecorationButtonType::Minimize: return DecorationOptions::DecorationButtonMinimize; case KDecoration2::DecorationButtonType::Maximize: return DecorationOptions::DecorationButtonMaximizeRestore; case KDecoration2::DecorationButtonType::Close: return DecorationOptions::DecorationButtonClose; case KDecoration2::DecorationButtonType::ContextHelp: return DecorationOptions::DecorationButtonQuickHelp; case KDecoration2::DecorationButtonType::Shade: return DecorationOptions::DecorationButtonShade; case KDecoration2::DecorationButtonType::KeepBelow: return DecorationOptions::DecorationButtonKeepBelow; case KDecoration2::DecorationButtonType::KeepAbove: return DecorationOptions::DecorationButtonKeepAbove; default: return DecorationOptions::DecorationButtonNone; } } QList DecorationOptions::titleButtonsLeft() const { QList ret; if (m_decoration) { for (auto it : m_decoration->settings()->decorationButtonsLeft()) { ret << decorationButton(it); } } return ret; } QList DecorationOptions::titleButtonsRight() const { QList ret; if (m_decoration) { for (auto it : m_decoration->settings()->decorationButtonsRight()) { ret << decorationButton(it); } } return ret; } KDecoration2::Decoration *DecorationOptions::decoration() const { return m_decoration; } void DecorationOptions::setDecoration(KDecoration2::Decoration *decoration) { if (m_decoration == decoration) { return; } if (m_decoration) { // disconnect from existing decoration disconnect(m_decoration->client().data(), &KDecoration2::DecoratedClient::activeChanged, this, &DecorationOptions::slotActiveChanged); auto s = m_decoration->settings(); disconnect(s.data(), &KDecoration2::DecorationSettings::fontChanged, this, &DecorationOptions::fontChanged); disconnect(s.data(), &KDecoration2::DecorationSettings::decorationButtonsLeftChanged, this, &DecorationOptions::titleButtonsChanged); disconnect(s.data(), &KDecoration2::DecorationSettings::decorationButtonsRightChanged, this, &DecorationOptions::titleButtonsChanged); disconnect(m_paletteConnection); } m_decoration = decoration; connect(m_decoration->client().data(), &KDecoration2::DecoratedClient::activeChanged, this, &DecorationOptions::slotActiveChanged); m_paletteConnection = connect(m_decoration->client().data(), &KDecoration2::DecoratedClient::paletteChanged, this, [this] (const QPalette &pal) { m_colors.update(pal); emit colorsChanged(); } ); auto s = m_decoration->settings(); connect(s.data(), &KDecoration2::DecorationSettings::fontChanged, this, &DecorationOptions::fontChanged); connect(s.data(), &KDecoration2::DecorationSettings::decorationButtonsLeftChanged, this, &DecorationOptions::titleButtonsChanged); connect(s.data(), &KDecoration2::DecorationSettings::decorationButtonsRightChanged, this, &DecorationOptions::titleButtonsChanged); emit decorationChanged(); } void DecorationOptions::slotActiveChanged() { if (!m_decoration) { return; } if (m_active == m_decoration->client().data()->isActive()) { return; } m_active = m_decoration->client().data()->isActive(); emit colorsChanged(); emit fontChanged(); } int DecorationOptions::mousePressAndHoldInterval() const { return QGuiApplication::styleHints()->mousePressAndHoldInterval(); } Borders::Borders(QObject *parent) : QObject(parent) , m_left(0) , m_right(0) , m_top(0) , m_bottom(0) { } Borders::~Borders() { } #define SETTER( methodName, name ) \ void Borders::methodName(int name) \ { \ if (m_##name == name) { \ return; \ } \ m_##name = name; \ emit name##Changed(); \ } SETTER(setLeft, left) SETTER(setRight, right) SETTER(setTop, top) SETTER(setBottom, bottom) #undef SETTER void Borders::setAllBorders(int border) { setBorders(border); setTitle(border); } void Borders::setBorders(int border) { setSideBorders(border); setBottom(border); } void Borders::setSideBorders(int border) { setLeft(border); setRight(border); } void Borders::setTitle(int value) { setTop(value); } Borders::operator QMargins() const { return QMargins(m_left, m_top, m_right, m_bottom); } } // namespace