Reduce code duplication between X11Client::createDecoration() and AbstractClient::createDecoration()

This commit is contained in:
Vlad Zahorodnii 2021-12-08 12:51:04 +02:00
parent 0db88c3ea6
commit 01a46ff389
2 changed files with 26 additions and 46 deletions

View file

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

View file

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