From 6a580d2b903f3663af8bcb4e422cbb6cde605172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 24 Oct 2014 13:05:41 +0200 Subject: [PATCH] Support themes in decoration loading A decoration plugin can indicate that it supports themes. For this the decoration plugin needs to specify in the org.kde.kdecoration2 group of the JSON meta data the following: themes: true, defaultTheme: "nameofDefaultTheme" If the themes key/value pair is present and set to true KWin will read the entry "theme" in the [org.kde.kdecoration2] group with the value of defaultTheme as the default value. The read value (if there is one) is passed to the created decoration in the QVariantList. The QVariantList contains a QVariantMap as first entry and the theme name is passed for key "theme". --- decorations/decorationbridge.cpp | 22 +++++++++++++++++++++- decorations/decorationbridge.h | 2 ++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/decorations/decorationbridge.cpp b/decorations/decorationbridge.cpp index d49fda51a6..359763a76b 100644 --- a/decorations/decorationbridge.cpp +++ b/decorations/decorationbridge.cpp @@ -89,6 +89,7 @@ void DecorationBridge::loadMetaData(const QJsonObject &object) { // reset all settings m_blur = false; + m_theme = QString(); // load the settings const QJsonValue decoSettings = object.value(s_pluginName); @@ -101,6 +102,21 @@ void DecorationBridge::loadMetaData(const QJsonObject &object) if (blurIt != decoSettingsMap.end()) { m_blur = blurIt.value().toBool(); } + findTheme(decoSettingsMap); +} + +void DecorationBridge::findTheme(const QVariantMap &map) +{ + auto it = map.find(QStringLiteral("themes")); + if (it == map.end()) { + return; + } + if (!it.value().toBool()) { + return; + } + it = map.find(QStringLiteral("defaultTheme")); + const KConfigGroup config = KSharedConfig::openConfig(KWIN_CONFIG)->group(s_pluginName); + m_theme = config.readEntry("theme", it != map.end() ? it.value().toString() : QString()); } std::unique_ptr DecorationBridge::createClient(KDecoration2::DecoratedClient *client, KDecoration2::Decoration *decoration) @@ -128,7 +144,11 @@ KDecoration2::Decoration *DecorationBridge::createDecoration(Client *client) if (!m_factory) { return nullptr; } - auto deco = m_factory->create(client); + QVariantList args; + if (!m_theme.isEmpty()) { + args << QVariantMap({ {QStringLiteral("theme"), m_theme} }); + } + auto deco = m_factory->create(client, args); deco->init(); return deco; } diff --git a/decorations/decorationbridge.h b/decorations/decorationbridge.h index 6bfc8f9cee..7126d27fda 100644 --- a/decorations/decorationbridge.h +++ b/decorations/decorationbridge.h @@ -55,8 +55,10 @@ public: static DecorationBridge *self(); private: void loadMetaData(const QJsonObject &object); + void findTheme(const QVariantMap &map); KPluginFactory *m_factory; bool m_blur; + QString m_theme; }; } // Decoration } // KWin