summaryrefslogtreecommitdiffstats
path: root/quantum/process_keycode/process_unicode_common.c
diff options
context:
space:
mode:
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);
}
}
}