[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:
parent
f3d2ae59ff
commit
009017c8bd
1 changed files with 51 additions and 55 deletions
|
@ -181,34 +181,68 @@ void SurfaceInterface::Private::installPointerConstraint(LockedPointerInterface
|
|||
Q_ASSERT(lockedPointer.isNull());
|
||||
Q_ASSERT(confinedPointer.isNull());
|
||||
lockedPointer = QPointer<LockedPointerInterface>(lock);
|
||||
if (lock->lifeTime() == LockedPointerInterface::LifeTime::OneShot) {
|
||||
constrainsOneShotConnection = QObject::connect(lock, &LockedPointerInterface::lockedChanged, q_func(),
|
||||
[this] {
|
||||
if (lockedPointer.isNull()) {
|
||||
return;
|
||||
}
|
||||
if (!lockedPointer->isLocked()) {
|
||||
|
||||
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) {
|
||||
constrainsOneShotConnection = QObject::connect(lock, &LockedPointerInterface::lockedChanged, q_func(),
|
||||
[this, cleanUp] {
|
||||
if (lockedPointer.isNull() || lockedPointer->isLocked()) {
|
||||
return;
|
||||
}
|
||||
cleanUp();
|
||||
}
|
||||
);
|
||||
}
|
||||
constrainsUnboundConnection = QObject::connect(lock, &LockedPointerInterface::unbound, q_func(),
|
||||
[this] {
|
||||
[this, cleanUp] {
|
||||
if (lockedPointer.isNull()) {
|
||||
return;
|
||||
}
|
||||
lockedPointer.clear();
|
||||
cleanUp();
|
||||
}
|
||||
);
|
||||
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();
|
||||
|
@ -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
|
||||
const struct wl_surface_interface SurfaceInterface::Private::s_interface = {
|
||||
resourceDestroyedCallback,
|
||||
|
|
Loading…
Reference in a new issue