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>
This commit is contained in:
parent
b21eacfa57
commit
84c2b4802f
@ -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();
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user