Commit 94ee33e9 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

wayland: Fix touch event delivery to subsurfaces

Use SurfaceInterface::inputSurfaceAt when deciding which surface are we
entering when sending a pointer event from a touch, in case it falls
onto a subsurface.

BUG: 452967
parent c73444dd
Pipeline #210267 passed with stage
in 23 minutes and 11 seconds
......@@ -1056,7 +1056,6 @@ void SeatInterface::setFocusedTouchSurface(SurfaceInterface *surface, const QPoi
d->globalTouch.focus = SeatInterfacePrivate::Touch::Focus();
});
}
d->touch->setFocusedSurface(surface);
}
void SeatInterface::setFocusedTouchSurfacePosition(const QPointF &surfacePosition)
......@@ -1068,12 +1067,19 @@ void SeatInterface::setFocusedTouchSurfacePosition(const QPointF &surfacePositio
void SeatInterface::notifyTouchDown(qint32 id, const QPointF &globalPosition)
{
if (!d->touch) {
if (!d->touch || !focusedTouchSurface()) {
return;
}
const qint32 serial = display()->nextSerial();
const auto pos = globalPosition - d->globalTouch.focus.offset;
d->touch->sendDown(id, serial, pos);
auto pos = globalPosition - d->globalTouch.focus.offset;
SurfaceInterface *effectiveFocusedSurface = focusedTouchSurface()->inputSurfaceAt(pos);
if (effectiveFocusedSurface && effectiveFocusedSurface != focusedTouchSurface()) {
pos = focusedTouchSurface()->mapToChild(effectiveFocusedSurface, pos);
} else if (!effectiveFocusedSurface) {
effectiveFocusedSurface = focusedTouchSurface();
}
d->touch->sendDown(id, serial, pos, effectiveFocusedSurface);
if (id == 0) {
d->globalTouch.focus.firstTouchPos = globalPosition;
......@@ -1081,10 +1087,10 @@ void SeatInterface::notifyTouchDown(qint32 id, const QPointF &globalPosition)
if (id == 0 && hasPointer() && focusedTouchSurface()) {
TouchInterfacePrivate *touchPrivate = TouchInterfacePrivate::get(d->touch.data());
if (!touchPrivate->hasTouchesForClient(focusedTouchSurface()->client())) {
if (!touchPrivate->hasTouchesForClient(effectiveFocusedSurface->client())) {
// If the client did not bind the touch interface fall back
// to at least emulating touch through pointer events.
d->pointer->sendEnter(focusedTouchSurface(), pos, serial);
d->pointer->sendEnter(effectiveFocusedSurface, pos, serial);
d->pointer->sendMotion(pos);
d->pointer->sendFrame();
}
......@@ -1105,7 +1111,12 @@ void SeatInterface::notifyTouchMotion(qint32 id, const QPointF &globalPosition)
return;
}
const auto pos = globalPosition - d->globalTouch.focus.offset;
auto pos = globalPosition - d->globalTouch.focus.offset;
SurfaceInterface *effectiveFocusedSurface = d->touch->focusedSurface();
if (effectiveFocusedSurface && focusedTouchSurface() != effectiveFocusedSurface) {
pos = focusedTouchSurface()->mapToChild(effectiveFocusedSurface, pos);
}
if (isDragTouch()) {
// handled by DataDevice
} else {
......
......@@ -54,11 +54,6 @@ SurfaceInterface *TouchInterface::focusedSurface() const
return d->focusedSurface;
}
void TouchInterface::setFocusedSurface(SurfaceInterface *surface)
{
d->focusedSurface = surface;
}
void TouchInterface::sendCancel()
{
if (!d->focusedSurface) {
......@@ -109,12 +104,14 @@ void TouchInterface::sendUp(qint32 id, quint32 serial)
}
}
void TouchInterface::sendDown(qint32 id, quint32 serial, const QPointF &localPos)
void TouchInterface::sendDown(qint32 id, quint32 serial, const QPointF &localPos, SurfaceInterface *surface)
{
if (!d->focusedSurface) {
if (!surface) {
return;
}
d->focusedSurface = surface;
QPointF pos = d->focusedSurface->toSurfaceLocal(localPos);
const auto touchResources = d->touchesForClient(d->focusedSurface->client());
......
......@@ -29,9 +29,8 @@ public:
~TouchInterface() override;
SurfaceInterface *focusedSurface() const;
void setFocusedSurface(SurfaceInterface *surface);
void sendDown(qint32 id, quint32 serial, const QPointF &localPos);
void sendDown(qint32 id, quint32 serial, const QPointF &localPos, SurfaceInterface *surface);
void sendUp(qint32 id, quint32 serial);
void sendFrame();
void sendCancel();
......
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