wasm: fix handling on int dead keys on mac
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 <morten.sorvig@qt.io>
This commit is contained in:
parent
4ed01f5d23
commit
f1638edf45
@ -305,7 +305,7 @@ static constexpr const auto DeadKeyShiftTbl = qMakeArray(
|
|||||||
|
|
||||||
// macOS CTRL <-> META switching. We most likely want to enable
|
// macOS CTRL <-> META switching. We most likely want to enable
|
||||||
// the existing switching code in QtGui, but for now do it here.
|
// 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
|
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"]
|
Platform platform = Platform(emscripten::val::global("navigator")["platform"]
|
||||||
.call<bool>("includes", emscripten::val("Mac")));
|
.call<bool>("includes", emscripten::val("Mac")));
|
||||||
g_usePlatformMacCtrlMetaSwitching = (platform == MacOSPlatform);
|
g_usePlatformMacSpecifics = (platform == MacOSPlatform);
|
||||||
|
|
||||||
if (platform == MacOSPlatform) {
|
if (platform == MacOSPlatform) {
|
||||||
g_useNaturalScrolling = false; // make this !default on macOS
|
g_useNaturalScrolling = false; // make this !default on macOS
|
||||||
@ -385,7 +385,7 @@ QFlags<Qt::KeyboardModifier> QWasmEventTranslator::translatKeyModifier(const Eve
|
|||||||
if (event->shiftKey)
|
if (event->shiftKey)
|
||||||
keyModifier |= Qt::ShiftModifier;
|
keyModifier |= Qt::ShiftModifier;
|
||||||
if (event->ctrlKey) {
|
if (event->ctrlKey) {
|
||||||
if (g_usePlatformMacCtrlMetaSwitching)
|
if (g_usePlatformMacSpecifics)
|
||||||
keyModifier |= Qt::MetaModifier;
|
keyModifier |= Qt::MetaModifier;
|
||||||
else
|
else
|
||||||
keyModifier |= Qt::ControlModifier;
|
keyModifier |= Qt::ControlModifier;
|
||||||
@ -393,7 +393,7 @@ QFlags<Qt::KeyboardModifier> QWasmEventTranslator::translatKeyModifier(const Eve
|
|||||||
if (event->altKey)
|
if (event->altKey)
|
||||||
keyModifier |= Qt::AltModifier;
|
keyModifier |= Qt::AltModifier;
|
||||||
if (event->metaKey) {
|
if (event->metaKey) {
|
||||||
if (g_usePlatformMacCtrlMetaSwitching)
|
if (g_usePlatformMacSpecifics)
|
||||||
keyModifier |= Qt::ControlModifier;
|
keyModifier |= Qt::ControlModifier;
|
||||||
else
|
else
|
||||||
keyModifier |= Qt::MetaModifier;
|
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 ||
|
} else if (qstrncmp(emscriptKey->code, "Key", 3) == 0 || qstrncmp(emscriptKey->code, "Numpad", 6) == 0 ||
|
||||||
qstrncmp(emscriptKey->code, "Digit", 5) == 0) {
|
qstrncmp(emscriptKey->code, "Digit", 5) == 0) {
|
||||||
|
|
||||||
emkb2qt_t searchKey{emscriptKey->code, 0}; // search emcsripten code
|
emkb2qt_t searchKey{emscriptKey->code, 0}; // search emcsripten code
|
||||||
auto it1 = std::lower_bound(KeyTbl.cbegin(), KeyTbl.cend(), searchKey);
|
auto it1 = std::lower_bound(KeyTbl.cbegin(), KeyTbl.cend(), searchKey);
|
||||||
if (it1 != KeyTbl.end() && !(searchKey < *it1)) {
|
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 QWasmEventTranslator::translateDeadKey(Qt::Key deadKey, Qt::Key accentBaseKey)
|
||||||
{
|
{
|
||||||
Qt::Key wasmKey = Qt::Key_unknown;
|
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) {
|
switch (deadKey) {
|
||||||
#ifdef Q_OS_MACOS
|
// case Qt::Key_QuoteLeft:
|
||||||
case Qt::Key_QuoteLeft: // ` macOS: Key_Dead_Grave
|
|
||||||
#else
|
|
||||||
case Qt::Key_O: // ´ Key_Dead_Grave
|
case Qt::Key_O: // ´ Key_Dead_Grave
|
||||||
#endif
|
|
||||||
wasmKey = find(graveKeyTable, accentBaseKey);
|
wasmKey = find(graveKeyTable, accentBaseKey);
|
||||||
break;
|
break;
|
||||||
case Qt::Key_E: // ´ Key_Dead_Acute
|
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
|
case Qt::Key_N:// Key_Dead_Tilde
|
||||||
wasmKey = find(tildeKeyTable, accentBaseKey);
|
wasmKey = find(tildeKeyTable, accentBaseKey);
|
||||||
break;
|
break;
|
||||||
#ifndef Q_OS_MACOS
|
|
||||||
case Qt::Key_QuoteLeft:
|
|
||||||
#endif
|
|
||||||
case Qt::Key_U:// ¨ Key_Dead_Diaeresis
|
case Qt::Key_U:// ¨ Key_Dead_Diaeresis
|
||||||
wasmKey = find(diaeresisKeyTable, accentBaseKey);
|
wasmKey = find(diaeresisKeyTable, accentBaseKey);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user