From 820a6d4117fc59b960e273e5f10d65b89217ce61 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Thu, 25 Nov 2021 16:39:45 +1000 Subject: [PATCH] wasm: fix mouse move and right click MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Emscripten has no concept of 'no mouse button', so when there is no button down, it was sending left mouse. Also we were hiding mousepress for only leftmouse downs. Fixes: QTBUG-97431 Pick-to: 6.2 Change-Id: Ibf078705c343944e45551830b7fee94ed5aa7333 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/wasm/qwasmeventtranslator.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp index 0017e182a2..5f809140f5 100644 --- a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp +++ b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp @@ -437,7 +437,7 @@ bool QWasmEventTranslator::processMouse(int eventType, const EmscriptenMouseEven QPoint globalPoint = screen()->geometry().topLeft() + targetPoint; QEvent::Type buttonEventType = QEvent::None; - Qt::MouseButton button = translateMouseButton(mouseEvent->button); + Qt::MouseButton button = Qt::NoButton; Qt::KeyboardModifiers modifiers = translateMouseEventModifier(mouseEvent); QWindow *window2 = nullptr; @@ -457,19 +457,22 @@ bool QWasmEventTranslator::processMouse(int eventType, const EmscriptenMouseEven switch (eventType) { case EMSCRIPTEN_EVENT_MOUSEDOWN: { + button = translateMouseButton(mouseEvent->button); + if (window2) window2->requestActivate(); pressedButtons.setFlag(button); + pressedWindow = window2; + buttonEventType = QEvent::MouseButtonPress; + // button overview: // 0 = primary mouse button, usually left click // 1 = middle mouse button, usually mouse wheel // 2 = right mouse button, usually right click // from: https://w3c.github.io/uievents/#dom-mouseevent-button if (mouseEvent->button == 0) { - pressedWindow = window2; - buttonEventType = QEvent::MouseButtonPress; if (!(htmlWindow->m_windowState & Qt::WindowFullScreen) && !(htmlWindow->m_windowState & Qt::WindowMaximized)) { if (htmlWindow && window2->flags().testFlag(Qt::WindowTitleHint) && htmlWindow->isPointOnTitle(globalPoint)) draggedWindow = window2; @@ -487,7 +490,8 @@ bool QWasmEventTranslator::processMouse(int eventType, const EmscriptenMouseEven } case EMSCRIPTEN_EVENT_MOUSEUP: { - pressedButtons.setFlag(translateMouseButton(mouseEvent->button), false); + button = translateMouseButton(mouseEvent->button); + pressedButtons.setFlag(button, false); buttonEventType = QEvent::MouseButtonRelease; QWasmWindow *oldWindow = nullptr;