diff options
author | Zay950 <Zay950@users.noreply.github.com> | 2017-03-29 12:00:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-29 12:00:38 -0700 |
commit | 2366ebfbbdeb6ec29cc9a0facda44d666305dd6e (patch) | |
tree | 883efed0b7260f3143f5a2a879bc3844a8255e0b /quantum/process_keycode/process_unicode.c | |
parent | 80c5ada3394c5ad8087df00ef878eb2cbcd87d70 (diff) | |
parent | 942f2ccee44bdb2e251553e9730cd8d59307d8b2 (diff) | |
download | qmk_firmware-2366ebfbbdeb6ec29cc9a0facda44d666305dd6e.tar.gz qmk_firmware-2366ebfbbdeb6ec29cc9a0facda44d666305dd6e.zip |
Merge branch 'master' into to_push
Diffstat (limited to 'quantum/process_keycode/process_unicode.c')
-rw-r--r-- | quantum/process_keycode/process_unicode.c | 196 |
1 files changed, 17 insertions, 179 deletions
diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c index f42f25538..cecfaeee9 100644 --- a/quantum/process_keycode/process_unicode.c +++ b/quantum/process_keycode/process_unicode.c | |||
@@ -1,4 +1,20 @@ | |||
1 | /* Copyright 2016 Jack Humbert | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
1 | #include "process_unicode.h" | 16 | #include "process_unicode.h" |
17 | #include "action_util.h" | ||
2 | 18 | ||
3 | static uint8_t input_mode; | 19 | static uint8_t input_mode; |
4 | static uint8_t first_flag = 0; | 20 | static uint8_t first_flag = 0; |
@@ -75,6 +91,7 @@ void register_hex(uint16_t hex) { | |||
75 | } | 91 | } |
76 | } | 92 | } |
77 | 93 | ||
94 | |||
78 | bool process_unicode(uint16_t keycode, keyrecord_t *record) { | 95 | bool process_unicode(uint16_t keycode, keyrecord_t *record) { |
79 | if (keycode > QK_UNICODE && record->event.pressed) { | 96 | if (keycode > QK_UNICODE && record->event.pressed) { |
80 | if (first_flag == 0) { | 97 | if (first_flag == 0) { |
@@ -89,182 +106,3 @@ bool process_unicode(uint16_t keycode, keyrecord_t *record) { | |||
89 | return true; | 106 | return true; |
90 | } | 107 | } |
91 | 108 | ||
92 | #ifdef UNICODEMAP_ENABLE | ||
93 | __attribute__((weak)) | ||
94 | const uint32_t PROGMEM unicode_map[] = { | ||
95 | }; | ||
96 | |||
97 | void register_hex32(uint32_t hex) { | ||
98 | uint8_t onzerostart = 1; | ||
99 | for(int i = 7; i >= 0; i--) { | ||
100 | if (i <= 3) { | ||
101 | onzerostart = 0; | ||
102 | } | ||
103 | uint8_t digit = ((hex >> (i*4)) & 0xF); | ||
104 | if (digit == 0) { | ||
105 | if (onzerostart == 0) { | ||
106 | register_code(hex_to_keycode(digit)); | ||
107 | unregister_code(hex_to_keycode(digit)); | ||
108 | } | ||
109 | } else { | ||
110 | register_code(hex_to_keycode(digit)); | ||
111 | unregister_code(hex_to_keycode(digit)); | ||
112 | onzerostart = 0; | ||
113 | } | ||
114 | } | ||
115 | } | ||
116 | |||
117 | __attribute__((weak)) | ||
118 | void unicode_map_input_error() {} | ||
119 | |||
120 | bool process_unicode_map(uint16_t keycode, keyrecord_t *record) { | ||
121 | if ((keycode & QK_UNICODE_MAP) == QK_UNICODE_MAP && record->event.pressed) { | ||
122 | const uint32_t* map = unicode_map; | ||
123 | uint16_t index = keycode & 0x7FF; | ||
124 | uint32_t code = pgm_read_dword_far(&map[index]); | ||
125 | if ((code > 0xFFFF && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) { | ||
126 | // when character is out of range supported by the OS | ||
127 | unicode_map_input_error(); | ||
128 | } else { | ||
129 | unicode_input_start(); | ||
130 | register_hex32(code); | ||
131 | unicode_input_finish(); | ||
132 | } | ||
133 | } | ||
134 | return true; | ||
135 | } | ||
136 | #endif | ||
137 | |||
138 | #ifdef UCIS_ENABLE | ||
139 | qk_ucis_state_t qk_ucis_state; | ||
140 | |||
141 | void qk_ucis_start(void) { | ||
142 | qk_ucis_state.count = 0; | ||
143 | qk_ucis_state.in_progress = true; | ||
144 | |||
145 | qk_ucis_start_user(); | ||
146 | } | ||
147 | |||
148 | __attribute__((weak)) | ||
149 | void qk_ucis_start_user(void) { | ||
150 | unicode_input_start(); | ||
151 | register_hex(0x2328); | ||
152 | unicode_input_finish(); | ||
153 | } | ||
154 | |||
155 | static bool is_uni_seq(char *seq) { | ||
156 | uint8_t i; | ||
157 | |||
158 | for (i = 0; seq[i]; i++) { | ||
159 | uint16_t code; | ||
160 | if (('1' <= seq[i]) && (seq[i] <= '0')) | ||
161 | code = seq[i] - '1' + KC_1; | ||
162 | else | ||
163 | code = seq[i] - 'a' + KC_A; | ||
164 | |||
165 | if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != code) | ||
166 | return false; | ||
167 | } | ||
168 | |||
169 | return (qk_ucis_state.codes[i] == KC_ENT || | ||
170 | qk_ucis_state.codes[i] == KC_SPC); | ||
171 | } | ||
172 | |||
173 | __attribute__((weak)) | ||
174 | void qk_ucis_symbol_fallback (void) { | ||
175 | for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) { | ||
176 | uint8_t code = qk_ucis_state.codes[i]; | ||
177 | register_code(code); | ||
178 | unregister_code(code); | ||
179 | wait_ms(UNICODE_TYPE_DELAY); | ||
180 | } | ||
181 | } | ||
182 | |||
183 | void register_ucis(const char *hex) { | ||
184 | for(int i = 0; hex[i]; i++) { | ||
185 | uint8_t kc = 0; | ||
186 | char c = hex[i]; | ||
187 | |||
188 | switch (c) { | ||
189 | case '0': | ||
190 | kc = KC_0; | ||
191 | break; | ||
192 | case '1' ... '9': | ||
193 | kc = c - '1' + KC_1; | ||
194 | break; | ||
195 | case 'a' ... 'f': | ||
196 | kc = c - 'a' + KC_A; | ||
197 | break; | ||
198 | case 'A' ... 'F': | ||
199 | kc = c - 'A' + KC_A; | ||
200 | break; | ||
201 | } | ||
202 | |||
203 | if (kc) { | ||
204 | register_code (kc); | ||
205 | unregister_code (kc); | ||
206 | wait_ms (UNICODE_TYPE_DELAY); | ||
207 | } | ||
208 | } | ||
209 | } | ||
210 | |||
211 | bool process_ucis (uint16_t keycode, keyrecord_t *record) { | ||
212 | uint8_t i; | ||
213 | |||
214 | if (!qk_ucis_state.in_progress) | ||
215 | return true; | ||
216 | |||
217 | if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH && | ||
218 | !(keycode == KC_BSPC || keycode == KC_ESC || keycode == KC_SPC || keycode == KC_ENT)) { | ||
219 | return false; | ||
220 | } | ||
221 | |||
222 | if (!record->event.pressed) | ||
223 | return true; | ||
224 | |||
225 | qk_ucis_state.codes[qk_ucis_state.count] = keycode; | ||
226 | qk_ucis_state.count++; | ||
227 | |||
228 | if (keycode == KC_BSPC) { | ||
229 | if (qk_ucis_state.count >= 2) { | ||
230 | qk_ucis_state.count -= 2; | ||
231 | return true; | ||
232 | } else { | ||
233 | qk_ucis_state.count--; | ||
234 | return false; | ||
235 | } | ||
236 | } | ||
237 | |||
238 | if (keycode == KC_ENT || keycode == KC_SPC || keycode == KC_ESC) { | ||
239 | bool symbol_found = false; | ||
240 | |||
241 | for (i = qk_ucis_state.count; i > 0; i--) { | ||
242 | register_code (KC_BSPC); | ||
243 | unregister_code (KC_BSPC); | ||
244 | wait_ms(UNICODE_TYPE_DELAY); | ||
245 | } | ||
246 | |||
247 | if (keycode == KC_ESC) { | ||
248 | qk_ucis_state.in_progress = false; | ||
249 | return false; | ||
250 | } | ||
251 | |||
252 | unicode_input_start(); | ||
253 | for (i = 0; ucis_symbol_table[i].symbol; i++) { | ||
254 | if (is_uni_seq (ucis_symbol_table[i].symbol)) { | ||
255 | symbol_found = true; | ||
256 | register_ucis(ucis_symbol_table[i].code + 2); | ||
257 | break; | ||
258 | } | ||
259 | } | ||
260 | if (!symbol_found) { | ||
261 | qk_ucis_symbol_fallback(); | ||
262 | } | ||
263 | unicode_input_finish(); | ||
264 | |||
265 | qk_ucis_state.in_progress = false; | ||
266 | return false; | ||
267 | } | ||
268 | return true; | ||
269 | } | ||
270 | #endif | ||