[kdecoration2] Adjust to DecortionSettings no longer being a singleton

This commit is contained in:
Martin Gräßlin 2014-10-29 16:11:20 +01:00
parent 8f87e18b79
commit a7bcb70980
6 changed files with 50 additions and 22 deletions

View file

@ -229,15 +229,6 @@ Decoration::Decoration(QObject *parent, const QVariantList &args)
}
}
Helper::instance().ref();
// recreate scene when compositing gets disabled, TODO: remove with rendercontrol
connect(KDecoration2::DecorationSettings::self(), &KDecoration2::DecorationSettings::alphaChannelSupportedChanged,
this, [this](bool alpha) {
if (!alpha && m_item) {
m_item->deleteLater();
m_decorationWindow.reset();
init();
}
});
}
Decoration::~Decoration()
@ -248,6 +239,19 @@ Decoration::~Decoration()
void Decoration::init()
{
KDecoration2::Decoration::init();
auto s = settings();
// recreate scene when compositing gets disabled, TODO: remove with rendercontrol
if (!m_recreateNonCompositedConnection) {
m_recreateNonCompositedConnection = connect(s.data(), &KDecoration2::DecorationSettings::alphaChannelSupportedChanged,
this, [this](bool alpha) {
if (!alpha && m_item) {
m_item->deleteLater();
m_decorationWindow.reset();
init();
}
});
}
QQmlContext *context = new QQmlContext(Helper::instance().rootContext(), this);
context->setContextProperty(QStringLiteral("decoration"), this);
auto component = Helper::instance().component(m_themeName);
@ -284,7 +288,7 @@ void Decoration::init()
m_view->setFlags(Qt::WindowDoesNotAcceptFocus | Qt::WindowTransparentForInput);
m_view->setColor(Qt::transparent);
connect(m_view.data(), &QQuickWindow::beforeRendering, [this]() {
if (!KDecoration2::DecorationSettings::self()->isAlphaChannelSupported()) {
if (!settings()->isAlphaChannelSupported()) {
// directly render to QQuickWindow
m_fbo.reset();
return;
@ -306,7 +310,7 @@ void Decoration::init()
QMutexLocker locker(&m_mutex);
m_buffer = m_fbo->toImage();
});
connect(KDecoration2::DecorationSettings::self(), &KDecoration2::DecorationSettings::alphaChannelSupportedChanged,
connect(s.data(), &KDecoration2::DecorationSettings::alphaChannelSupportedChanged,
m_view.data(), &QQuickWindow::update);
connect(m_view.data(), &QQuickWindow::afterRendering, this, [this] { update(); }, Qt::QueuedConnection);
m_item->setParentItem(m_view->contentItem());
@ -389,7 +393,7 @@ void Decoration::updateBorders()
void Decoration::paint(QPainter *painter)
{
if (!KDecoration2::DecorationSettings::self()->isAlphaChannelSupported()) {
if (!settings()->isAlphaChannelSupported()) {
return;
}
QMutexLocker locker(&m_mutex);

View file

@ -75,6 +75,7 @@ private:
KWin::Borders *m_padding;
QString m_themeName;
QMutex m_mutex;
QMetaObject::Connection m_recreateNonCompositedConnection;
};
class ThemeFinder : public QObject

View file

@ -61,9 +61,7 @@ DecorationOptions::DecorationOptions(QObject *parent)
connect(this, &DecorationOptions::decorationChanged, this, &DecorationOptions::slotActiveChanged);
connect(this, &DecorationOptions::decorationChanged, this, &DecorationOptions::colorsChanged);
connect(this, &DecorationOptions::decorationChanged, this, &DecorationOptions::fontChanged);
connect(KDecoration2::DecorationSettings::self(), &KDecoration2::DecorationSettings::fontChanged, this, &DecorationOptions::fontChanged);
connect(KDecoration2::DecorationSettings::self(), &KDecoration2::DecorationSettings::decorationButtonsLeftChanged, this, &DecorationOptions::titleButtonsChanged);
connect(KDecoration2::DecorationSettings::self(), &KDecoration2::DecorationSettings::decorationButtonsRightChanged, this, &DecorationOptions::titleButtonsChanged);
connect(this, &DecorationOptions::decorationChanged, this, &DecorationOptions::titleButtonsChanged);
}
DecorationOptions::~DecorationOptions()
@ -102,7 +100,7 @@ QColor DecorationOptions::titleBarColor() const
QFont DecorationOptions::titleFont() const
{
return KDecoration2::DecorationSettings::self()->font();
return m_decoration ? m_decoration->settings()->font() : QFont();
}
static int decorationButton(KDecoration2::DecorationButtonType type)
@ -136,8 +134,10 @@ static int decorationButton(KDecoration2::DecorationButtonType type)
QList<int> DecorationOptions::titleButtonsLeft() const
{
QList<int> ret;
for (auto it : KDecoration2::DecorationSettings::self()->decorationButtonsLeft()) {
ret << decorationButton(it);
if (m_decoration) {
for (auto it : m_decoration->settings()->decorationButtonsLeft()) {
ret << decorationButton(it);
}
}
return ret;
}
@ -145,8 +145,10 @@ QList<int> DecorationOptions::titleButtonsLeft() const
QList<int> DecorationOptions::titleButtonsRight() const
{
QList<int> ret;
for (auto it : KDecoration2::DecorationSettings::self()->decorationButtonsRight()) {
ret << decorationButton(it);
if (m_decoration) {
for (auto it : m_decoration->settings()->decorationButtonsRight()) {
ret << decorationButton(it);
}
}
return ret;
}
@ -164,9 +166,17 @@ void DecorationOptions::setDecoration(KDecoration2::Decoration *decoration)
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);
}
m_decoration = decoration;
connect(m_decoration->client().data(), &KDecoration2::DecoratedClient::activeChanged, this, &DecorationOptions::slotActiveChanged);
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();
}

View file

@ -52,6 +52,7 @@ DecorationBridge::DecorationBridge(QObject *parent)
, KDecoration2::DecorationBridge()
, m_factory(nullptr)
, m_blur(false)
, m_settings()
{
}
@ -75,7 +76,7 @@ QString DecorationBridge::readTheme() const
void DecorationBridge::init()
{
m_plugin = readPlugin();
KDecoration2::DecorationSettings::self(this);
m_settings = QSharedPointer<KDecoration2::DecorationSettings>::create();
initPlugin();
}
@ -196,6 +197,7 @@ KDecoration2::Decoration *DecorationBridge::createDecoration(Client *client)
args << QVariantMap({ {QStringLiteral("theme"), m_theme} });
}
auto deco = m_factory->create<KDecoration2::Decoration>(client, args);
deco->setSettings(m_settings);
deco->init();
return deco;
}

View file

@ -23,9 +23,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KDecoration2/Private/DecorationBridge>
#include <QObject>
#include <QSharedPointer>
class KPluginFactory;
namespace KDecoration2
{
class DecorationSettings;
}
namespace KWin
{
@ -54,6 +60,10 @@ public:
void reconfigure();
const QSharedPointer<KDecoration2::DecorationSettings> &settings() const {
return m_settings;
}
static DecorationBridge *self();
private:
void loadMetaData(const QJsonObject &object);
@ -65,6 +75,7 @@ private:
QString m_plugin;
QString m_defaultTheme;
QString m_theme;
QSharedPointer<KDecoration2::DecorationSettings> m_settings;
};
} // Decoration
} // KWin

View file

@ -1444,7 +1444,7 @@ QVariant EffectsHandlerImpl::kwinOption(KWinOption kwopt)
switch (kwopt) {
case CloseButtonCorner:
// TODO: this could become per window and be derived from the actual position in the deco
return KDecoration2::DecorationSettings::self()->decorationButtonsLeft().contains(KDecoration2::DecorationButtonType::Close) ? Qt::TopLeftCorner : Qt::TopRightCorner;
return Decoration::DecorationBridge::self()->settings()->decorationButtonsLeft().contains(KDecoration2::DecorationButtonType::Close) ? Qt::TopLeftCorner : Qt::TopRightCorner;
#ifdef KWIN_BUILD_SCREENEDGES
case SwitchDesktopOnScreenEdge:
return ScreenEdges::self()->isDesktopSwitching();