aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode/process_unicodemap.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/process_keycode/process_unicodemap.c')
-rw-r--r--quantum/process_keycode/process_unicodemap.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c
new file mode 100644
index 000000000..68a593a18
--- /dev/null
+++ b/quantum/process_keycode/process_unicodemap.c
@@ -0,0 +1,56 @@
1#include "process_unicodemap.h"
2#include "process_unicode_common.h"
3
4__attribute__((weak))
5const uint32_t PROGMEM unicode_map[] = {
6};
7
8void register_hex32(uint32_t hex) {
9 bool onzerostart = true;
10 for(int i = 7; i >= 0; i--) {
11 if (i <= 3) {
12 onzerostart = false;
13 }
14 uint8_t digit = ((hex >> (i*4)) & 0xF);
15 if (digit == 0) {
16 if (!onzerostart) {
17 register_code(hex_to_keycode(digit));
18 unregister_code(hex_to_keycode(digit));
19 }
20 } else {
21 register_code(hex_to_keycode(digit));
22 unregister_code(hex_to_keycode(digit));
23 onzerostart = false;
24 }
25 }
26}
27
28__attribute__((weak))
29void unicode_map_input_error() {}
30
31bool process_unicode_map(uint16_t keycode, keyrecord_t *record) {
32 uint8_t input_mode = get_unicode_input_mode();
33 if ((keycode & QK_UNICODE_MAP) == QK_UNICODE_MAP && record->event.pressed) {
34 const uint32_t* map = unicode_map;
35 uint16_t index = keycode - QK_UNICODE_MAP;
36 uint32_t code = pgm_read_dword_far(&map[index]);
37 if (code > 0xFFFF && code <= 0x10ffff && input_mode == UC_OSX) {
38 // Convert to UTF-16 surrogate pair
39 code -= 0x10000;
40 uint32_t lo = code & 0x3ff;
41 uint32_t hi = (code & 0xffc00) >> 10;
42 unicode_input_start();
43 register_hex32(hi + 0xd800);
44 register_hex32(lo + 0xdc00);
45 unicode_input_finish();
46 } else if ((code > 0x10ffff && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) {
47 // when character is out of range supported by the OS
48 unicode_map_input_error();
49 } else {
50 unicode_input_start();
51 register_hex32(code);
52 unicode_input_finish();
53 }
54 }
55 return true;
56} \ No newline at end of file