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;
};
std::vector<ReverseMapEntry> mapping;
static std::vector<ReverseMapEntry> mapping;
/// References:
/// * 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
///
/// Known flaw:
/// * UCKeyTranslate doesn't handle modifiers at all.
/// Known possible flaws 1) UCKeyTranslate doesn't handle modifiers at all 2) Handling keyboard switching
void createMapping()
{
if (mapping.empty()) {
@ -53,13 +52,13 @@ void createMapping()
CFDataRef uchrDataRef = (CFDataRef)TISGetInputSourceProperty(inputSourceRef, kTISPropertyUnicodeKeyLayoutData);
const UCKeyboardLayout* UCkeyboardLayoutPtr;
const UCKeyboardLayout* UCKeyboardLayoutPtr;
if (uchrDataRef) {
UCkeyboardLayoutPtr = (const UCKeyboardLayout*)CFDataGetBytePtr(uchrDataRef);
UCKeyboardLayoutPtr = (const UCKeyboardLayout*)CFDataGetBytePtr(uchrDataRef);
}
if (!UCkeyboardLayoutPtr) {
if (!UCKeyboardLayoutPtr) {
return;
}
@ -67,7 +66,7 @@ void createMapping()
UInt32 theDeadKeyState = 0;
UniCharCount theLength = 0;
UniChar temp_char_buf;
if (UCKeyTranslate(UCkeyboardLayoutPtr, i, kUCKeyActionDown, 0, LMGetKbdType(),
if (UCKeyTranslate(UCKeyboardLayoutPtr, i, kUCKeyActionDown, 0, LMGetKbdType(),
kUCKeyTranslateNoDeadKeysBit, &theDeadKeyState, 1, &theLength,
&temp_char_buf)
== noErr
@ -81,7 +80,7 @@ void createMapping()
}
}
quint32 qtKeyToNativeKey(quint32 key)
quint32 qtKeyToNativeKey(UniChar key)
{
createMapping();
if (mapping.empty()) {
@ -341,7 +340,7 @@ quint32 HotkeyWrapper::nativeKey(int key)
return 0x72;
default:;
}
return MacKeyMapping::qtKeyToNativeKey(QChar(key).toLower().toLatin1());
return MacKeyMapping::qtKeyToNativeKey(QChar(key).toLower().unicode());
}
void HotkeyWrapper::sendCmdC()