diff options
Diffstat (limited to 'quantum/process_keycode/process_unicode_common.c')
| -rw-r--r-- | quantum/process_keycode/process_unicode_common.c | 25 |
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 | ||
| 174 | void 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 | ||
| 176 | void send_unicode_hex_string(const char *str) { | 195 | void 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 | } |
