From 883a12d28d469940335d3e33d6fc63388c860aad Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Thu, 24 Aug 2023 19:00:02 +1000 Subject: [PATCH] wasm: remove 'shift' from being inputed on touchscreens MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: QTBUG-116231 Change-Id: Icbbe80877c2c21c3e82ba2c27909b6679b72e498 Reviewed-by: Morten Johan Sørvig (cherry picked from commit 91d3c48d3da5f75e126bbce79096a84c078e23e2) Reviewed-by: Qt Cherry-pick Bot --- .../platforms/wasm/qwasminputcontext.cpp | 22 ++++++++++++++----- .../platforms/wasm/qwasminputcontext.h | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/plugins/platforms/wasm/qwasminputcontext.cpp b/src/plugins/platforms/wasm/qwasminputcontext.cpp index fb2d81d33d6..f2c4c93fe4d 100644 --- a/src/plugins/platforms/wasm/qwasminputcontext.cpp +++ b/src/plugins/platforms/wasm/qwasminputcontext.cpp @@ -30,7 +30,7 @@ static void inputCallback(emscripten::val event) QString str = QString::fromStdString(_incomingCharVal.as()); QWasmInputContext *wasmInput = reinterpret_cast(event["target"]["data-qinputcontext"].as()); - wasmInput->inputStringChanged(str, wasmInput); + wasmInput->inputStringChanged(str, EMSCRIPTEN_EVENT_KEYDOWN, wasmInput); } // this clears the input string, so backspaces do not send a character // but stops suggestions @@ -138,13 +138,26 @@ void QWasmInputContext::hideInputPanel() inputPanelIsOpen = false; } -void QWasmInputContext::inputStringChanged(QString &inputString, QWasmInputContext *context) +void QWasmInputContext::inputStringChanged(QString &inputString, int eventType, QWasmInputContext *context) { Q_UNUSED(context) QKeySequence keys = QKeySequence::fromString(inputString); + Qt::Key thisKey = keys[0].key(); + // synthesize this keyevent as android is not normal + if (inputString.size() > 2 && (thisKey < Qt::Key_F35 + || thisKey > Qt::Key_Back)) { + inputString.clear(); + } + if (inputString == QStringLiteral("Escape")) { + thisKey = Qt::Key_Escape; + inputString.clear(); + } else if (thisKey == Qt::Key(0)) { + thisKey = Qt::Key_Return; + } QWindowSystemInterface::handleKeyEvent( - 0, QEvent::KeyPress,keys[0].key(), keys[0].keyboardModifiers(), inputString); + 0, eventType == EMSCRIPTEN_EVENT_KEYDOWN ? QEvent::KeyPress : QEvent::KeyRelease, + thisKey, keys[0].keyboardModifiers(), inputString); } int QWasmInputContext::androidKeyboardCallback(int eventType, @@ -152,13 +165,12 @@ int QWasmInputContext::androidKeyboardCallback(int eventType, void *userData) { // we get Enter, Backspace and function keys via emscripten on target window - Q_UNUSED(eventType) QString strKey(keyEvent->key); if (strKey == "Unidentified" || strKey == "Process") return false; QWasmInputContext *wasmInput = reinterpret_cast(userData); - wasmInput->inputStringChanged(strKey, wasmInput); + wasmInput->inputStringChanged(strKey, eventType, wasmInput); return true; } diff --git a/src/plugins/platforms/wasm/qwasminputcontext.h b/src/plugins/platforms/wasm/qwasminputcontext.h index 086599bfb04..7e07220bd2b 100644 --- a/src/plugins/platforms/wasm/qwasminputcontext.h +++ b/src/plugins/platforms/wasm/qwasminputcontext.h @@ -29,7 +29,7 @@ public: bool isValid() const override { return true; } void focusWindowChanged(QWindow *focusWindow); - void inputStringChanged(QString &, QWasmInputContext *context); + void inputStringChanged(QString &, int eventType, QWasmInputContext *context); private: emscripten::val inputHandlerElementForFocusedWindow();