aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode/process_unicode.c
diff options
context:
space:
mode:
authorGergely Nagy <algernon@madhouse-project.org>2016-08-13 10:46:38 +0200
committerGergely Nagy <algernon@madhouse-project.org>2016-08-15 10:08:53 +0200
commitfa06a163607e8c6c4bd0968c2de96a9a298b777c (patch)
tree47ddc21952c9319163bb74d4d89ac72d5c56a0fe /quantum/process_keycode/process_unicode.c
parent63e5782d2cdf0ee282ad434c773463d9da9db6b3 (diff)
downloadqmk_firmware-fa06a163607e8c6c4bd0968c2de96a9a298b777c.tar.gz
qmk_firmware-fa06a163607e8c6c4bd0968c2de96a9a298b777c.zip
process_unicode: Add a way to enter unicode symbols by name
The purpose of this change is to allow keymaps to specify a dictionary of unicode symbol name to code mappings, and let the person at the keyboard enter unicode symbols by name. This is done by having a way to trigger unicode symbol input mode, when all keys are cached until Esc, Enter or Space are pressed. Once that happens, we try to look up the symbol from our lookup table. If found, we erase back, and type the unicode magic in to get that symbol. If not found, we still erase back, start unicode input mode, and replay what the user typed in. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Diffstat (limited to 'quantum/process_keycode/process_unicode.c')
-rw-r--r--quantum/process_keycode/process_unicode.c93
1 files changed, 92 insertions, 1 deletions
diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c
index 55e47f179..8a6509300 100644
--- a/quantum/process_keycode/process_unicode.c
+++ b/quantum/process_keycode/process_unicode.c
@@ -68,4 +68,95 @@ bool process_unicode(uint16_t keycode, keyrecord_t *record) {
68 unicode_input_finish(); 68 unicode_input_finish();
69 } 69 }
70 return true; 70 return true;
71} \ No newline at end of file 71}
72
73#ifdef UCIS_ENABLE
74void qk_ucis_start(void) {
75 qk_ucis_state.count = 0;
76 qk_ucis_state.in_progress = true;
77
78 unicode_input_start();
79 register_hex(0x2328);
80 unicode_input_finish();
81}
82
83static bool is_uni_seq(char *seq) {
84 uint8_t i;
85
86 for (i = 0; seq[i]; i++) {
87 uint16_t code;
88 if (('1' <= seq[i]) && (seq[i] <= '0'))
89 code = seq[i] - '1' + KC_1;
90 else
91 code = seq[i] - 'a' + KC_A;
92
93 if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != code)
94 return false;
95 }
96
97 return (qk_ucis_state.codes[i] == KC_ENT ||
98 qk_ucis_state.codes[i] == KC_SPC);
99}
100
101__attribute__((weak))
102void qk_ucis_symbol_fallback (void) {
103 for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) {
104 uint8_t code = qk_ucis_state.codes[i];
105 register_code(code);
106 unregister_code(code);
107 }
108}
109
110bool process_record_ucis (uint16_t keycode, keyrecord_t *record) {
111 uint8_t i;
112
113 if (!qk_ucis_state.in_progress || !record->event.pressed)
114 return true;
115
116 qk_ucis_state.codes[qk_ucis_state.count] = keycode;
117 qk_ucis_state.count++;
118
119 if (keycode == KC_BSPC) {
120 if (qk_ucis_state.count >= 2) {
121 qk_ucis_state.count -= 2;
122 return true;
123 } else {
124 qk_ucis_state.count--;
125 return false;
126 }
127 }
128
129 if (keycode == KC_ENT || keycode == KC_SPC || keycode == KC_ESC) {
130 bool symbol_found = false;
131
132 for (i = qk_ucis_state.count; i > 0; i--) {
133 register_code (KC_BSPC);
134 unregister_code (KC_BSPC);
135 }
136
137 if (keycode == KC_ESC) {
138 qk_ucis_state.in_progress = false;
139 return false;
140 }
141
142 unicode_input_start();
143 for (i = 0; ucis_symbol_table[i].symbol; i++) {
144 if (is_uni_seq (ucis_symbol_table[i].symbol)) {
145 symbol_found = true;
146 for (uint8_t j = 0; ucis_symbol_table[i].codes[j]; j++) {
147 register_hex(ucis_symbol_table[i].codes[j]);
148 }
149 break;
150 }
151 }
152 if (!symbol_found) {
153 qk_ucis_symbol_fallback();
154 }
155 unicode_input_finish();
156
157 qk_ucis_state.in_progress = false;
158 return false;
159 }
160 return true;
161}
162#endif