summaryrefslogtreecommitdiff
path: root/quantum/process_keycode/process_unicode_common.c
diff options
context:
space:
mode:
authorJason Laqua <jlaqua118@gmail.com>2020-06-18 02:07:34 -0500
committerGitHub <noreply@github.com>2020-06-18 08:07:34 +0100
commitf7eb030e917a8fa360ad7cc7bb26d804cf4c5f6c (patch)
tree8415ddb70ed9fa1cfea2651a6ef950483648d851 /quantum/process_keycode/process_unicode_common.c
parentaae1814319c4992471d074ed18b8b7b4842b0a66 (diff)
downloadqmk_firmware-f7eb030e917a8fa360ad7cc7bb26d804cf4c5f6c.tar.gz
qmk_firmware-f7eb030e917a8fa360ad7cc7bb26d804cf4c5f6c.zip
Standardize how unicode is processed (fixes #8768) (#8770)
Co-authored-by: Konstantin Đorđević <vomindoraan@gmail.com>
Diffstat (limited to 'quantum/process_keycode/process_unicode_common.c')
-rw-r--r--quantum/process_keycode/process_unicode_common.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c
index fb50215012..bea34c31ea 100644
--- a/quantum/process_keycode/process_unicode_common.c
+++ b/quantum/process_keycode/process_unicode_common.c
@@ -171,6 +171,25 @@ void register_hex32(uint32_t hex) {
}
}
+void register_unicode(uint32_t code_point) {
+ if (code_point > 0x10FFFF || (code_point > 0xFFFF && unicode_config.input_mode == UC_WIN)) {
+ // Code point out of range, do nothing
+ return;
+ }
+
+ unicode_input_start();
+ if (code_point > 0xFFFF && unicode_config.input_mode == UC_MAC) {
+ // Convert code point to UTF-16 surrogate pair on macOS
+ code_point -= 0x10000;
+ uint32_t lo = code_point & 0x3FF, hi = (code_point & 0xFFC00) >> 10;
+ register_hex32(hi + 0xD800);
+ register_hex32(lo + 0xDC00);
+ } else {
+ register_hex32(code_point);
+ }
+ unicode_input_finish();
+}
+
// clang-format off
void send_unicode_hex_string(const char *str) {
@@ -236,14 +255,12 @@ void send_unicode_string(const char *str) {
return;
}
- int32_t code_point = 0;
while (*str) {
+ int32_t code_point = 0;
str = decode_utf8(str, &code_point);
if (code_point >= 0) {
- unicode_input_start();
- register_hex32(code_point);
- unicode_input_finish();
+ register_unicode(code_point);
}
}
}