move DecorationBridge singleton into Workspace

This commit is contained in:
Xaver Hugl 2022-07-20 13:46:41 +02:00
parent 7f1923cc9b
commit b6cf576efa
14 changed files with 32 additions and 29 deletions

View file

@ -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;
};

View file

@ -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);

View file

@ -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");

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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<KDecoration2::DecorationSettings> m_settings;
bool m_noPlugin;
KWIN_SINGLETON(DecorationBridge)
};
} // Decoration
} // KWin

View file

@ -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;

View file

@ -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:

View file

@ -324,7 +324,7 @@ void InternalWindow::setNoBorder(bool set)
void InternalWindow::createDecoration(const QRectF &oldGeometry)
{
setDecoration(std::shared_ptr<KDecoration2::Decoration>(Decoration::DecorationBridge::self()->createDecoration(this)));
setDecoration(std::shared_ptr<KDecoration2::Decoration>(Workspace::self()->decorationBridge()->createDecoration(this)));
moveResize(oldGeometry);
Q_EMIT geometryShapeChanged(this, oldGeometry);

View file

@ -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<Decoration::DecorationBridge>();
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
{

View file

@ -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<FocusChain> m_focusChain;
std::unique_ptr<ApplicationMenu> m_applicationMenu;
std::unique_ptr<Decoration::DecorationBridge> m_decorationBridge;
#if KWIN_BUILD_ACTIVITIES
std::unique_ptr<Activities> m_activities;
#endif

View file

@ -1144,7 +1144,7 @@ void X11Window::invalidateDecoration()
void X11Window::createDecoration(const QRectF &oldgeom)
{
std::shared_ptr<KDecoration2::Decoration> decoration(Decoration::DecorationBridge::self()->createDecoration(this));
std::shared_ptr<KDecoration2::Decoration> 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);

View file

@ -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;
}