aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/feature_unicode.md3
-rw-r--r--quantum/process_keycode/process_unicode_common.c24
-rw-r--r--quantum/process_keycode/process_unicode_common.h1
-rw-r--r--quantum/process_keycode/process_unicodemap.c20
-rw-r--r--quantum/process_keycode/process_unicodemap.h1
5 files changed, 22 insertions, 27 deletions
diff --git a/docs/feature_unicode.md b/docs/feature_unicode.md
index 546af2521..697541458 100644
--- a/docs/feature_unicode.md
+++ b/docs/feature_unicode.md
@@ -195,7 +195,7 @@ By default, when the keyboard boots, it will initialize the input mode to the la
195 195
196## `send_unicode_string()` 196## `send_unicode_string()`
197 197
198This function is much like `send_string()` but allows you to input UTF-8 characters directly, currently up to code point U+FFFF. Make sure your `keymap.c` is formatted in UTF-8 encoding. 198This function is much like `send_string()` but allows you to input UTF-8 characters directly, and supports all code points (provided the selected input method also supports it). Make sure your `keymap.c` is formatted in UTF-8 encoding.
199 199
200```c 200```c
201send_unicode_string("(ノಠ痊ಠ)ノ彡┻━┻"); 201send_unicode_string("(ノಠ痊ಠ)ノ彡┻━┻");
@@ -210,7 +210,6 @@ send_unicode_hex_string("0028 30CE 0CA0 75CA 0CA0 0029 30CE 5F61 253B 2501 253B"
210``` 210```
211 211
212An easy way to convert your Unicode string to this format is by using [this site](https://r12a.github.io/app-conversion/), and taking the result in the "Hex/UTF-32" section. 212An easy way to convert your Unicode string to this format is by using [this site](https://r12a.github.io/app-conversion/), and taking the result in the "Hex/UTF-32" section.
213Unlike `send_unicode_string()` this function supports code points up to U+10FFFF.
214 213
215## Additional Language Support 214## Additional Language Support
216 215
diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c
index 4ac305e66..fc392813a 100644
--- a/quantum/process_keycode/process_unicode_common.c
+++ b/quantum/process_keycode/process_unicode_common.c
@@ -150,6 +150,24 @@ void register_hex(uint16_t hex) {
150 } 150 }
151} 151}
152 152
153void register_hex32(uint32_t hex) {
154 bool onzerostart = true;
155 for (int i = 7; i >= 0; i--) {
156 if (i <= 3) {
157 onzerostart = false;
158 }
159 uint8_t digit = ((hex >> (i * 4)) & 0xF);
160 if (digit == 0) {
161 if (!onzerostart) {
162 tap_code(hex_to_keycode(digit));
163 }
164 } else {
165 tap_code(hex_to_keycode(digit));
166 onzerostart = false;
167 }
168 }
169}
170
153void send_unicode_hex_string(const char *str) { 171void send_unicode_hex_string(const char *str) {
154 if (!str) { 172 if (!str) {
155 return; 173 return;
@@ -192,9 +210,7 @@ const char *decode_utf8(const char *str, int32_t *code_point) {
192 *code_point = ((int32_t)(str[0] & 0x0F) << 12) | ((int32_t)(str[1] & 0x3F) << 6) | ((int32_t)(str[2] & 0x3F) << 0); 210 *code_point = ((int32_t)(str[0] & 0x0F) << 12) | ((int32_t)(str[1] & 0x3F) << 6) | ((int32_t)(str[2] & 0x3F) << 0);
193 next = str + 3; 211 next = str + 3;
194 } else if ((str[0] & 0xF8) == 0xF0 && (str[0] <= 0xF4)) { // U+10000-10FFFF 212 } else if ((str[0] & 0xF8) == 0xF0 && (str[0] <= 0xF4)) { // U+10000-10FFFF
195 // Skip for now - register_hex() only takes a uint16 213 *code_point = ((int32_t)(str[0] & 0x07) << 18) | ((int32_t)(str[1] & 0x3F) << 12) | ((int32_t)(str[2] & 0x3F) << 6) | ((int32_t)(str[3] & 0x3F) << 0);
196 //*code_point = ((int32_t)(str[0] & 0x07) << 18) | ((int32_t)(str[1] & 0x3F) << 12) | ((int32_t)(str[2] & 0x3F) << 6) | ((int32_t)(str[3] & 0x3F) << 0);
197 *code_point = -1;
198 next = str + 4; 214 next = str + 4;
199 } else { 215 } else {
200 *code_point = -1; 216 *code_point = -1;
@@ -221,7 +237,7 @@ void send_unicode_string(const char *str) {
221 237
222 if (code_point >= 0) { 238 if (code_point >= 0) {
223 unicode_input_start(); 239 unicode_input_start();
224 register_hex(code_point); 240 register_hex32(code_point);
225 unicode_input_finish(); 241 unicode_input_finish();
226 } 242 }
227 } 243 }
diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h
index 393db2d99..13b6431bf 100644
--- a/quantum/process_keycode/process_unicode_common.h
+++ b/quantum/process_keycode/process_unicode_common.h
@@ -79,6 +79,7 @@ void unicode_input_finish(void);
79void unicode_input_cancel(void); 79void unicode_input_cancel(void);
80 80
81void register_hex(uint16_t hex); 81void register_hex(uint16_t hex);
82void register_hex32(uint32_t hex);
82void send_unicode_hex_string(const char *str); 83void send_unicode_hex_string(const char *str);
83void send_unicode_string(const char *str); 84void send_unicode_string(const char *str);
84 85
diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c
index 4364f156c..1be51a995 100644
--- a/quantum/process_keycode/process_unicodemap.c
+++ b/quantum/process_keycode/process_unicodemap.c
@@ -16,26 +16,6 @@
16 16
17#include "process_unicodemap.h" 17#include "process_unicodemap.h"
18 18
19void register_hex32(uint32_t hex) {
20 bool onzerostart = true;
21 for (int i = 7; i >= 0; i--) {
22 if (i <= 3) {
23 onzerostart = false;
24 }
25 uint8_t digit = ((hex >> (i * 4)) & 0xF);
26 if (digit == 0) {
27 if (!onzerostart) {
28 register_code(hex_to_keycode(digit));
29 unregister_code(hex_to_keycode(digit));
30 }
31 } else {
32 register_code(hex_to_keycode(digit));
33 unregister_code(hex_to_keycode(digit));
34 onzerostart = false;
35 }
36 }
37}
38
39__attribute__((weak)) uint16_t unicodemap_index(uint16_t keycode) { 19__attribute__((weak)) uint16_t unicodemap_index(uint16_t keycode) {
40 if (keycode >= QK_UNICODEMAP_PAIR) { 20 if (keycode >= QK_UNICODEMAP_PAIR) {
41 // Keycode is a pair: extract index based on Shift / Caps Lock state 21 // Keycode is a pair: extract index based on Shift / Caps Lock state
diff --git a/quantum/process_keycode/process_unicodemap.h b/quantum/process_keycode/process_unicodemap.h
index a4b6d77f3..c429859bb 100644
--- a/quantum/process_keycode/process_unicodemap.h
+++ b/quantum/process_keycode/process_unicodemap.h
@@ -20,6 +20,5 @@
20 20
21extern const uint32_t PROGMEM unicode_map[]; 21extern const uint32_t PROGMEM unicode_map[];
22 22
23void register_hex32(uint32_t hex);
24uint16_t unicodemap_index(uint16_t keycode); 23uint16_t unicodemap_index(uint16_t keycode);
25bool process_unicodemap(uint16_t keycode, keyrecord_t *record); 24bool process_unicodemap(uint16_t keycode, keyrecord_t *record);