[server] Small code cleanup in SurfaceInterface

Summary:
Use lambda function to reduce code duplication and put
function definitions in the same order as in the header file.

Test Plan: All autotests succeed.

Reviewers: #plasma, davidedmundson

Reviewed By: #plasma, davidedmundson

Subscribers: davidedmundson, kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D13191
This commit is contained in:
Roman Gilg 2018-05-29 10:35:28 +02:00
parent f3d2ae59ff
commit 009017c8bd

View file

@ -181,34 +181,68 @@ void SurfaceInterface::Private::installPointerConstraint(LockedPointerInterface
Q_ASSERT(lockedPointer.isNull()); Q_ASSERT(lockedPointer.isNull());
Q_ASSERT(confinedPointer.isNull()); Q_ASSERT(confinedPointer.isNull());
lockedPointer = QPointer<LockedPointerInterface>(lock); lockedPointer = QPointer<LockedPointerInterface>(lock);
auto cleanUp = [this]() {
lockedPointer.clear();
disconnect(constrainsOneShotConnection);
constrainsOneShotConnection = QMetaObject::Connection();
disconnect(constrainsUnboundConnection);
constrainsUnboundConnection = QMetaObject::Connection();
emit q_func()->pointerConstraintsChanged();
};
if (lock->lifeTime() == LockedPointerInterface::LifeTime::OneShot) { if (lock->lifeTime() == LockedPointerInterface::LifeTime::OneShot) {
constrainsOneShotConnection = QObject::connect(lock, &LockedPointerInterface::lockedChanged, q_func(), constrainsOneShotConnection = QObject::connect(lock, &LockedPointerInterface::lockedChanged, q_func(),
[this] { [this, cleanUp] {
if (lockedPointer.isNull()) { if (lockedPointer.isNull() || lockedPointer->isLocked()) {
return; return;
} }
if (!lockedPointer->isLocked()) { cleanUp();
lockedPointer.clear();
disconnect(constrainsOneShotConnection);
constrainsOneShotConnection = QMetaObject::Connection();
disconnect(constrainsUnboundConnection);
constrainsUnboundConnection = QMetaObject::Connection();
emit q_func()->pointerConstraintsChanged();
}
} }
); );
} }
constrainsUnboundConnection = QObject::connect(lock, &LockedPointerInterface::unbound, q_func(), constrainsUnboundConnection = QObject::connect(lock, &LockedPointerInterface::unbound, q_func(),
[this] { [this, cleanUp] {
if (lockedPointer.isNull()) { if (lockedPointer.isNull()) {
return; return;
} }
lockedPointer.clear(); cleanUp();
disconnect(constrainsOneShotConnection); }
constrainsOneShotConnection = QMetaObject::Connection(); );
disconnect(constrainsUnboundConnection); emit q_func()->pointerConstraintsChanged();
constrainsUnboundConnection = QMetaObject::Connection(); }
emit q_func()->pointerConstraintsChanged();
void SurfaceInterface::Private::installPointerConstraint(ConfinedPointerInterface *confinement)
{
Q_ASSERT(lockedPointer.isNull());
Q_ASSERT(confinedPointer.isNull());
confinedPointer = QPointer<ConfinedPointerInterface>(confinement);
auto cleanUp = [this]() {
confinedPointer.clear();
disconnect(constrainsOneShotConnection);
constrainsOneShotConnection = QMetaObject::Connection();
disconnect(constrainsUnboundConnection);
constrainsUnboundConnection = QMetaObject::Connection();
emit q_func()->pointerConstraintsChanged();
};
if (confinement->lifeTime() == ConfinedPointerInterface::LifeTime::OneShot) {
constrainsOneShotConnection = QObject::connect(confinement, &ConfinedPointerInterface::confinedChanged, q_func(),
[this, cleanUp] {
if (confinedPointer.isNull() || confinedPointer->isConfined()) {
return;
}
cleanUp();
}
);
}
constrainsUnboundConnection = QObject::connect(confinement, &ConfinedPointerInterface::unbound, q_func(),
[this, cleanUp] {
if (confinedPointer.isNull()) {
return;
}
cleanUp();
} }
); );
emit q_func()->pointerConstraintsChanged(); emit q_func()->pointerConstraintsChanged();
@ -230,44 +264,6 @@ void SurfaceInterface::Private::installIdleInhibitor(IdleInhibitorInterface *inh
} }
} }
void SurfaceInterface::Private::installPointerConstraint(ConfinedPointerInterface *confinement)
{
Q_ASSERT(lockedPointer.isNull());
Q_ASSERT(confinedPointer.isNull());
confinedPointer = QPointer<ConfinedPointerInterface>(confinement);
if (confinement->lifeTime() == ConfinedPointerInterface::LifeTime::OneShot) {
constrainsOneShotConnection = QObject::connect(confinement, &ConfinedPointerInterface::confinedChanged, q_func(),
[this] {
if (confinedPointer.isNull()) {
return;
}
if (!confinedPointer->isConfined()) {
confinedPointer.clear();
disconnect(constrainsOneShotConnection);
constrainsOneShotConnection = QMetaObject::Connection();
disconnect(constrainsUnboundConnection);
constrainsUnboundConnection = QMetaObject::Connection();
emit q_func()->pointerConstraintsChanged();
}
}
);
}
constrainsUnboundConnection = QObject::connect(confinement, &ConfinedPointerInterface::unbound, q_func(),
[this] {
if (confinedPointer.isNull()) {
return;
}
confinedPointer.clear();
disconnect(constrainsOneShotConnection);
constrainsOneShotConnection = QMetaObject::Connection();
disconnect(constrainsUnboundConnection);
constrainsUnboundConnection = QMetaObject::Connection();
emit q_func()->pointerConstraintsChanged();
}
);
emit q_func()->pointerConstraintsChanged();
}
#ifndef DOXYGEN_SHOULD_SKIP_THIS #ifndef DOXYGEN_SHOULD_SKIP_THIS
const struct wl_surface_interface SurfaceInterface::Private::s_interface = { const struct wl_surface_interface SurfaceInterface::Private::s_interface = {
resourceDestroyedCallback, resourceDestroyedCallback,