From 01a46ff389af6c2b411e72ce4f063502c2c9caaf Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 8 Dec 2021 12:51:04 +0200 Subject: [PATCH] Reduce code duplication between X11Client::createDecoration() and AbstractClient::createDecoration() --- src/abstract_client.cpp | 45 ++++++++++++++++++++++------------------- src/x11client.cpp | 27 ++----------------------- 2 files changed, 26 insertions(+), 46 deletions(-) diff --git a/src/abstract_client.cpp b/src/abstract_client.cpp index a6def53f6f..944b20e9cf 100644 --- a/src/abstract_client.cpp +++ b/src/abstract_client.cpp @@ -2310,27 +2310,8 @@ void AbstractClient::endInteractiveMoveResize() void AbstractClient::createDecoration(const QRect &oldGeometry) { - KDecoration2::Decoration *decoration = Decoration::DecorationBridge::self()->createDecoration(this); - if (decoration) { - QMetaObject::invokeMethod(decoration, QOverload<>::of(&KDecoration2::Decoration::update), Qt::QueuedConnection); - connect(decoration, &KDecoration2::Decoration::shadowChanged, this, &Toplevel::updateShadow); - connect(decoration, &KDecoration2::Decoration::bordersChanged, - this, &AbstractClient::updateDecorationInputShape); - connect(decoration, &KDecoration2::Decoration::resizeOnlyBordersChanged, - this, &AbstractClient::updateDecorationInputShape); - connect(decoration, &KDecoration2::Decoration::bordersChanged, this, [this]() { - GeometryUpdatesBlocker blocker(this); - const QRect oldGeometry = frameGeometry(); - if (!isShade()) { - checkWorkspacePosition(oldGeometry); - } - Q_EMIT geometryShapeChanged(this, oldGeometry); - }); - connect(decoratedClient()->decoratedClient(), &KDecoration2::DecoratedClient::sizeChanged, - this, &AbstractClient::updateDecorationInputShape); - } - setDecoration(decoration); - moveResize(QRect(oldGeometry.topLeft(), clientSizeToFrameSize(clientSize()))); + setDecoration(Decoration::DecorationBridge::self()->createDecoration(this)); + moveResize(oldGeometry); Q_EMIT geometryShapeChanged(this, oldGeometry); } @@ -2344,6 +2325,28 @@ void AbstractClient::destroyDecoration() void AbstractClient::setDecoration(KDecoration2::Decoration *decoration) { + if (m_decoration.decoration.data() == decoration) { + return; + } + if (decoration) { + QMetaObject::invokeMethod(decoration, QOverload<>::of(&KDecoration2::Decoration::update), Qt::QueuedConnection); + connect(decoration, &KDecoration2::Decoration::shadowChanged, this, &Toplevel::updateShadow); + connect(decoration, &KDecoration2::Decoration::bordersChanged, + this, &AbstractClient::updateDecorationInputShape); + connect(decoration, &KDecoration2::Decoration::resizeOnlyBordersChanged, + this, &AbstractClient::updateDecorationInputShape); + connect(decoration, &KDecoration2::Decoration::bordersChanged, this, [this]() { + GeometryUpdatesBlocker blocker(this); + const QRect oldGeometry = frameGeometry(); + resize(implicitSize()); + if (!isShade()) { + checkWorkspacePosition(oldGeometry); + } + Q_EMIT geometryShapeChanged(this, oldGeometry); + }); + connect(decoratedClient()->decoratedClient(), &KDecoration2::DecoratedClient::sizeChanged, + this, &AbstractClient::updateDecorationInputShape); + } m_decoration.decoration.reset(decoration); updateDecorationInputShape(); Q_EMIT decorationChanged(); diff --git a/src/x11client.cpp b/src/x11client.cpp index 30e17cfda6..b7058bf1ff 100644 --- a/src/x11client.cpp +++ b/src/x11client.cpp @@ -1114,32 +1114,9 @@ void X11Client::createDecoration(const QRect& oldgeom) { KDecoration2::Decoration *decoration = Decoration::DecorationBridge::self()->createDecoration(this); if (decoration) { - QMetaObject::invokeMethod(decoration, QOverload<>::of(&KDecoration2::Decoration::update), Qt::QueuedConnection); - connect(decoration, &KDecoration2::Decoration::shadowChanged, this, &Toplevel::updateShadow); - connect(decoration, &KDecoration2::Decoration::bordersChanged, - this, &X11Client::updateDecorationInputShape); - connect(decoration, &KDecoration2::Decoration::resizeOnlyBordersChanged, - this, &X11Client::updateDecorationInputShape); connect(decoration, &KDecoration2::Decoration::resizeOnlyBordersChanged, this, &X11Client::updateInputWindow); - connect(decoration, &KDecoration2::Decoration::bordersChanged, this, - [this]() { - updateFrameExtents(); - GeometryUpdatesBlocker blocker(this); - // TODO: this is obviously idempotent - // calculateGravitation(true) would have to operate on the old border sizes -// move(calculateGravitation(true)); -// move(calculateGravitation(false)); - QRect oldgeom = frameGeometry(); - resize(implicitSize()); - if (!isShade()) - checkWorkspacePosition(oldgeom); - Q_EMIT geometryShapeChanged(this, oldgeom); - } - ); - connect(decoratedClient()->decoratedClient(), &KDecoration2::DecoratedClient::widthChanged, this, &X11Client::updateInputWindow); - connect(decoratedClient()->decoratedClient(), &KDecoration2::DecoratedClient::heightChanged, this, &X11Client::updateInputWindow); - connect(decoratedClient()->decoratedClient(), &KDecoration2::DecoratedClient::sizeChanged, - this, &X11Client::updateDecorationInputShape); + connect(decoration, &KDecoration2::Decoration::bordersChanged, this, &X11Client::updateFrameExtents); + connect(decoratedClient()->decoratedClient(), &KDecoration2::DecoratedClient::sizeChanged, this, &X11Client::updateInputWindow); } setDecoration(decoration);