diff options
author | Johan Klokkhammer Helsing <johan.helsing@qt.io> | 2019-12-20 09:31:04 +0100 |
---|---|---|
committer | Johan Klokkhammer Helsing <johan.helsing@qt.io> | 2019-12-30 12:33:29 +0100 |
commit | 957c0f52de83a0efe75b0ab33d1645799b892725 (patch) | |
tree | bff0e3d7e0c0fec62ee8037beafd92e5fd5d0821 /src/client/qwaylandwindow.cpp | |
parent | 4b2376e850d5030f73fd9e8e03ebf07922e1361b (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/client/qwaylandwindow.cpp')
-rw-r--r-- | src/client/qwaylandwindow.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
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) { |