From 0c10be1859ff91c627144553c80758316a4050ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Thu, 5 Jan 2023 14:59:22 +0100 Subject: [PATCH] wasm: sync pointer button state on pointer down MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Change-Id: I0a49abc398308bbfed657b99fc74f60c16e05a59 Reviewed-by: Morten Johan Sørvig (cherry picked from commit 1d3d7bfbbcfde475804db31747c3a4b42d3bfc9b) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/wasm/qwasmevent.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/plugins/platforms/wasm/qwasmevent.cpp b/src/plugins/platforms/wasm/qwasmevent.cpp index 0e43a381bf3..4a013577fee 100644 --- a/src/plugins/platforms/wasm/qwasmevent.cpp +++ b/src/plugins/platforms/wasm/qwasmevent.cpp @@ -43,6 +43,14 @@ std::optional PointerEvent::fromWeb(emscripten::val event) PointerType::Mouse : PointerType::Other; ret.mouseButton = MouseEvent::buttonFromWeb(event["button"].as()); ret.mouseButtons = MouseEvent::buttonsFromWeb(event["buttons"].as()); + + // 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(), event["offsetY"].as()); ret.pointInPage = QPoint(event["pageX"].as(), event["pageY"].as()); ret.pointInViewport = QPoint(event["clientX"].as(), event["clientY"].as());