diff --git a/autotests/integration/decoration_input_test.cpp b/autotests/integration/decoration_input_test.cpp index 1d926bc361..5859a276a1 100644 --- a/autotests/integration/decoration_input_test.cpp +++ b/autotests/integration/decoration_input_test.cpp @@ -332,7 +332,7 @@ void DecorationInputTest::testHover() // // TODO: Test input position with different border sizes. // TODO: We should test with the fake decoration to have a fixed test environment. - const bool hasBorders = Decoration::DecorationBridge::self()->settings()->borderSize() != KDecoration2::BorderSize::None; + const bool hasBorders = Workspace::self()->decorationBridge()->settings()->borderSize() != KDecoration2::BorderSize::None; auto deviation = [hasBorders] { return hasBorders ? -1 : 0; }; diff --git a/autotests/integration/maximize_test.cpp b/autotests/integration/maximize_test.cpp index 1cf998d8f0..9becde5359 100644 --- a/autotests/integration/maximize_test.cpp +++ b/autotests/integration/maximize_test.cpp @@ -114,7 +114,7 @@ void TestMaximized::testMaximizedPassedToDeco() // When there are no borders, there is no change to them when maximizing. // TODO: we should test both cases with fixed fake decoration for autotests. - const bool hasBorders = Decoration::DecorationBridge::self()->settings()->borderSize() != KDecoration2::BorderSize::None; + const bool hasBorders = Workspace::self()->decorationBridge()->settings()->borderSize() != KDecoration2::BorderSize::None; // now maximize QSignalSpy bordersChangedSpy(decoration, &KDecoration2::Decoration::bordersChanged); diff --git a/autotests/integration/quick_tiling_test.cpp b/autotests/integration/quick_tiling_test.cpp index a4fa85c10c..74e0185605 100644 --- a/autotests/integration/quick_tiling_test.cpp +++ b/autotests/integration/quick_tiling_test.cpp @@ -531,7 +531,7 @@ void QuickTilingTest::testQuickTilingTouchMove() // When there are no borders, there is no change to them when quick-tiling. // TODO: we should test both cases with fixed fake decoration for autotests. - const bool hasBorders = Decoration::DecorationBridge::self()->settings()->borderSize() != KDecoration2::BorderSize::None; + const bool hasBorders = Workspace::self()->decorationBridge()->settings()->borderSize() != KDecoration2::BorderSize::None; QCOMPARE(quickTileChangedSpy.count(), 1); QTEST(window->quickTileMode(), "expectedMode"); diff --git a/src/appmenu.cpp b/src/appmenu.cpp index 20d10e48cf..4b51c4cd7d 100644 --- a/src/appmenu.cpp +++ b/src/appmenu.cpp @@ -65,7 +65,7 @@ void ApplicationMenu::setViewEnabled(bool enabled) void ApplicationMenu::slotShowRequest(const QString &serviceName, const QDBusObjectPath &menuObjectPath, int actionId) { // Ignore show request when user has not configured the application menu title bar button - auto decorationSettings = Decoration::DecorationBridge::self()->settings(); + auto decorationSettings = Workspace::self()->decorationBridge()->settings(); if (decorationSettings && !decorationSettings->decorationButtonsLeft().contains(KDecoration2::DecorationButtonType::ApplicationMenu) && !decorationSettings->decorationButtonsRight().contains(KDecoration2::DecorationButtonType::ApplicationMenu)) { return; diff --git a/src/decorations/decoratedclient.cpp b/src/decorations/decoratedclient.cpp index fb783be0f2..e1d3682f8a 100644 --- a/src/decorations/decoratedclient.cpp +++ b/src/decorations/decoratedclient.cpp @@ -177,7 +177,7 @@ QColor DecoratedClientImpl::color(KDecoration2::ColorGroup group, KDecoration2:: void DecoratedClientImpl::requestShowToolTip(const QString &text) { - if (!DecorationBridge::self()->showToolTips()) { + if (!workspace()->decorationBridge()->showToolTips()) { return; } diff --git a/src/decorations/decorationbridge.cpp b/src/decorations/decorationbridge.cpp index e603bc13c3..cfe5ccae23 100644 --- a/src/decorations/decorationbridge.cpp +++ b/src/decorations/decorationbridge.cpp @@ -45,11 +45,8 @@ static const QString s_defaultPlugin = QStringLiteral(BREEZE_KDECORATION_PLUGIN_ static const QString s_defaultPlugin = s_aurorae; #endif -KWIN_SINGLETON_FACTORY(DecorationBridge) - -DecorationBridge::DecorationBridge(QObject *parent) - : KDecoration2::DecorationBridge(parent) - , m_factory(nullptr) +DecorationBridge::DecorationBridge() + : m_factory(nullptr) , m_showToolTips(false) , m_settings() , m_noPlugin(false) @@ -57,11 +54,6 @@ DecorationBridge::DecorationBridge(QObject *parent) readDecorationOptions(); } -DecorationBridge::~DecorationBridge() -{ - s_self = nullptr; -} - QString DecorationBridge::readPlugin() { return kwinApp()->config()->group(s_pluginName).readEntry("library", s_defaultPlugin); @@ -84,7 +76,7 @@ void DecorationBridge::readDecorationOptions() bool DecorationBridge::hasPlugin() { - const DecorationBridge *bridge = DecorationBridge::self(); + const DecorationBridge *bridge = workspace()->decorationBridge(); if (!bridge) { return false; } diff --git a/src/decorations/decorationbridge.h b/src/decorations/decorationbridge.h index 0c021e795f..3ab41f6f12 100644 --- a/src/decorations/decorationbridge.h +++ b/src/decorations/decorationbridge.h @@ -35,7 +35,7 @@ class KWIN_EXPORT DecorationBridge : public KDecoration2::DecorationBridge { Q_OBJECT public: - ~DecorationBridge() override; + explicit DecorationBridge(); static bool hasPlugin(); @@ -82,7 +82,6 @@ private: QString m_theme; QSharedPointer m_settings; bool m_noPlugin; - KWIN_SINGLETON(DecorationBridge) }; } // Decoration } // KWin diff --git a/src/decorations/settings.cpp b/src/decorations/settings.cpp index 2cdc87941c..bb11a41c2c 100644 --- a/src/decorations/settings.cpp +++ b/src/decorations/settings.cpp @@ -44,7 +44,7 @@ SettingsImpl::SettingsImpl(KDecoration2::DecorationSettings *parent) disconnect(c); }); connect(Workspace::self(), &Workspace::configChanged, this, &SettingsImpl::readSettings); - connect(DecorationBridge::self(), &DecorationBridge::metaDataLoaded, this, &SettingsImpl::readSettings); + connect(Workspace::self()->decorationBridge(), &DecorationBridge::metaDataLoaded, this, &SettingsImpl::readSettings); } SettingsImpl::~SettingsImpl() = default; @@ -160,7 +160,7 @@ void SettingsImpl::readSettings() auto size = stringToSize(config.readEntry("BorderSize", QStringLiteral("Normal"))); if (m_autoBorderSize) { /* Falls back to Normal border size, if the plugin does not provide a valid recommendation. */ - size = stringToSize(DecorationBridge::self()->recommendedBorderSize()); + size = stringToSize(Workspace::self()->decorationBridge()->recommendedBorderSize()); } if (size != m_borderSize) { m_borderSize = size; diff --git a/src/effects.cpp b/src/effects.cpp index 1eef9d108b..4d2a6ec65e 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -1590,7 +1590,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 - const auto settings = Decoration::DecorationBridge::self()->settings(); + const auto settings = Workspace::self()->decorationBridge()->settings(); return settings && settings->decorationButtonsLeft().contains(KDecoration2::DecorationButtonType::Close) ? Qt::TopLeftCorner : Qt::TopRightCorner; } case SwitchDesktopOnScreenEdge: diff --git a/src/internalwindow.cpp b/src/internalwindow.cpp index d557c06b2c..3b7163de2c 100644 --- a/src/internalwindow.cpp +++ b/src/internalwindow.cpp @@ -324,7 +324,7 @@ void InternalWindow::setNoBorder(bool set) void InternalWindow::createDecoration(const QRectF &oldGeometry) { - setDecoration(std::shared_ptr(Decoration::DecorationBridge::self()->createDecoration(this))); + setDecoration(std::shared_ptr(Workspace::self()->decorationBridge()->createDecoration(this))); moveResize(oldGeometry); Q_EMIT geometryShapeChanged(this, oldGeometry); diff --git a/src/workspace.cpp b/src/workspace.cpp index 16051af61a..b8b49f60f3 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -175,9 +175,9 @@ Workspace::Workspace() X11Compositor::create(this); } - auto decorationBridge = Decoration::DecorationBridge::create(this); - decorationBridge->init(); - connect(this, &Workspace::configChanged, decorationBridge, &Decoration::DecorationBridge::reconfigure); + m_decorationBridge = std::make_unique(); + m_decorationBridge->init(); + connect(this, &Workspace::configChanged, m_decorationBridge.get(), &Decoration::DecorationBridge::reconfigure); new DBusInterface(this); Outline::create(this); @@ -1516,10 +1516,10 @@ QString Workspace::supportInformation() const support.append(QStringLiteral("\n")); } - if (auto bridge = Decoration::DecorationBridge::self()) { + if (m_decorationBridge) { support.append(QStringLiteral("Decoration\n")); support.append(QStringLiteral("==========\n")); - support.append(bridge->supportInformation()); + support.append(m_decorationBridge->supportInformation()); support.append(QStringLiteral("\n")); } support.append(QStringLiteral("Platform\n")); @@ -2831,6 +2831,11 @@ ApplicationMenu *Workspace::applicationMenu() const return m_applicationMenu.get(); } +Decoration::DecorationBridge *Workspace::decorationBridge() const +{ + return m_decorationBridge.get(); +} + #if KWIN_BUILD_ACTIVITIES Activities *Workspace::activities() const { diff --git a/src/workspace.h b/src/workspace.h index 87df26c89e..4963e6a86f 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -34,6 +34,11 @@ class KStartupInfoId; namespace KWin { +namespace Decoration +{ +class DecorationBridge; +} + namespace Xcb { class Tree; @@ -430,6 +435,7 @@ public: } FocusChain *focusChain() const; ApplicationMenu *applicationMenu() const; + Decoration::DecorationBridge *decorationBridge() const; #if KWIN_BUILD_ACTIVITIES Activities *activities() const; #endif @@ -703,6 +709,7 @@ private: SessionManager *m_sessionManager; std::unique_ptr m_focusChain; std::unique_ptr m_applicationMenu; + std::unique_ptr m_decorationBridge; #if KWIN_BUILD_ACTIVITIES std::unique_ptr m_activities; #endif diff --git a/src/x11window.cpp b/src/x11window.cpp index c89c270ee5..d3c30d75b1 100644 --- a/src/x11window.cpp +++ b/src/x11window.cpp @@ -1144,7 +1144,7 @@ void X11Window::invalidateDecoration() void X11Window::createDecoration(const QRectF &oldgeom) { - std::shared_ptr decoration(Decoration::DecorationBridge::self()->createDecoration(this)); + std::shared_ptr decoration(Workspace::self()->decorationBridge()->createDecoration(this)); if (decoration) { connect(decoration.get(), &KDecoration2::Decoration::resizeOnlyBordersChanged, this, &X11Window::updateInputWindow); connect(decoration.get(), &KDecoration2::Decoration::bordersChanged, this, &X11Window::updateFrameExtents); diff --git a/src/xdgshellwindow.cpp b/src/xdgshellwindow.cpp index 3d4a19add7..62f90448ad 100644 --- a/src/xdgshellwindow.cpp +++ b/src/xdgshellwindow.cpp @@ -1513,7 +1513,7 @@ void XdgToplevelWindow::configureDecoration() break; case DecorationMode::Server: if (!m_nextDecoration) { - m_nextDecoration.reset(Decoration::DecorationBridge::self()->createDecoration(this)); + m_nextDecoration.reset(Workspace::self()->decorationBridge()->createDecoration(this)); } break; }