2014-07-22 11:11:19 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
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 "decorationbridge.h"
|
|
|
|
#include "decoratedclient.h"
|
|
|
|
#include "decorationrenderer.h"
|
2015-07-31 11:12:43 +00:00
|
|
|
#include "decorations_logging.h"
|
2014-07-22 11:11:19 +00:00
|
|
|
#include "settings.h"
|
|
|
|
// KWin core
|
2015-12-17 14:50:57 +00:00
|
|
|
#include "abstract_client.h"
|
2014-07-22 11:11:19 +00:00
|
|
|
#include "composite.h"
|
|
|
|
#include "scene.h"
|
2015-12-17 10:14:54 +00:00
|
|
|
#include "wayland_server.h"
|
2014-10-21 06:03:23 +00:00
|
|
|
#include "workspace.h"
|
2016-04-07 12:25:42 +00:00
|
|
|
#include <config-kwin.h>
|
2014-07-22 11:11:19 +00:00
|
|
|
|
|
|
|
// KDecoration
|
|
|
|
#include <KDecoration2/Decoration>
|
|
|
|
#include <KDecoration2/DecoratedClient>
|
|
|
|
#include <KDecoration2/DecorationSettings>
|
|
|
|
|
2015-12-17 10:14:54 +00:00
|
|
|
// KWayland
|
|
|
|
#include <KWayland/Server/server_decoration_interface.h>
|
|
|
|
|
2014-07-22 11:11:19 +00:00
|
|
|
// Frameworks
|
2015-07-07 06:06:34 +00:00
|
|
|
#include <KPluginMetaData>
|
2014-07-22 11:11:19 +00:00
|
|
|
#include <KPluginLoader>
|
|
|
|
|
|
|
|
// Qt
|
2014-12-08 15:14:05 +00:00
|
|
|
#include <QMetaProperty>
|
2014-07-22 11:11:19 +00:00
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
namespace Decoration
|
|
|
|
{
|
|
|
|
|
2016-04-07 12:25:42 +00:00
|
|
|
static const QString s_aurorae = QStringLiteral("org.kde.kwin.aurorae");
|
2014-07-22 11:11:19 +00:00
|
|
|
static const QString s_pluginName = QStringLiteral("org.kde.kdecoration2");
|
2016-04-07 12:25:42 +00:00
|
|
|
#if HAVE_BREEZE_DECO
|
|
|
|
static const QString s_defaultPlugin = QStringLiteral(BREEZE_KDECORATION_PLUGIN_ID);
|
|
|
|
#else
|
|
|
|
static const QString s_defaultPlugin = s_aurorae;
|
|
|
|
#endif
|
2014-07-22 11:11:19 +00:00
|
|
|
|
2014-10-30 08:01:06 +00:00
|
|
|
KWIN_SINGLETON_FACTORY(DecorationBridge)
|
|
|
|
|
2014-07-22 11:11:19 +00:00
|
|
|
DecorationBridge::DecorationBridge(QObject *parent)
|
2014-10-30 08:01:06 +00:00
|
|
|
: KDecoration2::DecorationBridge(parent)
|
2014-07-22 11:11:19 +00:00
|
|
|
, m_factory(nullptr)
|
2014-07-22 12:47:08 +00:00
|
|
|
, m_blur(false)
|
2019-02-19 10:18:28 +00:00
|
|
|
, m_showToolTips(false)
|
2014-10-29 15:11:20 +00:00
|
|
|
, m_settings()
|
2015-08-12 08:29:03 +00:00
|
|
|
, m_noPlugin(false)
|
2014-07-22 11:11:19 +00:00
|
|
|
{
|
2019-01-15 14:07:11 +00:00
|
|
|
KConfigGroup cg(KSharedConfig::openConfig(), "KDE");
|
|
|
|
|
|
|
|
// try to extract the proper defaults file from a lookandfeel package
|
|
|
|
const QString looknfeel = cg.readEntry(QStringLiteral("LookAndFeelPackage"), "org.kde.breeze.desktop");
|
|
|
|
m_lnfConfig = KSharedConfig::openConfig(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("plasma/look-and-feel/") + looknfeel + QStringLiteral("/contents/defaults")));
|
2019-02-19 10:18:28 +00:00
|
|
|
|
|
|
|
readDecorationOptions();
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
|
2014-10-30 08:01:06 +00:00
|
|
|
DecorationBridge::~DecorationBridge()
|
2014-07-22 11:11:19 +00:00
|
|
|
{
|
2014-10-30 08:01:06 +00:00
|
|
|
s_self = nullptr;
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 14:07:11 +00:00
|
|
|
QString DecorationBridge::readPlugin()
|
2014-10-28 10:22:22 +00:00
|
|
|
{
|
2019-01-15 14:07:11 +00:00
|
|
|
//Try to get a default from look and feel
|
|
|
|
KConfigGroup cg(m_lnfConfig, "kwinrc");
|
|
|
|
cg = KConfigGroup(&cg, "org.kde.kdecoration2");
|
|
|
|
return kwinApp()->config()->group(s_pluginName).readEntry("library", cg.readEntry("library", s_defaultPlugin));
|
2014-10-28 10:22:22 +00:00
|
|
|
}
|
|
|
|
|
2015-08-12 08:29:03 +00:00
|
|
|
static bool readNoPlugin()
|
|
|
|
{
|
2016-01-29 10:24:18 +00:00
|
|
|
return kwinApp()->config()->group(s_pluginName).readEntry("NoPlugin", false);
|
2015-08-12 08:29:03 +00:00
|
|
|
}
|
|
|
|
|
2014-10-28 10:22:22 +00:00
|
|
|
QString DecorationBridge::readTheme() const
|
|
|
|
{
|
2019-01-15 14:07:11 +00:00
|
|
|
//Try to get a default from look and feel
|
|
|
|
KConfigGroup cg(m_lnfConfig, "kwinrc");
|
|
|
|
cg = KConfigGroup(&cg, "org.kde.kdecoration2");
|
|
|
|
return kwinApp()->config()->group(s_pluginName).readEntry("theme", cg.readEntry("theme", m_defaultTheme));
|
2014-10-28 10:22:22 +00:00
|
|
|
}
|
|
|
|
|
2019-02-19 10:18:28 +00:00
|
|
|
void DecorationBridge::readDecorationOptions()
|
|
|
|
{
|
|
|
|
m_showToolTips = kwinApp()->config()->group(s_pluginName).readEntry("ShowToolTips", true);
|
|
|
|
}
|
|
|
|
|
2014-07-22 11:11:19 +00:00
|
|
|
void DecorationBridge::init()
|
|
|
|
{
|
2015-12-17 10:14:54 +00:00
|
|
|
using namespace KWayland::Server;
|
2015-08-12 08:29:03 +00:00
|
|
|
m_noPlugin = readNoPlugin();
|
|
|
|
if (m_noPlugin) {
|
2015-12-17 10:14:54 +00:00
|
|
|
if (waylandServer()) {
|
|
|
|
waylandServer()->decorationManager()->setDefaultMode(ServerSideDecorationManagerInterface::Mode::None);
|
|
|
|
}
|
2015-08-12 08:29:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-10-28 10:22:22 +00:00
|
|
|
m_plugin = readPlugin();
|
2014-10-29 15:51:31 +00:00
|
|
|
m_settings = QSharedPointer<KDecoration2::DecorationSettings>::create(this);
|
2014-10-28 10:22:22 +00:00
|
|
|
initPlugin();
|
2015-01-05 13:30:42 +00:00
|
|
|
if (!m_factory) {
|
|
|
|
if (m_plugin != s_defaultPlugin) {
|
|
|
|
// try loading default plugin
|
|
|
|
m_plugin = s_defaultPlugin;
|
|
|
|
initPlugin();
|
|
|
|
}
|
|
|
|
// default plugin failed to load, try fallback
|
|
|
|
if (!m_factory) {
|
2016-04-07 12:25:42 +00:00
|
|
|
m_plugin = s_aurorae;
|
2015-01-05 13:30:42 +00:00
|
|
|
initPlugin();
|
|
|
|
}
|
|
|
|
}
|
2015-12-17 10:14:54 +00:00
|
|
|
if (waylandServer()) {
|
|
|
|
waylandServer()->decorationManager()->setDefaultMode(m_factory ? ServerSideDecorationManagerInterface::Mode::Server : ServerSideDecorationManagerInterface::Mode::None);
|
|
|
|
}
|
2014-10-28 10:22:22 +00:00
|
|
|
}
|
2014-07-22 11:11:19 +00:00
|
|
|
|
2014-10-28 10:22:22 +00:00
|
|
|
void DecorationBridge::initPlugin()
|
|
|
|
{
|
2015-07-07 06:06:34 +00:00
|
|
|
const auto offers = KPluginLoader::findPluginsById(s_pluginName, m_plugin);
|
2014-07-22 11:11:19 +00:00
|
|
|
if (offers.isEmpty()) {
|
2015-07-31 11:12:43 +00:00
|
|
|
qCWarning(KWIN_DECORATIONS) << "Could not locate decoration plugin";
|
2014-07-22 11:11:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-07-31 11:12:43 +00:00
|
|
|
qCDebug(KWIN_DECORATIONS) << "Trying to load decoration plugin: " << offers.first().fileName();
|
2015-07-07 06:06:34 +00:00
|
|
|
KPluginLoader loader(offers.first().fileName());
|
2014-07-22 11:11:19 +00:00
|
|
|
KPluginFactory *factory = loader.factory();
|
|
|
|
if (!factory) {
|
2015-07-31 11:12:43 +00:00
|
|
|
qCWarning(KWIN_DECORATIONS) << "Error loading plugin:" << loader.errorString();
|
2014-07-22 11:11:19 +00:00
|
|
|
} else {
|
|
|
|
m_factory = factory;
|
2014-07-22 12:47:08 +00:00
|
|
|
loadMetaData(loader.metaData().value(QStringLiteral("MetaData")).toObject());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-28 10:22:22 +00:00
|
|
|
static void recreateDecorations()
|
|
|
|
{
|
2015-12-17 14:49:48 +00:00
|
|
|
Workspace::self()->forEachAbstractClient([](AbstractClient *c) { c->updateDecoration(true, true); });
|
2014-10-28 10:22:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DecorationBridge::reconfigure()
|
|
|
|
{
|
2019-02-19 10:18:28 +00:00
|
|
|
readDecorationOptions();
|
|
|
|
|
2015-08-12 08:29:03 +00:00
|
|
|
if (m_noPlugin != readNoPlugin()) {
|
|
|
|
m_noPlugin = !m_noPlugin;
|
|
|
|
// no plugin setting changed
|
|
|
|
if (m_noPlugin) {
|
|
|
|
// decorations disabled now
|
|
|
|
m_plugin = QString();
|
|
|
|
delete m_factory;
|
|
|
|
m_factory = nullptr;
|
|
|
|
m_settings.clear();
|
|
|
|
} else {
|
|
|
|
// decorations enabled now
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
recreateDecorations();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-28 10:22:22 +00:00
|
|
|
const QString newPlugin = readPlugin();
|
|
|
|
if (newPlugin != m_plugin) {
|
|
|
|
// plugin changed, recreate everything
|
|
|
|
auto oldFactory = m_factory;
|
|
|
|
const auto oldPluginName = m_plugin;
|
|
|
|
m_plugin = newPlugin;
|
|
|
|
initPlugin();
|
|
|
|
if (m_factory == oldFactory) {
|
|
|
|
// loading new plugin failed
|
|
|
|
m_factory = oldFactory;
|
|
|
|
m_plugin = oldPluginName;
|
|
|
|
} else {
|
|
|
|
recreateDecorations();
|
|
|
|
// TODO: unload and destroy old plugin
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// same plugin, but theme might have changed
|
|
|
|
const QString oldTheme = m_theme;
|
|
|
|
m_theme = readTheme();
|
|
|
|
if (m_theme != oldTheme) {
|
|
|
|
recreateDecorations();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-22 12:47:08 +00:00
|
|
|
void DecorationBridge::loadMetaData(const QJsonObject &object)
|
|
|
|
{
|
|
|
|
// reset all settings
|
|
|
|
m_blur = false;
|
2014-10-24 11:05:41 +00:00
|
|
|
m_theme = QString();
|
2014-10-28 10:22:22 +00:00
|
|
|
m_defaultTheme = QString();
|
2014-07-22 12:47:08 +00:00
|
|
|
|
|
|
|
// load the settings
|
|
|
|
const QJsonValue decoSettings = object.value(s_pluginName);
|
|
|
|
if (decoSettings.isUndefined()) {
|
|
|
|
// no settings
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const QVariantMap decoSettingsMap = decoSettings.toObject().toVariantMap();
|
|
|
|
auto blurIt = decoSettingsMap.find(QStringLiteral("blur"));
|
|
|
|
if (blurIt != decoSettingsMap.end()) {
|
|
|
|
m_blur = blurIt.value().toBool();
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
2014-10-24 11:05:41 +00:00
|
|
|
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"));
|
2014-10-28 10:22:22 +00:00
|
|
|
m_defaultTheme = it != map.end() ? it.value().toString() : QString();
|
|
|
|
m_theme = readTheme();
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
|
2014-10-20 15:42:50 +00:00
|
|
|
std::unique_ptr<KDecoration2::DecoratedClientPrivate> DecorationBridge::createClient(KDecoration2::DecoratedClient *client, KDecoration2::Decoration *decoration)
|
2014-07-22 11:11:19 +00:00
|
|
|
{
|
2015-12-04 08:29:22 +00:00
|
|
|
return std::unique_ptr<DecoratedClientImpl>(new DecoratedClientImpl(static_cast<AbstractClient*>(decoration->parent()), client, decoration));
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
|
2014-10-20 15:42:50 +00:00
|
|
|
std::unique_ptr<KDecoration2::DecorationSettingsPrivate> DecorationBridge::settings(KDecoration2::DecorationSettings *parent)
|
2014-07-22 11:11:19 +00:00
|
|
|
{
|
2014-10-20 15:42:50 +00:00
|
|
|
return std::unique_ptr<SettingsImpl>(new SettingsImpl(parent));
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DecorationBridge::update(KDecoration2::Decoration *decoration, const QRect &geometry)
|
|
|
|
{
|
|
|
|
// TODO: remove check once all compositors implement it
|
2015-12-04 08:54:10 +00:00
|
|
|
if (AbstractClient *c = Workspace::self()->findAbstractClient([decoration] (const AbstractClient *client) { return client->decoration() == decoration; })) {
|
2014-10-21 06:03:23 +00:00
|
|
|
if (Renderer *renderer = c->decoratedClient()->renderer()) {
|
|
|
|
renderer->schedule(geometry);
|
|
|
|
}
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-04 08:29:22 +00:00
|
|
|
KDecoration2::Decoration *DecorationBridge::createDecoration(AbstractClient *client)
|
2014-07-22 11:11:19 +00:00
|
|
|
{
|
2015-08-12 08:29:03 +00:00
|
|
|
if (m_noPlugin) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-07-22 11:11:19 +00:00
|
|
|
if (!m_factory) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-10-30 08:01:06 +00:00
|
|
|
QVariantMap args({ {QStringLiteral("bridge"), QVariant::fromValue(this)} });
|
|
|
|
|
2014-10-24 11:05:41 +00:00
|
|
|
if (!m_theme.isEmpty()) {
|
2014-10-30 08:01:06 +00:00
|
|
|
args.insert(QStringLiteral("theme"), m_theme);
|
2014-10-24 11:05:41 +00:00
|
|
|
}
|
2014-10-30 08:01:06 +00:00
|
|
|
auto deco = m_factory->create<KDecoration2::Decoration>(client, QVariantList({args}));
|
2014-10-29 15:11:20 +00:00
|
|
|
deco->setSettings(m_settings);
|
2014-10-23 08:59:00 +00:00
|
|
|
deco->init();
|
|
|
|
return deco;
|
2014-07-22 11:11:19 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 15:14:05 +00:00
|
|
|
static
|
|
|
|
QString settingsProperty(const QVariant &variant)
|
|
|
|
{
|
|
|
|
if (QLatin1String(variant.typeName()) == QLatin1String("KDecoration2::BorderSize")) {
|
|
|
|
return QString::number(variant.toInt());
|
|
|
|
} else if (QLatin1String(variant.typeName()) == QLatin1String("QVector<KDecoration2::DecorationButtonType>")) {
|
|
|
|
const auto &b = variant.value<QVector<KDecoration2::DecorationButtonType>>();
|
|
|
|
QString buffer;
|
|
|
|
for (auto it = b.begin(); it != b.end(); ++it) {
|
|
|
|
if (it != b.begin()) {
|
|
|
|
buffer.append(QStringLiteral(", "));
|
|
|
|
}
|
|
|
|
buffer.append(QString::number(int(*it)));
|
|
|
|
}
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
return variant.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DecorationBridge::supportInformation() const
|
|
|
|
{
|
|
|
|
QString b;
|
|
|
|
b.append(QStringLiteral("Plugin: %1\n").arg(m_plugin));
|
|
|
|
b.append(QStringLiteral("Theme: %1\n").arg(m_theme));
|
|
|
|
b.append(QStringLiteral("Blur: %1\n").arg(m_blur));
|
|
|
|
const QMetaObject *metaOptions = m_settings->metaObject();
|
|
|
|
for (int i=0; i<metaOptions->propertyCount(); ++i) {
|
|
|
|
const QMetaProperty property = metaOptions->property(i);
|
|
|
|
if (QLatin1String(property.name()) == QLatin1String("objectName")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
b.append(QStringLiteral("%1: %2\n").arg(property.name()).arg(settingsProperty(m_settings->property(property.name()))));
|
|
|
|
}
|
|
|
|
return b;
|
|
|
|
}
|
2014-07-22 11:11:19 +00:00
|
|
|
|
|
|
|
} // Decoration
|
|
|
|
} // KWin
|