Compare commits

...

3 commits

Author SHA1 Message Date
shenleban tongying 659bf38bda decorations 2024-11-12 07:23:44 -05:00
shenleban tongying 8720a1a183 comment 2024-11-12 07:13:32 -05:00
shenleban tongying 384dcfbc36 proper typing of char16_t 2024-11-12 06:59:25 -05:00

View file

@ -33,14 +33,13 @@ struct ReverseMapEntry {
UInt16 keyCode; UInt16 keyCode;
}; };
std::vector<ReverseMapEntry> mapping; static std::vector<ReverseMapEntry> mapping;
/// References: /// References:
/// * https://github.com/libsdl-org/SDL/blob/fc12cc6dfd859a4e01376162a58f12208e539ac6/src/video/cocoa/SDL_cocoakeyboard.m#L345 /// * https://github.com/libsdl-org/SDL/blob/fc12cc6dfd859a4e01376162a58f12208e539ac6/src/video/cocoa/SDL_cocoakeyboard.m#L345
/// * https://github.com/qt/qtbase/blob/922369844fcb75386237bca3eef59edd5093f58d/src/gui/platform/darwin/qapplekeymapper.mm#L449 /// * https://github.com/qt/qtbase/blob/922369844fcb75386237bca3eef59edd5093f58d/src/gui/platform/darwin/qapplekeymapper.mm#L449
/// ///
/// Known flaw: /// Known possible flaws 1) UCKeyTranslate doesn't handle modifiers at all 2) Handling keyboard switching
/// * UCKeyTranslate doesn't handle modifiers at all.
void createMapping() void createMapping()
{ {
if (mapping.empty()) { if (mapping.empty()) {
@ -53,13 +52,13 @@ void createMapping()
CFDataRef uchrDataRef = (CFDataRef)TISGetInputSourceProperty(inputSourceRef, kTISPropertyUnicodeKeyLayoutData); CFDataRef uchrDataRef = (CFDataRef)TISGetInputSourceProperty(inputSourceRef, kTISPropertyUnicodeKeyLayoutData);
const UCKeyboardLayout* UCkeyboardLayoutPtr; const UCKeyboardLayout* UCKeyboardLayoutPtr;
if (uchrDataRef) { if (uchrDataRef) {
UCkeyboardLayoutPtr = (const UCKeyboardLayout*)CFDataGetBytePtr(uchrDataRef); UCKeyboardLayoutPtr = (const UCKeyboardLayout*)CFDataGetBytePtr(uchrDataRef);
} }
if (!UCkeyboardLayoutPtr) { if (!UCKeyboardLayoutPtr) {
return; return;
} }
@ -67,7 +66,7 @@ void createMapping()
UInt32 theDeadKeyState = 0; UInt32 theDeadKeyState = 0;
UniCharCount theLength = 0; UniCharCount theLength = 0;
UniChar temp_char_buf; UniChar temp_char_buf;
if (UCKeyTranslate(UCkeyboardLayoutPtr, 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
@ -81,7 +80,7 @@ void createMapping()
} }
} }
quint32 qtKeyToNativeKey(quint32 key) quint32 qtKeyToNativeKey(UniChar key)
{ {
createMapping(); createMapping();
if (mapping.empty()) { if (mapping.empty()) {
@ -341,7 +340,7 @@ quint32 HotkeyWrapper::nativeKey(int key)
return 0x72; return 0x72;
default:; default:;
} }
return MacKeyMapping::qtKeyToNativeKey(QChar(key).toLower().toLatin1()); return MacKeyMapping::qtKeyToNativeKey(QChar(key).toLower().unicode());
} }
void HotkeyWrapper::sendCmdC() void HotkeyWrapper::sendCmdC()