From 9e4d9fca8a5ed0a10033345bc88b4ae39d20b952 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 12 Jan 2021 14:50:40 +0100 Subject: QGuiApplication: use global position to create local position for synthetic mouse events When QWidgetWindow handles a QTouchEvent, it will call updateTouchPointsForWidget() for each widget it tries to deliver the touch event to. This will make sure that the point's position() is updated to be local to the widget being processed. The problem is that we never reset this overwriting of local positions in the event after we're done. So if we later try to synthesize a mouse event from it, the local position in the fake mouse event will be based on the local position inside a random widget, and not the original local position sent from QPA. Rather than trying to store all the original local positions inside the event before going through this delivery logic, and reset it afterwards, we base the local position of the synthesized mouse event on the (unmodified) global position instead. Fixes: QTBUG-90033 Pick-to: dev Change-Id: I1588351482de7cce9c06d102db3686ea8dd0c118 Reviewed-by: Jani Heikkinen Reviewed-by: Shawn Rutledge --- src/gui/kernel/qguiapplication.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/gui/kernel/qguiapplication.cpp') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index d3ed576220..b6720a8e76 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2954,6 +2954,9 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To continue; } + // Note: after the call to sendSpontaneousEvent, touchEvent.position() will have + // changed to reflect the local position inside the last (random) widget it tried + // to deliver the touch event to, and will therefore be invalid afterwards. QGuiApplication::sendSpontaneousEvent(window, &touchEvent); if (!e->synthetic() && !touchEvent.isAccepted() && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)) { @@ -2993,7 +2996,7 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To // left mouse button events instead (see AA_SynthesizeMouseForUnhandledTouchEvents docs). // TODO why go through QPA? Why not just send a QMouseEvent right from here? QWindowSystemInterfacePrivate::MouseEvent fake(window, e->timestamp, - touchPoint->position(), + window->mapFromGlobal(touchPoint->globalPosition().toPoint()), touchPoint->globalPosition(), buttons, e->modifiers, -- cgit v1.2.3