From 96b5c4ee0353effa7947dec1dfc2f1bf36940226 Mon Sep 17 00:00:00 2001 From: Josh Klar Date: Sun, 30 Sep 2018 20:49:40 -0700 Subject: [PATCH] Ensure we always send at least four characters when sending Unicode sequences to better support MacOS/Windows --- kmk/common/macros/unicode.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/kmk/common/macros/unicode.py b/kmk/common/macros/unicode.py index 11c465f..ad2cd77 100644 --- a/kmk/common/macros/unicode.py +++ b/kmk/common/macros/unicode.py @@ -9,10 +9,20 @@ IBUS_KEY_COMBO = Modifiers.KC_LCTRL(Modifiers.KC_LSHIFT(Common.KC_U)) def generate_codepoint_keysym_seq(codepoint): - return [ - getattr(Common, 'KC_{}'.format(codepoint_fragment.upper())) - for codepoint_fragment in codepoint - ] + # To make MacOS and Windows happy, always try to send + # sequences that are of length 4 at a minimum + # On Linux systems, we can happily send longer strings. + # They will almost certainly break on MacOS and Windows, + # but this is a documentation problem more than anything. + # Not sure how to send emojis on Mac/Windows like that, + # though, since (for example) the Canadian flag is assembled + # from two five-character codepoints, 1f1e8 and 1f1e6 + seq = [Common.KC_0 for _ in range(max(len(codepoint), 4))] + + for idx, codepoint_fragment in enumerate(reversed(codepoint)): + seq[-(idx + 1)] = getattr(Common, 'KC_{}'.format(codepoint_fragment.upper())) + + return seq def unicode_sequence(codepoints):