Adapt to KDecoration API changes

Adapt to API changes introduced by b62e8888cd39301e00ad98dfe791fa66676408fb.
It adds DecoratedClient::color(group, role) for getting colors that are
not included in QPalette. Breeze used to read these colors from
kdeglobals, breaking per window color schemes. KWin now handles reading
these colors along with QPalette loading with DecorationPalette.

REVIEW: 122883
This commit is contained in:
Mika Allan Rauhala 2015-03-31 15:26:42 +02:00 committed by Martin Gräßlin
parent 66e92347a8
commit 3389c7569f
11 changed files with 289 additions and 33 deletions

View file

@ -378,6 +378,7 @@ set(kwin_KDEINIT_SRCS
scripting/screenedgeitem.cpp
decorations/decoratedclient.cpp
decorations/decorationbridge.cpp
decorations/decorationpalette.cpp
decorations/settings.cpp
decorations/decorationrenderer.cpp
)

View file

@ -79,6 +79,9 @@ const long ClientWinMask = XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE
XCB_EVENT_MASK_STRUCTURE_NOTIFY |
XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT;
QHash<QString, std::weak_ptr<Decoration::DecorationPalette>> Client::s_palettes;
std::shared_ptr<Decoration::DecorationPalette> Client::s_defaultPalette;
// Creating a client:
// - only by calling Workspace::createClient()
// - it creates a new client and calls manage() for it
@ -138,7 +141,7 @@ Client::Client()
, needsXWindowMove(false)
, m_decoInputExtent()
, m_focusOutTimer(nullptr)
, m_palette(QApplication::palette())
, m_colorScheme(QStringLiteral("kdeglobals"))
, m_clientSideDecorated(false)
{
// TODO: Do all as initialization
@ -2257,15 +2260,43 @@ void Client::readColorScheme(Xcb::StringProperty &property)
{
QString path = QString::fromUtf8(property);
path = rules()->checkDecoColor(path);
QPalette p = m_palette;
if (!path.isEmpty()) {
p = KColorScheme::createApplicationPalette(KSharedConfig::openConfig(path));
} else {
p = QApplication::palette();
if (path.isEmpty()) {
path = QStringLiteral("kdeglobals");
}
if (p != m_palette) {
m_palette = p;
emit paletteChanged(m_palette);
if (!m_palette || m_colorScheme != path) {
m_colorScheme = path;
if (m_palette) {
disconnect(m_palette.get(), &Decoration::DecorationPalette::changed, this, &Client::handlePaletteChange);
}
auto it = s_palettes.find(m_colorScheme);
if (it == s_palettes.end() || it->expired()) {
m_palette = std::make_shared<Decoration::DecorationPalette>(m_colorScheme);
if (m_palette->isValid()) {
s_palettes[m_colorScheme] = m_palette;
} else {
if (!s_defaultPalette) {
s_defaultPalette = std::make_shared<Decoration::DecorationPalette>(QStringLiteral("kdeglobals"));
s_palettes[QStringLiteral("kdeglobals")] = s_defaultPalette;
}
m_palette = s_defaultPalette;
}
if (m_colorScheme == QStringLiteral("kdeglobals")) {
s_defaultPalette = m_palette;
}
} else {
m_palette = it->lock();
}
connect(m_palette.get(), &Decoration::DecorationPalette::changed, this, &Client::handlePaletteChange);
emit paletteChanged(palette());
triggerDecorationRepaint();
}
}
@ -2276,6 +2307,12 @@ void Client::updateColorScheme()
readColorScheme(property);
}
void Client::handlePaletteChange()
{
emit paletteChanged(palette());
triggerDecorationRepaint();
}
bool Client::isClient() const
{
return true;

View file

@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "tabgroup.h"
#include "toplevel.h"
#include "xcbutils.h"
#include "decorations/decorationpalette.h"
// Qt
#include <QElapsedTimer>
#include <QFlags>
@ -671,6 +672,7 @@ public:
void cancelFocusOutTimer();
QPalette palette() const;
const Decoration::DecorationPalette *decorationPalette() const;
/**
* Restores the Client after it had been hidden due to show on screen edge functionality.
@ -881,6 +883,8 @@ private:
**/
void updateShowOnScreenEdge();
void handlePaletteChange();
Xcb::Window m_client;
Xcb::Window m_wrapper;
Xcb::Window m_frame;
@ -1025,7 +1029,11 @@ private:
QTimer *m_focusOutTimer;
QPalette m_palette;
QString m_colorScheme;
std::shared_ptr<Decoration::DecorationPalette> m_palette;
static QHash<QString, std::weak_ptr<Decoration::DecorationPalette>> s_palettes;
static std::shared_ptr<Decoration::DecorationPalette> s_defaultPalette;
QList<QMetaObject::Connection> m_connections;
bool m_clientSideDecorated;
};
@ -1278,7 +1286,12 @@ inline bool Client::hiddenPreview() const
inline QPalette Client::palette() const
{
return m_palette;
return m_palette->palette();
}
inline const Decoration::DecorationPalette *Client::decorationPalette() const
{
return m_palette.get();
}
template <typename T>

View file

@ -166,6 +166,16 @@ DELEGATE(requestClose, closeWindow)
#undef DELEGATE
QColor DecoratedClientImpl::color(KDecoration2::ColorGroup group, KDecoration2::ColorRole role) const
{
auto dp = m_client->decorationPalette();
if (dp) {
return dp->color(group, role);
}
return QColor();
}
void DecoratedClientImpl::requestShowWindowMenu()
{
// TODO: add rect to requestShowWindowMenu

View file

@ -61,6 +61,7 @@ public:
bool isShadeable() const override;
bool isShaded() const override;
QPalette palette() const override;
QColor color(KDecoration2::ColorGroup group, KDecoration2::ColorRole role) const override;
bool providesContextHelp() const override;
int width() const override;
WId windowId() const override;

View file

@ -0,0 +1,129 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
Copyright 2014 Hugo Pereira Da Costa <hugo.pereira@free.fr>
Copyright 2015 Mika Allan Rauhala <mika.allan.rauhala@gmail.com>
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 <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "decorationpalette.h"
#include <KConfigGroup>
#include <KSharedConfig>
#include <KColorScheme>
#include <QPalette>
#include <QFileInfo>
#include <QStandardPaths>
#include <QDebug>
namespace KWin
{
namespace Decoration
{
DecorationPalette::DecorationPalette(const QString &colorScheme)
: m_colorScheme(QFileInfo(colorScheme).isAbsolute()
? 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()) {
qWarning() << "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::Background));
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());
KConfigGroup windowColorsConfig(config, QStringLiteral("Colors:Window"));
m_warningForegroundColor = windowColorsConfig.readEntry("ForegroundNegative", QColor(237, 21, 2));
}
}
}

View file

@ -0,0 +1,70 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
Copyright 2014 Hugo Pereira Da Costa <hugo.pereira@free.fr>
Copyright 2015 Mika Allan Rauhala <mika.allan.rauhala@gmail.com>
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 <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_DECORATION_PALETTE_H
#define KWIN_DECORATION_PALETTE_H
#include <KDecoration2/DecorationSettings>
#include <QFileSystemWatcher>
#include <QPalette>
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;
QColor m_activeFrameColor;
QColor m_inactiveFrameColor;
QColor m_activeForegroundColor;
QColor m_inactiveForegroundColor;
QColor m_warningForegroundColor;
};
}
}
#endif

View file

@ -6,6 +6,7 @@ set(plugin_SRCS
previewsettings.cpp
plugin.cpp
buttonsmodel.cpp
../../../decorations/decorationpalette.cpp
)
add_library(kdecorationprivatedeclarative SHARED ${plugin_SRCS})

View file

@ -41,6 +41,7 @@ PreviewClient::PreviewClient(DecoratedClient *c, Decoration *decoration)
, m_colorSchemeIndex(0)
, m_icon(QIcon::fromTheme(QStringLiteral("start-here-kde")))
, m_iconName(m_icon.name())
, m_palette(QStringLiteral("kdeglobals"))
, m_active(true)
, m_closeable(true)
, m_keepBelow(false)
@ -107,14 +108,9 @@ PreviewClient::PreviewClient(DecoratedClient *c, Decoration *decoration)
emit onAllDesktopsChanged(isOnAllDesktops());
}
);
connect(this, &PreviewClient::colorSchemeIndexChanged, this,
[this]() {
const QModelIndex index = m_colorSchemeManager->model()->index(m_colorSchemeIndex, 0);
qDebug() << "Scheme: " << index.data(Qt::UserRole).toString();
m_palette = KColorScheme::createApplicationPalette(KSharedConfig::openConfig(index.data(Qt::UserRole).toString()));
emit paletteChanged(m_palette);
}
);
connect(&m_palette, &KWin::Decoration::DecorationPalette::changed, [this]() {
emit paletteChanged(m_palette.palette());
});
auto emitEdgesChanged = [this, c]() {
c->adjacentScreenEdgesChanged(adjacentScreenEdges());
};
@ -268,7 +264,12 @@ WId PreviewClient::windowId() const
QPalette PreviewClient::palette() const
{
return m_palette;
return m_palette.palette();
}
QColor PreviewClient::color(ColorGroup group, ColorRole role) const
{
return m_palette.color(group, role);
}
QAbstractItemModel *PreviewClient::colorSchemeModel() const
@ -453,14 +454,5 @@ SETTER2(setProvidesContextHelp, providesContextHelp)
#undef SETTER2
#undef SETTER
bool PreviewClient::eventFilter(QObject *watched, QEvent *e)
{
if (e->type() == QEvent::ApplicationPaletteChange) {
m_palette = QPalette();
emit paletteChanged(m_palette);
}
return false;
}
} // namespace Preview
} // namespace KDecoration2

View file

@ -20,6 +20,8 @@
#ifndef KDECOARTIONS_PREVIEW_CLIENT_H
#define KDECOARTIONS_PREVIEW_CLIENT_H
#include "../../../decorations/decorationpalette.h"
#include <KDecoration2/Private/DecoratedClientPrivate>
#include <QObject>
#include <QPalette>
@ -92,6 +94,7 @@ public:
int width() const override;
int height() const override;
QPalette palette() const override;
QColor color(ColorGroup group, ColorRole role) const override;
Qt::Edges adjacentScreenEdges() const override;
void requestClose() override;
@ -142,8 +145,6 @@ public:
void setBordersRightEdge(bool enabled);
void setBordersBottomEdge(bool enabled);
bool eventFilter(QObject *watched, QEvent *e) override;
Q_SIGNALS:
void captionChanged(const QString &);
void iconChanged(const QIcon &);
@ -184,7 +185,7 @@ private:
QString m_caption;
QIcon m_icon;
QString m_iconName;
QPalette m_palette;
KWin::Decoration::DecorationPalette m_palette;
bool m_active;
bool m_closeable;
bool m_keepBelow;

View file

@ -377,6 +377,8 @@ bool Client::manage(xcb_window_t w, bool isMapped)
}
}
readColorScheme(colorSchemeCookie);
updateDecoration(false); // Also gravitates
// TODO: Is CentralGravity right here, when resizing is done after gravitating?
plainResize(rules()->checkSize(sizeForClientSize(geom.size()), !isMapped));
@ -641,7 +643,6 @@ bool Client::manage(xcb_window_t w, bool isMapped)
updateWindowRules(Rules::All); // Was blocked while !isManaged()
setBlockingCompositing(info->isBlockingCompositing());
readColorScheme(colorSchemeCookie);
readShowOnScreenEdge(showOnScreenEdgeCookie);
// TODO: there's a small problem here - isManaged() depends on the mapping state,