diff --git a/clients/aurorae/src/aurorae.cpp b/clients/aurorae/src/aurorae.cpp index e6865c52fc..124ad830f1 100644 --- a/clients/aurorae/src/aurorae.cpp +++ b/clients/aurorae/src/aurorae.cpp @@ -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); diff --git a/clients/aurorae/src/aurorae.h b/clients/aurorae/src/aurorae.h index c5dc38ce41..ff53281c5b 100644 --- a/clients/aurorae/src/aurorae.h +++ b/clients/aurorae/src/aurorae.h @@ -75,6 +75,7 @@ private: KWin::Borders *m_padding; QString m_themeName; QMutex m_mutex; + QMetaObject::Connection m_recreateNonCompositedConnection; }; class ThemeFinder : public QObject diff --git a/clients/aurorae/src/decorationoptions.cpp b/clients/aurorae/src/decorationoptions.cpp index bdf57d54c7..14d235241d 100644 --- a/clients/aurorae/src/decorationoptions.cpp +++ b/clients/aurorae/src/decorationoptions.cpp @@ -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 DecorationOptions::titleButtonsLeft() const { QList 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 DecorationOptions::titleButtonsLeft() const QList DecorationOptions::titleButtonsRight() const { QList 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(); } diff --git a/decorations/decorationbridge.cpp b/decorations/decorationbridge.cpp index 76d5f8f6b2..639937b751 100644 --- a/decorations/decorationbridge.cpp +++ b/decorations/decorationbridge.cpp @@ -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::create(); initPlugin(); } @@ -196,6 +197,7 @@ KDecoration2::Decoration *DecorationBridge::createDecoration(Client *client) args << QVariantMap({ {QStringLiteral("theme"), m_theme} }); } auto deco = m_factory->create(client, args); + deco->setSettings(m_settings); deco->init(); return deco; } diff --git a/decorations/decorationbridge.h b/decorations/decorationbridge.h index e4a5cfd5b1..31b2d9765a 100644 --- a/decorations/decorationbridge.h +++ b/decorations/decorationbridge.h @@ -23,9 +23,15 @@ along with this program. If not, see . #include #include +#include class KPluginFactory; +namespace KDecoration2 +{ +class DecorationSettings; +} + namespace KWin { @@ -54,6 +60,10 @@ public: void reconfigure(); + const QSharedPointer &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 m_settings; }; } // Decoration } // KWin diff --git a/effects.cpp b/effects.cpp index 88bbf3a2c9..2935754549 100644 --- a/effects.cpp +++ b/effects.cpp @@ -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();