diff --git a/src/plugins/platforms/cocoa/qcocoakeymapper.h b/src/plugins/platforms/cocoa/qcocoakeymapper.h index a75e275077..2624f19978 100644 --- a/src/plugins/platforms/cocoa/qcocoakeymapper.h +++ b/src/plugins/platforms/cocoa/qcocoakeymapper.h @@ -89,15 +89,12 @@ public: void clearMappings(); private: - QCFType currentInputSource; + QCFType currentInputSource = nullptr; - enum { NullMode, UnicodeMode, OtherMode } keyboard_mode; - union { - const UCKeyboardLayout *unicode; - void *other; - } keyboard_layout_format; - KeyboardLayoutKind keyboard_kind; - UInt32 keyboard_dead; + enum { NullMode, UnicodeMode, OtherMode } keyboard_mode = NullMode; + const UCKeyboardLayout *keyboard_layout_format = nullptr; + KeyboardLayoutKind keyboard_kind = kKLKCHRuchrKind; + UInt32 keyboard_dead = 0; KeyboardLayoutItem *keyLayout[256]; }; diff --git a/src/plugins/platforms/cocoa/qcocoakeymapper.mm b/src/plugins/platforms/cocoa/qcocoakeymapper.mm index 5e279a400b..c18b7d6bc0 100644 --- a/src/plugins/platforms/cocoa/qcocoakeymapper.mm +++ b/src/plugins/platforms/cocoa/qcocoakeymapper.mm @@ -341,8 +341,6 @@ static int qt_mac_get_key(int modif, const QChar &key, int virtualKey) QCocoaKeyMapper::QCocoaKeyMapper() { memset(keyLayout, 0, sizeof(keyLayout)); - keyboard_layout_format.unicode = 0; - currentInputSource = 0; } QCocoaKeyMapper::~QCocoaKeyMapper() @@ -371,8 +369,11 @@ bool QCocoaKeyMapper::updateKeyboard() keyboard_kind = LMGetKbdType(); if (uchrData) { - keyboard_layout_format.unicode = uchrData; + keyboard_layout_format = uchrData; keyboard_mode = UnicodeMode; + } else { + keyboard_layout_format = nullptr; + keyboard_mode = NullMode; } currentInputSource = source; keyboard_dead = 0; @@ -414,7 +415,7 @@ void QCocoaKeyMapper::updateKeyMap(unsigned short macVirtualKey, QChar unicodeKe keyLayout[macVirtualKey]->qtKey[i] = 0; const UInt32 keyModifier = ((qt_mac_get_mac_modifiers(ModsTbl[i]) >> 8) & 0xFF); - OSStatus err = UCKeyTranslate(keyboard_layout_format.unicode, macVirtualKey, kUCKeyActionDown, keyModifier, + OSStatus err = UCKeyTranslate(keyboard_layout_format, macVirtualKey, kUCKeyActionDown, keyModifier, keyboard_kind, 0, &keyboard_dead, buffer_size, &out_buffer_size, buffer); if (err == noErr && out_buffer_size) { const QChar unicode(buffer[0]);