QCocoaKeyMapper: Properly initialize all members and reset on update

Previously some of the members would have random initial values. Also,
on updateKeyboard() if we don't find usable uchrData, we should just
reset keyboard_layout_format and keyboard_mode, rather than keep the
previous values.

Task-number: QTBUG-50865
Change-Id: I1297fa55bb1593dd549d0bc122713d5d98f7b1fc
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Ulf Hermann 2018-09-27 16:00:55 +02:00
parent 21355b3630
commit 28c831fa13
2 changed files with 10 additions and 12 deletions

View File

@ -89,15 +89,12 @@ public:
void clearMappings();
private:
QCFType<TISInputSourceRef> currentInputSource;
QCFType<TISInputSourceRef> 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];
};

View File

@ -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]);