summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohan Klokkhammer Helsing <johan.helsing@qt.io>2019-12-20 09:31:04 +0100
committerJohan Klokkhammer Helsing <johan.helsing@qt.io>2019-12-30 12:33:29 +0100
commit957c0f52de83a0efe75b0ab33d1645799b892725 (patch)
treebff0e3d7e0c0fec62ee8037beafd92e5fd5d0821 /src
parent4b2376e850d5030f73fd9e8e03ebf07922e1361b (diff)
Client: Add QWaylandWindow::mapFromWlSurface
Qt window coordinates start inside the decorations, while wl_surface coordinates start at the first pixel of the buffer. Potentially, that would be in the shadow, although we don't have those. So for now, it's the first pixel of the decorations. Change-Id: Idccf8a359035f5477d6bc9e2e03a0e9fafe16971 Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@liri.io>
Diffstat (limited to 'src')
-rw-r--r--src/client/qwaylandinputdevice.cpp3
-rw-r--r--src/client/qwaylandwindow.cpp17
-rw-r--r--src/client/qwaylandwindow_p.h1
3 files changed, 16 insertions, 5 deletions
diff --git a/src/client/qwaylandinputdevice.cpp b/src/client/qwaylandinputdevice.cpp
index 3f0d61d6a..8f23805de 100644
--- a/src/client/qwaylandinputdevice.cpp
+++ b/src/client/qwaylandinputdevice.cpp
@@ -1408,8 +1408,7 @@ void QWaylandInputDevice::handleTouchPoint(int id, Qt::TouchPointState state, co
return;
tp.area = QRectF(0, 0, 8, 8);
- QMargins margins = win->frameMargins();
- QPointF localPosition = surfacePosition - QPointF(margins.left(), margins.top());
+ QPointF localPosition = win->mapFromWlSurface(surfacePosition);
// TODO: This doesn't account for high dpi scaling for the delta, but at least it matches
// what we have for mouse input.
QPointF delta = localPosition - localPosition.toPoint();
diff --git a/src/client/qwaylandwindow.cpp b/src/client/qwaylandwindow.cpp
index a6134cf49..0a623e9a2 100644
--- a/src/client/qwaylandwindow.cpp
+++ b/src/client/qwaylandwindow.cpp
@@ -672,6 +672,19 @@ QRect QWaylandWindow::windowContentGeometry() const
return QRect(QPoint(), surfaceSize());
}
+/*!
+ * Converts from wl_surface coordinates to Qt window coordinates. Qt window
+ * coordinates start inside (not including) the window decorations, while
+ * wl_surface coordinates start at the first pixel of the buffer. Potentially,
+ * this should be in the window shadow, although we don't have those. So for
+ * now, it's the first pixel of the decorations.
+ */
+QPointF QWaylandWindow::mapFromWlSurface(const QPointF &surfacePosition) const
+{
+ const QMargins margins = frameMargins();
+ return QPointF(surfacePosition.x() - margins.left(), surfacePosition.y() - margins.top());
+}
+
wl_surface *QWaylandWindow::wlSurface()
{
return mSurface ? mSurface->object() : nullptr;
@@ -922,10 +935,8 @@ void QWaylandWindow::handleMouseEventWithDecoration(QWaylandInputDevice *inputDe
geometry().size().width() - marg.right(),
geometry().size().height() - marg.bottom());
if (windowRect.contains(e.local.toPoint()) || mMousePressedInContentArea != Qt::NoButton) {
- QPointF localTranslated = e.local;
+ const QPointF localTranslated = mapFromWlSurface(e.local);
QPointF globalTranslated = e.global;
- localTranslated.setX(localTranslated.x() - marg.left());
- localTranslated.setY(localTranslated.y() - marg.top());
globalTranslated.setX(globalTranslated.x() - marg.left());
globalTranslated.setY(globalTranslated.y() - marg.top());
if (!mMouseEventsInContentArea) {
diff --git a/src/client/qwaylandwindow_p.h b/src/client/qwaylandwindow_p.h
index 36cbee89b..35fa1fdfc 100644
--- a/src/client/qwaylandwindow_p.h
+++ b/src/client/qwaylandwindow_p.h
@@ -129,6 +129,7 @@ public:
QMargins frameMargins() const override;
QSize surfaceSize() const;
QRect windowContentGeometry() const;
+ QPointF mapFromWlSurface(const QPointF &surfacePosition) const;
QWaylandSurface *waylandSurface() const { return mSurface.data(); }
::wl_surface *wlSurface();