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
committerDrashna Jael're <drashna@live.com>2020-08-08 21:08:28 -0700
commitbbc30127f9e051af7b2903766bfcc53b84bf0d5c (patch)
treef3aedb26753dc97d54175f0c2b55fcbf8db160d9 /quantum/process_keycode/process_unicode_common.c
parent15cc75be6f5657e089dbc2c534826405eef792e0 (diff)
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);
}
}
}