This commit is contained in:
shenleban tongying 2024-11-12 06:31:24 -05:00
parent e01c39c4fc
commit d4a49fbf79

View file

@ -51,15 +51,15 @@ void createMapping()
return; return;
} }
CFDataRef dataRef = (CFDataRef)TISGetInputSourceProperty(inputSourceRef, kTISPropertyUnicodeKeyLayoutData); CFDataRef uchrDataRef = (CFDataRef)TISGetInputSourceProperty(inputSourceRef, kTISPropertyUnicodeKeyLayoutData);
const UCKeyboardLayout* keyboardLayoutPtr; const UCKeyboardLayout* UCkeyboardLayoutPtr;
if (dataRef) { if (uchrDataRef) {
keyboardLayoutPtr = (const UCKeyboardLayout*)CFDataGetBytePtr(dataRef); UCkeyboardLayoutPtr = (const UCKeyboardLayout*)CFDataGetBytePtr(uchrDataRef);
} }
if (!keyboardLayoutPtr) { if (!UCkeyboardLayoutPtr) {
return; return;
} }
@ -67,16 +67,17 @@ void createMapping()
UInt32 theDeadKeyState = 0; UInt32 theDeadKeyState = 0;
UniCharCount theLength = 0; UniCharCount theLength = 0;
UniChar temp_char_buf; UniChar temp_char_buf;
if (UCKeyTranslate(keyboardLayoutPtr, i, kUCKeyActionDown, 0, LMGetKbdType(), if (UCKeyTranslate(UCkeyboardLayoutPtr, i, kUCKeyActionDown, 0, LMGetKbdType(),
kUCKeyTranslateNoDeadKeysBit, &theDeadKeyState, 1, &theLength, kUCKeyTranslateNoDeadKeysBit, &theDeadKeyState, 1, &theLength,
&temp_char_buf) &temp_char_buf)
== noErr == noErr
&& theLength > 0) { && theLength > 0) {
if (isprint(temp_char_buf)) { if (isprint(temp_char_buf)) {
mapping.emplace_back(ReverseMapEntry { temp_char, i }); mapping.emplace_back(ReverseMapEntry { temp_char_buf, i });
} }
} }
} }
mapping.shrink_to_fit();
} }
} }