summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
authorMorten Sørvig <morten.sorvig@qt.io>2023-01-05 14:59:22 +0100
committerMorten Sørvig <morten.sorvig@qt.io>2023-01-06 17:57:17 +0100
commit1d3d7bfbbcfde475804db31747c3a4b42d3bfc9b (patch)
tree6fa6795ff9d865738ae9976299007c5a2d41d8bd /src/plugins/platforms
parent029e118a4e014c3751c4a8f6bcc41f85b78286d5 (diff)
wasm: sync pointer button state on pointer down
We may get PointerDown events with "no buttons" as the button state in some cases such as for tap events on Apple trackpads. Make sure the mouse button which caused the pointer down event is in the mouse buttons set for the event. Fixes: QTBUG-108639 Pick-to: 6.4 6.5 Change-Id: I0a49abc398308bbfed657b99fc74f60c16e05a59 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/wasm/qwasmevent.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/plugins/platforms/wasm/qwasmevent.cpp b/src/plugins/platforms/wasm/qwasmevent.cpp
index d4f9991feb..19730c2c68 100644
--- a/src/plugins/platforms/wasm/qwasmevent.cpp
+++ b/src/plugins/platforms/wasm/qwasmevent.cpp
@@ -44,6 +44,14 @@ std::optional<PointerEvent> PointerEvent::fromWeb(emscripten::val event)
PointerType::Mouse : PointerType::Other;
ret.mouseButton = MouseEvent::buttonFromWeb(event["button"].as<int>());
ret.mouseButtons = MouseEvent::buttonsFromWeb(event["buttons"].as<unsigned short>());
+
+ // The current button state (event.buttons) may be out of sync for some PointerDown
+ // events where the "down" state is very brief, for example taps on Apple trackpads.
+ // Qt expects that the current button state is in sync with the event, so we sync
+ // it up here.
+ if (*eventType == EventType::PointerDown)
+ ret.mouseButtons |= ret.mouseButton;
+
ret.localPoint = QPoint(event["offsetX"].as<int>(), event["offsetY"].as<int>());
ret.pointInPage = QPoint(event["pageX"].as<int>(), event["pageY"].as<int>());
ret.pointInViewport = QPoint(event["clientX"].as<int>(), event["clientY"].as<int>());