Commit c3f5f8ce authored by David Edmundson's avatar David Edmundson
Browse files

[wayland] Fix SurfaceInterface::surfaceItemAt

QRectF::contains includes all edges. If two subsurfaces are next to each
other ::contains will treat it as having a singularity where a value is
on 2 subsurfaces rather than either one of the other, which isn't what
we want for our purposes.

The unit test is extended but also featured some wrong values, the
biggest clue that it was wrong was that we used different test
co-ordiantes for surfaceContains and inputContains.
parent c8b4937f
Pipeline #187956 passed with stage
in 12 minutes and 56 seconds
......@@ -969,9 +969,9 @@ void TestSubSurface::testSurfaceAt()
QCOMPARE(parentServerSurface->surfaceAt(QPointF(0, 0)), childFor1ServerSurface);
QCOMPARE(parentServerSurface->surfaceAt(QPointF(49, 49)), childFor1ServerSurface);
QCOMPARE(parentServerSurface->surfaceAt(QPointF(50, 50)), childFor2ServerSurface);
QCOMPARE(parentServerSurface->surfaceAt(QPointF(100, 100)), childFor2ServerSurface);
QCOMPARE(parentServerSurface->surfaceAt(QPointF(100, 50)), childFor2ServerSurface);
QCOMPARE(parentServerSurface->surfaceAt(QPointF(50, 100)), childFor2ServerSurface);
QCOMPARE(parentServerSurface->surfaceAt(QPointF(99, 99)), childFor2ServerSurface);
QCOMPARE(parentServerSurface->surfaceAt(QPointF(99, 50)), childFor2ServerSurface);
QCOMPARE(parentServerSurface->surfaceAt(QPointF(50, 99)), childFor2ServerSurface);
QCOMPARE(parentServerSurface->surfaceAt(QPointF(25, 75)), parentServerSurface);
QCOMPARE(parentServerSurface->surfaceAt(QPointF(75, 25)), parentServerSurface);
......@@ -987,6 +987,12 @@ void TestSubSurface::testSurfaceAt()
// outside the geometries should be no surface
QVERIFY(!parentServerSurface->surfaceAt(QPointF(-1, -1)));
QVERIFY(!parentServerSurface->surfaceAt(QPointF(101, 101)));
// on the surface edge right/bottom edges should not trigger as contained
QCOMPARE(parentServerSurface->surfaceAt(QPointF(50, 25)), parentServerSurface);
QCOMPARE(parentServerSurface->surfaceAt(QPointF(25, 50)), parentServerSurface);
QCOMPARE(parentServerSurface->inputSurfaceAt(QPointF(50, 25)), parentServerSurface);
QCOMPARE(parentServerSurface->inputSurfaceAt(QPointF(25, 50)), parentServerSurface);
}
void TestSubSurface::testDestroyAttachedBuffer()
......
......@@ -761,6 +761,20 @@ void SurfaceInterfacePrivate::updateEffectiveMapped()
}
}
bool SurfaceInterfacePrivate::contains(const QPointF &position) const
{
// avoid QRectF::contains as that includes all edges
const qreal x = position.x();
const qreal y = position.y();
return mapped && x >= 0 && y >= 0 && x < surfaceSize.width() && y < surfaceSize.height();
}
bool SurfaceInterfacePrivate::inputContains(const QPointF &position) const
{
return contains(position) && inputRegion.contains(position.toPoint());
}
QRegion SurfaceInterface::damage() const
{
return d->current.damage;
......@@ -944,7 +958,7 @@ SurfaceInterface *SurfaceInterface::surfaceAt(const QPointF &position)
}
// check whether the geometry contains the pos
if (!size().isEmpty() && QRectF(QPoint(0, 0), size()).contains(position)) {
if (d->contains(position)) {
return this;
}
......@@ -975,7 +989,7 @@ SurfaceInterface *SurfaceInterface::inputSurfaceAt(const QPointF &position)
}
// check whether the geometry and input region contain the pos
if (!size().isEmpty() && QRectF(QPoint(0, 0), size()).contains(position) && input().contains(position.toPoint())) {
if (d->inputContains(position)) {
return this;
}
......
......@@ -96,6 +96,13 @@ public:
bool computeEffectiveMapped() const;
void updateEffectiveMapped();
/**
* Returns true if this surface (not including subsurfaces) contains a given point
* @param position in surface-local co-ordiantes
*/
bool contains(const QPointF &position) const;
bool inputContains(const QPointF &position) const;
CompositorInterface *compositor;
SurfaceInterface *q;
SurfaceRole *role = nullptr;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment