From f1638edf4599aa74be439873a7719d9b70c57f54 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Tue, 2 Jun 2020 14:27:37 +1000 Subject: [PATCH] wasm: fix handling on int dead keys on mac MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Q_OS_MAC is not defined when building wasm on mac, so we need to use a runtime check. Pick-to: 5.15 Change-Id: I1e9c5ec4e11aae94c9d8e918b5f1f1526723c782 Reviewed-by: Morten Johan Sørvig --- .../platforms/wasm/qwasmeventtranslator.cpp | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp index 8eb30c0ecd..38dbb2e9ff 100644 --- a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp +++ b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp @@ -305,7 +305,7 @@ static constexpr const auto DeadKeyShiftTbl = qMakeArray( // macOS CTRL <-> META switching. We most likely want to enable // the existing switching code in QtGui, but for now do it here. -static bool g_usePlatformMacCtrlMetaSwitching = false; +static bool g_usePlatformMacSpecifics = false; bool g_useNaturalScrolling = true; // natural scrolling is default on linux/windows @@ -348,7 +348,7 @@ void QWasmEventTranslator::initEventHandlers() }; Platform platform = Platform(emscripten::val::global("navigator")["platform"] .call("includes", emscripten::val("Mac"))); - g_usePlatformMacCtrlMetaSwitching = (platform == MacOSPlatform); + g_usePlatformMacSpecifics = (platform == MacOSPlatform); if (platform == MacOSPlatform) { g_useNaturalScrolling = false; // make this !default on macOS @@ -385,7 +385,7 @@ QFlags QWasmEventTranslator::translatKeyModifier(const Eve if (event->shiftKey) keyModifier |= Qt::ShiftModifier; if (event->ctrlKey) { - if (g_usePlatformMacCtrlMetaSwitching) + if (g_usePlatformMacSpecifics) keyModifier |= Qt::MetaModifier; else keyModifier |= Qt::ControlModifier; @@ -393,7 +393,7 @@ QFlags QWasmEventTranslator::translatKeyModifier(const Eve if (event->altKey) keyModifier |= Qt::AltModifier; if (event->metaKey) { - if (g_usePlatformMacCtrlMetaSwitching) + if (g_usePlatformMacSpecifics) keyModifier |= Qt::ControlModifier; else keyModifier |= Qt::MetaModifier; @@ -442,7 +442,6 @@ Qt::Key QWasmEventTranslator::translateEmscriptKey(const EmscriptenKeyboardEvent } else if (qstrncmp(emscriptKey->code, "Key", 3) == 0 || qstrncmp(emscriptKey->code, "Numpad", 6) == 0 || qstrncmp(emscriptKey->code, "Digit", 5) == 0) { - emkb2qt_t searchKey{emscriptKey->code, 0}; // search emcsripten code auto it1 = std::lower_bound(KeyTbl.cbegin(), KeyTbl.cend(), searchKey); if (it1 != KeyTbl.end() && !(searchKey < *it1)) { @@ -839,12 +838,19 @@ static Qt::Key find(const KeyMapping (&map)[N], Qt::Key key) noexcept Qt::Key QWasmEventTranslator::translateDeadKey(Qt::Key deadKey, Qt::Key accentBaseKey) { Qt::Key wasmKey = Qt::Key_unknown; + + if (deadKey == Qt::Key_QuoteLeft ) { + if (g_usePlatformMacSpecifics) { // ` macOS: Key_Dead_Grave + wasmKey = find(graveKeyTable, accentBaseKey); + } else { + wasmKey = find(diaeresisKeyTable, accentBaseKey); + } + return wasmKey; + } + switch (deadKey) { -#ifdef Q_OS_MACOS - case Qt::Key_QuoteLeft: // ` macOS: Key_Dead_Grave -#else + // case Qt::Key_QuoteLeft: case Qt::Key_O: // ´ Key_Dead_Grave -#endif wasmKey = find(graveKeyTable, accentBaseKey); break; case Qt::Key_E: // ´ Key_Dead_Acute @@ -854,9 +860,6 @@ Qt::Key QWasmEventTranslator::translateDeadKey(Qt::Key deadKey, Qt::Key accentBa case Qt::Key_N:// Key_Dead_Tilde wasmKey = find(tildeKeyTable, accentBaseKey); break; -#ifndef Q_OS_MACOS - case Qt::Key_QuoteLeft: -#endif case Qt::Key_U:// ¨ Key_Dead_Diaeresis wasmKey = find(diaeresisKeyTable, accentBaseKey); break;