aboutsummaryrefslogtreecommitdiff
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 fb5021501..bea34c31e 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) {
171 } 171 }
172} 172}
173 173
174void register_unicode(uint32_t code_point) {
175 if (code_point > 0x10FFFF || (code_point > 0xFFFF && unicode_config.input_mode == UC_WIN)) {
176 // Code point out of range, do nothing
177 return;
178 }
179
180 unicode_input_start();
181 if (code_point > 0xFFFF && unicode_config.input_mode == UC_MAC) {
182 // Convert code point to UTF-16 surrogate pair on macOS
183 code_point -= 0x10000;
184 uint32_t lo = code_point & 0x3FF, hi = (code_point & 0xFFC00) >> 10;
185 register_hex32(hi + 0xD800);
186 register_hex32(lo + 0xDC00);
187 } else {
188 register_hex32(code_point);
189 }
190 unicode_input_finish();
191}
192
174// clang-format off 193// clang-format off
175 194
176void send_unicode_hex_string(const char *str) { 195void send_unicode_hex_string(const char *str) {
@@ -236,14 +255,12 @@ void send_unicode_string(const char *str) {
236 return; 255 return;
237 } 256 }
238 257
239 int32_t code_point = 0;
240 while (*str) { 258 while (*str) {
259 int32_t code_point = 0;
241 str = decode_utf8(str, &code_point); 260 str = decode_utf8(str, &code_point);
242 261
243 if (code_point >= 0) { 262 if (code_point >= 0) {
244 unicode_input_start(); 263 register_unicode(code_point);
245 register_hex32(code_point);
246 unicode_input_finish();
247 } 264 }
248 } 265 }
249} 266}