diff options
author | Drashna Jaelre <drashna@live.com> | 2018-10-01 17:56:04 -0700 |
---|---|---|
committer | Jack Humbert <jack.humb@gmail.com> | 2018-10-01 20:56:04 -0400 |
commit | f5ae3760c6be7e927fba74aca4a0cf21a44113af (patch) | |
tree | 9c74968b67556649ab89d95e4387f3796a43309a /quantum/process_keycode | |
parent | 26f4e7031a643ce2760ae7b6df3bd2c79710451a (diff) | |
download | qmk_firmware-f5ae3760c6be7e927fba74aca4a0cf21a44113af.tar.gz qmk_firmware-f5ae3760c6be7e927fba74aca4a0cf21a44113af.zip |
Add send_unicode_hex_string function (#3828)
* Add send_string_unicode function
Co-authored-by: kdb424 <kdb424@gmail.com>
Co-authored-by: Konstantin <vomindoraan@gmail.com>
* Clean up code based on feedback
* Fix includes
Diffstat (limited to 'quantum/process_keycode')
-rw-r--r-- | quantum/process_keycode/process_unicode_common.c | 28 | ||||
-rw-r--r-- | quantum/process_keycode/process_unicode_common.h | 1 |
2 files changed, 29 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 7f34ad57c..e6620b7ea 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c | |||
@@ -16,6 +16,8 @@ | |||
16 | 16 | ||
17 | #include "process_unicode_common.h" | 17 | #include "process_unicode_common.h" |
18 | #include "eeprom.h" | 18 | #include "eeprom.h" |
19 | #include <string.h> | ||
20 | #include <ctype.h> | ||
19 | 21 | ||
20 | static uint8_t input_mode; | 22 | static uint8_t input_mode; |
21 | uint8_t mods; | 23 | uint8_t mods; |
@@ -120,3 +122,29 @@ void register_hex(uint16_t hex) { | |||
120 | unregister_code(hex_to_keycode(digit)); | 122 | unregister_code(hex_to_keycode(digit)); |
121 | } | 123 | } |
122 | } | 124 | } |
125 | |||
126 | void send_unicode_hex_string(const char *str) | ||
127 | { | ||
128 | if (!str) { return; } // Safety net | ||
129 | |||
130 | while (*str) { | ||
131 | // Find the next code point (token) in the string | ||
132 | for (; *str == ' '; str++); | ||
133 | size_t n = strcspn(str, " "); // Length of the current token | ||
134 | char code_point[n+1]; | ||
135 | strncpy(code_point, str, n); | ||
136 | code_point[n] = '\0'; // Make sure it's null-terminated | ||
137 | |||
138 | // Normalize the code point: make all hex digits lowercase | ||
139 | for (char *p = code_point; *p; p++) { | ||
140 | *p = tolower((unsigned char)*p); | ||
141 | } | ||
142 | |||
143 | // Send the code point as a Unicode input string | ||
144 | unicode_input_start(); | ||
145 | send_string(code_point); | ||
146 | unicode_input_finish(); | ||
147 | |||
148 | str += n; // Move to the first ' ' (or '\0') after the current token | ||
149 | } | ||
150 | } | ||
diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 4d2b04fb3..814b60c57 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h | |||
@@ -31,6 +31,7 @@ uint8_t get_unicode_input_mode(void); | |||
31 | void unicode_input_start(void); | 31 | void unicode_input_start(void); |
32 | void unicode_input_finish(void); | 32 | void unicode_input_finish(void); |
33 | void register_hex(uint16_t hex); | 33 | void register_hex(uint16_t hex); |
34 | void send_unicode_hex_string(const char *str); | ||
34 | 35 | ||
35 | #define UC_OSX 0 // Mac OS X | 36 | #define UC_OSX 0 // Mac OS X |
36 | #define UC_LNX 1 // Linux | 37 | #define UC_LNX 1 // Linux |