From 1b83de9b65487d5e89bcaccefc2c22c368ad7a80 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Sun, 8 Dec 2019 17:24:40 +0000 Subject: [PATCH 1/3] fix(developer): Hotkeys in .kmn unquoted Fixes #138. Hotkeys in .kmn files no longer need to be quoted. This update does not change compatibility with earlier versions of Keyman Engine as the difference is entirely in the compiler. --- windows/src/developer/history.md | 1 + windows/src/developer/kmcmpdll/Compiler.cpp | 21 +++++++++++++++++++++ windows/src/developer/kmcmpdll/Compiler.rc | 1 + windows/src/developer/kmcmpdll/kcframe.cpp | 5 ++--- windows/src/global/inc/Comperr.h | 2 ++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/windows/src/developer/history.md b/windows/src/developer/history.md index efd53c26ed..bbb7e00c11 100644 --- a/windows/src/developer/history.md +++ b/windows/src/developer/history.md @@ -3,6 +3,7 @@ ## 13.0 alpha * Start version 13.0 * Feature: Add unsupported kmdecomp decompiler utility (#2419) +* Feature: Hotkeys defined in .kmn no longer need to be quoted (#138) ## 2019-11-18 12.0.55 stable * Bug Fix: Some keyboards were incorrectly marked as mobile-capable (#2334) diff --git a/windows/src/developer/kmcmpdll/Compiler.cpp b/windows/src/developer/kmcmpdll/Compiler.cpp index a4c8623d6b..2d325e3dbf 100644 --- a/windows/src/developer/kmcmpdll/Compiler.cpp +++ b/windows/src/developer/kmcmpdll/Compiler.cpp @@ -2792,6 +2792,8 @@ DWORD ProcessEthnologueStore(PWSTR p) // I2646 return res; } +#define K_HOTKEYSHIFTFLAGS (K_SHIFTFLAG | K_CTRLFLAG | K_ALTFLAG | ISVIRTUALKEY) + DWORD ProcessHotKey(PWSTR p, DWORD *hk) { PWSTR q, r; @@ -2800,6 +2802,25 @@ DWORD ProcessHotKey(PWSTR p, DWORD *hk) *hk = 0; + if(*p == UC_SENTINEL && *(p+1) == CODE_EXTENDED) { + WORD Key = *(p + 3); + WORD ShiftFlags = *(p + 2); + + // Convert virtual key to hotkey (different bitflags) + + if (ShiftFlags & ~K_HOTKEYSHIFTFLAGS) { + AddWarning(CWARN_HotkeyHasInvalidModifier); + } + + if (ShiftFlags & K_SHIFTFLAG) *hk |= HK_SHIFT; + if (ShiftFlags & K_CTRLFLAG) *hk |= HK_SHIFT; + if (ShiftFlags & K_ALTFLAG) *hk |= HK_SHIFT; + + *hk |= Key; + + return CERR_None; + } + q = wcschr(p, '['); if(q) { diff --git a/windows/src/developer/kmcmpdll/Compiler.rc b/windows/src/developer/kmcmpdll/Compiler.rc index 33325d1a84..888c924bac 100644 --- a/windows/src/developer/kmcmpdll/Compiler.rc +++ b/windows/src/developer/kmcmpdll/Compiler.rc @@ -222,5 +222,6 @@ END STRINGTABLE BEGIN CWARN_LanguageHeadersDeprecatedInKeyman10 "This language header has been deprecated in Keyman 10. Instead, add language metadata in the package file" + CWARN_HotkeyHasInvalidModifier "Hotkey has modifiers that are not supported. Use only SHIFT, CTRL and ALT" CINFO_NonUnicodeFile "Keyman Developer has detected that the file has ANSI encoding. Consider converting this file to UTF-8" END diff --git a/windows/src/developer/kmcmpdll/kcframe.cpp b/windows/src/developer/kmcmpdll/kcframe.cpp index 2ec24edc2a..2d41947135 100644 --- a/windows/src/developer/kmcmpdll/kcframe.cpp +++ b/windows/src/developer/kmcmpdll/kcframe.cpp @@ -37,9 +37,8 @@ int main(int argc, char *argv[]) if(argc < 3) { puts("Usage: kcframe infile.kmn outfile.kmx"); - return 0; + return 1; } - CompileKeyboardFile(argv[1], argv[2], TRUE, FALSE, TRUE, msgproc); // I4865 // I4866 - return 1; + return CompileKeyboardFile(argv[1], argv[2], TRUE, FALSE, TRUE, msgproc) ? 0 : 1; // I4865 // I4866 } diff --git a/windows/src/global/inc/Comperr.h b/windows/src/global/inc/Comperr.h index 52bc24c554..b59687e378 100644 --- a/windows/src/global/inc/Comperr.h +++ b/windows/src/global/inc/Comperr.h @@ -189,6 +189,8 @@ #define CWARN_TooManyErrorsOrWarnings 0x000020A7 +#define CWARN_HotkeyHasInvalidModifier 0x000020A8 + #define CERR_BufferOverflow 0x000080C0 #define CERR_Break 0x000080C1 From 50a382d181ea20edea2a69bcac6c25982819523c Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Sun, 8 Dec 2019 17:27:26 +0000 Subject: [PATCH 2/3] chore: typos --- windows/src/developer/kmcmpdll/Compiler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/windows/src/developer/kmcmpdll/Compiler.cpp b/windows/src/developer/kmcmpdll/Compiler.cpp index 2d325e3dbf..d024e160cd 100644 --- a/windows/src/developer/kmcmpdll/Compiler.cpp +++ b/windows/src/developer/kmcmpdll/Compiler.cpp @@ -2813,8 +2813,8 @@ DWORD ProcessHotKey(PWSTR p, DWORD *hk) } if (ShiftFlags & K_SHIFTFLAG) *hk |= HK_SHIFT; - if (ShiftFlags & K_CTRLFLAG) *hk |= HK_SHIFT; - if (ShiftFlags & K_ALTFLAG) *hk |= HK_SHIFT; + if (ShiftFlags & K_CTRLFLAG) *hk |= HK_CTRL; + if (ShiftFlags & K_ALTFLAG) *hk |= HK_ALT; *hk |= Key; From 727059c7bf44536181ac9228b4919f30aa1adcf6 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Sun, 8 Dec 2019 17:37:32 +0000 Subject: [PATCH 3/3] chore: history --- windows/src/developer/history.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/src/developer/history.md b/windows/src/developer/history.md index bbb7e00c11..9a2f116676 100644 --- a/windows/src/developer/history.md +++ b/windows/src/developer/history.md @@ -3,7 +3,7 @@ ## 13.0 alpha * Start version 13.0 * Feature: Add unsupported kmdecomp decompiler utility (#2419) -* Feature: Hotkeys defined in .kmn no longer need to be quoted (#138) +* Feature: Hotkeys defined in .kmn no longer need to be quoted (#2432) ## 2019-11-18 12.0.55 stable * Bug Fix: Some keyboards were incorrectly marked as mobile-capable (#2334)