summaryrefslogtreecommitdiffstats
path: root/src/compositor/compositor_api/qwaylandsurface.cpp
diff options
context:
space:
mode:
authorJohan Klokkhammer Helsing <johan.helsing@qt.io>2019-09-04 10:12:32 +0200
committerJohan Klokkhammer Helsing <johan.helsing@qt.io>2019-09-05 10:10:19 +0200
commit7f189ec10a9b3e9825dda30d3a8f86ee2e07b97f (patch)
tree3ce274aef44192fe5439649bb943a696b7f6b036 /src/compositor/compositor_api/qwaylandsurface.cpp
parent2950ab906db92ad0e00a1113fb0027b76e6c8ac0 (diff)
Compositor: Fix various input-related rounding errors
QPointF::toPoint (which is what the QPoint versions of the events use internally) uses qRound, which is not the right kind of rounding to use with the QRegion we use for the input region. This switches to use QPointF variants instead of QPoint wherever possible, and then the correct conversion (with qFloor) is done once in the new QPointF version of QWaylandSurface::inputRegionContains(). The compositor inputRegion test has now been updated to test the new API. [ChangeLog][Compositor] Fixed various rounding errors related to touch and mouse input. Fixes: QTBUG-77457 Change-Id: Ife2365abd56a239c34eee91310ab0e698a50d4ff Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'src/compositor/compositor_api/qwaylandsurface.cpp')
-rw-r--r--src/compositor/compositor_api/qwaylandsurface.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/compositor/compositor_api/qwaylandsurface.cpp b/src/compositor/compositor_api/qwaylandsurface.cpp
index c79787e6e..a82c93f7b 100644
--- a/src/compositor/compositor_api/qwaylandsurface.cpp
+++ b/src/compositor/compositor_api/qwaylandsurface.cpp
@@ -67,6 +67,7 @@
#include <QtGui/QScreen>
#include <QtCore/QDebug>
+#include <QtCore/QtMath>
QT_BEGIN_NAMESPACE
@@ -706,6 +707,23 @@ bool QWaylandSurface::inputRegionContains(const QPoint &p) const
return d->inputRegion.contains(p);
}
+//TODO: Add appropriate \since version when this is made public.
+/*!
+ * Returns \c true if the QWaylandSurface's input region contains the point \a position.
+ * Otherwise returns \c false.
+ */
+bool QWaylandSurface::inputRegionContains(const QPointF &position) const
+{
+ Q_D(const QWaylandSurface);
+ // QRegion::contains operates in integers. If a region has a rect (0,0,10,10), (0,0) is
+ // inside while (10,10) is outside. Therefore, we can't use QPoint::toPoint(), which will
+ // round upwards, meaning the point (-0.25,-0.25) would be rounded to (0,0) and count as
+ // being inside the region, and similarly, a point (9.75,9.75) inside the region would be
+ // rounded upwards and count as being outside the region.
+ const QPoint floored(qFloor(position.x()), qFloor(position.y()));
+ return d->inputRegion.contains(floored);
+}
+
/*!
* \qmlmethod void QtWaylandCompositor::WaylandSurface::destroy()
*