aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode/process_unicodemap.c
diff options
context:
space:
mode:
authorKonstantin Đorđević <vomindoraan@gmail.com>2019-01-07 21:56:57 +0100
committerDrashna Jaelre <drashna@live.com>2019-01-07 12:56:57 -0800
commitcd9262d7b2dcde5d31aa34f066dd593a012d7049 (patch)
treebb9cda36efc39af997e019af4f6a91f451d12807 /quantum/process_keycode/process_unicodemap.c
parent6e984a8b5e34ba181b0893a929af569a1faef2b6 (diff)
downloadqmk_firmware-cd9262d7b2dcde5d31aa34f066dd593a012d7049.tar.gz
qmk_firmware-cd9262d7b2dcde5d31aa34f066dd593a012d7049.zip
Improve consistency in UNICODEMAP code and docs, update docs/understanding_qmk (#4774)
* Remove unused UNICODE(n) macro, update docs * Add note about max length of unicode_map to docs * QK_UNICODE_MAP → QK_UNICODEMAP * Refactor process_unicode_map * process_unicode_map → process_unicodemap This is done for consistency: UNICODEMAP is the method (hence UNICODEMAP_ENABLE, process_unicodemap), whereas unicode_map is the mapping table itself. * Update references and ordering in docs/understanding_qmk * Add additional note to docs/understanding_qmk * &unicode_map[index] → unicode_map + index This avoids the issue of the compiler sometimes complaining about the array index being out of range * Update docs/getting_started_make_guide * Update method sections in docs/feature_unicode
Diffstat (limited to 'quantum/process_keycode/process_unicodemap.c')
-rw-r--r--quantum/process_keycode/process_unicodemap.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c
index 75f35112b..cee9acb5f 100644
--- a/quantum/process_keycode/process_unicodemap.c
+++ b/quantum/process_keycode/process_unicodemap.c
@@ -18,8 +18,7 @@
18#include "process_unicode_common.h" 18#include "process_unicode_common.h"
19 19
20__attribute__((weak)) 20__attribute__((weak))
21const uint32_t PROGMEM unicode_map[] = { 21const uint32_t PROGMEM unicode_map[] = {};
22};
23 22
24void register_hex32(uint32_t hex) { 23void register_hex32(uint32_t hex) {
25 bool onzerostart = true; 24 bool onzerostart = true;
@@ -42,26 +41,26 @@ void register_hex32(uint32_t hex) {
42} 41}
43 42
44__attribute__((weak)) 43__attribute__((weak))
45void unicode_map_input_error() {} 44void unicodemap_input_error() {}
46 45
47bool process_unicode_map(uint16_t keycode, keyrecord_t *record) { 46bool process_unicodemap(uint16_t keycode, keyrecord_t *record) {
48 uint8_t input_mode = get_unicode_input_mode(); 47 if ((keycode & QK_UNICODEMAP) == QK_UNICODEMAP && record->event.pressed) {
49 if ((keycode & QK_UNICODE_MAP) == QK_UNICODE_MAP && record->event.pressed) { 48 uint16_t index = keycode - QK_UNICODEMAP;
50 const uint32_t* map = unicode_map; 49 uint32_t code = pgm_read_dword(unicode_map + index);
51 uint16_t index = keycode - QK_UNICODE_MAP; 50 uint8_t input_mode = get_unicode_input_mode();
52 uint32_t code = pgm_read_dword(&map[index]); 51
53 if (code > 0xFFFF && code <= 0x10ffff && input_mode == UC_OSX) { 52 if (code > 0xFFFF && code <= 0x10FFFF && input_mode == UC_OSX) {
54 // Convert to UTF-16 surrogate pair 53 // Convert to UTF-16 surrogate pair
55 code -= 0x10000; 54 code -= 0x10000;
56 uint32_t lo = code & 0x3ff; 55 uint32_t lo = code & 0x3FF, hi = (code & 0xFFC00) >> 10;
57 uint32_t hi = (code & 0xffc00) >> 10; 56
58 unicode_input_start(); 57 unicode_input_start();
59 register_hex32(hi + 0xd800); 58 register_hex32(hi + 0xD800);
60 register_hex32(lo + 0xdc00); 59 register_hex32(lo + 0xDC00);
61 unicode_input_finish(); 60 unicode_input_finish();
62 } else if ((code > 0x10ffff && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) { 61 } else if ((code > 0x10FFFF && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) {
63 // when character is out of range supported by the OS 62 // Character is out of range supported by the OS
64 unicode_map_input_error(); 63 unicodemap_input_error();
65 } else { 64 } else {
66 unicode_input_start(); 65 unicode_input_start();
67 register_hex32(code); 66 register_hex32(code);