Rev 4240 | Rev 4298 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4240 | Rev 4285 | ||
---|---|---|---|
Line 32... | Line 32... | ||
32 | */ |
32 | */ |
33 | 33 | ||
34 | #include <kbd.h> |
34 | #include <kbd.h> |
35 | #include <kbd/kbd.h> |
35 | #include <kbd/kbd.h> |
36 | #include <kbd/keycode.h> |
36 | #include <kbd/keycode.h> |
- | 37 | #include <bool.h> |
|
37 | #include <layout.h> |
38 | #include <layout.h> |
38 | 39 | ||
- | 40 | static void layout_reset(void); |
|
39 | static wchar_t layout_parse_ev(kbd_event_t *ev); |
41 | static wchar_t layout_parse_ev(kbd_event_t *ev); |
40 | 42 | ||
- | 43 | enum m_state { |
|
- | 44 | ms_start, |
|
- | 45 | ms_hacek, |
|
- | 46 | ms_carka |
|
- | 47 | }; |
|
- | 48 | ||
- | 49 | static enum m_state mstate; |
|
- | 50 | ||
41 | layout_op_t cz_op = { |
51 | layout_op_t cz_op = { |
- | 52 | layout_reset, |
|
42 | layout_parse_ev |
53 | layout_parse_ev |
43 | }; |
54 | }; |
44 | 55 | ||
45 | static wchar_t map_lcase[] = { |
56 | static wchar_t map_lcase[] = { |
46 | [KC_2] = L'ě', |
57 | [KC_2] = L'ě', |
Line 198... | Line 209... | ||
198 | 209 | ||
199 | [KC_N0] = '0', |
210 | [KC_N0] = '0', |
200 | [KC_NPERIOD] = '.' |
211 | [KC_NPERIOD] = '.' |
201 | }; |
212 | }; |
202 | 213 | ||
- | 214 | static wchar_t map_hacek_lcase[] = { |
|
- | 215 | [KC_E] = L'ě', |
|
- | 216 | [KC_R] = L'ř', |
|
- | 217 | [KC_T] = L'ť', |
|
- | 218 | [KC_Y] = L'ž', |
|
- | 219 | [KC_U] = L'ů', |
|
- | 220 | ||
- | 221 | [KC_S] = L'š', |
|
- | 222 | [KC_D] = L'ď', |
|
- | 223 | ||
- | 224 | [KC_C] = L'č', |
|
- | 225 | [KC_N] = L'ň' |
|
- | 226 | }; |
|
- | 227 | ||
- | 228 | static wchar_t map_hacek_ucase[] = { |
|
- | 229 | [KC_E] = L'Ě', |
|
- | 230 | [KC_R] = L'Ř', |
|
- | 231 | [KC_T] = L'Ť', |
|
- | 232 | [KC_Y] = L'Ž', |
|
- | 233 | [KC_U] = L'Ů', |
|
- | 234 | ||
- | 235 | [KC_S] = L'Š', |
|
- | 236 | [KC_D] = L'Ď', |
|
- | 237 | ||
- | 238 | [KC_C] = L'Č', |
|
- | 239 | [KC_N] = L'Ň' |
|
- | 240 | }; |
|
- | 241 | ||
- | 242 | static wchar_t map_carka_lcase[] = { |
|
- | 243 | [KC_E] = L'é', |
|
- | 244 | [KC_U] = L'ú', |
|
- | 245 | [KC_I] = L'í', |
|
- | 246 | [KC_O] = L'ó', |
|
- | 247 | ||
- | 248 | [KC_A] = L'á', |
|
- | 249 | ||
- | 250 | [KC_Z] = L'ý', |
|
- | 251 | }; |
|
- | 252 | ||
- | 253 | static wchar_t map_carka_ucase[] = { |
|
- | 254 | [KC_E] = L'É', |
|
- | 255 | [KC_U] = L'Ú', |
|
- | 256 | [KC_I] = L'Í', |
|
- | 257 | [KC_O] = L'Ó', |
|
- | 258 | ||
- | 259 | [KC_A] = L'Á', |
|
- | 260 | ||
- | 261 | [KC_Z] = L'Ý', |
|
- | 262 | }; |
|
- | 263 | ||
203 | static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length) |
264 | static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length) |
204 | { |
265 | { |
205 | if (key >= map_length) |
266 | if (key >= map_length) |
206 | return 0; |
267 | return 0; |
207 | return map[key]; |
268 | return map[key]; |
208 | } |
269 | } |
209 | 270 | ||
210 | static wchar_t layout_parse_ev(kbd_event_t *ev) |
271 | static wchar_t parse_ms_hacek(kbd_event_t *ev) |
211 | { |
272 | { |
212 | wchar_t c; |
273 | wchar_t c; |
213 | 274 | ||
- | 275 | mstate = ms_start; |
|
- | 276 | ||
214 | /* Produce no characters when Ctrl or Alt is pressed. */ |
277 | /* Produce no characters when Ctrl or Alt is pressed. */ |
215 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
278 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
216 | return 0; |
279 | return 0; |
217 | 280 | ||
- | 281 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
|
- | 282 | c = translate(ev->key, map_hacek_ucase, sizeof(map_hacek_ucase) / sizeof(wchar_t)); |
|
- | 283 | else |
|
- | 284 | c = translate(ev->key, map_hacek_lcase, sizeof(map_hacek_lcase) / sizeof(wchar_t)); |
|
- | 285 | ||
- | 286 | return c; |
|
- | 287 | } |
|
- | 288 | ||
- | 289 | static wchar_t parse_ms_carka(kbd_event_t *ev) |
|
- | 290 | { |
|
- | 291 | wchar_t c; |
|
- | 292 | ||
- | 293 | mstate = ms_start; |
|
- | 294 | ||
- | 295 | /* Produce no characters when Ctrl or Alt is pressed. */ |
|
- | 296 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
|
- | 297 | return 0; |
|
- | 298 | ||
- | 299 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
|
- | 300 | c = translate(ev->key, map_carka_ucase, sizeof(map_carka_ucase) / sizeof(wchar_t)); |
|
- | 301 | else |
|
- | 302 | c = translate(ev->key, map_carka_lcase, sizeof(map_carka_lcase) / sizeof(wchar_t)); |
|
- | 303 | ||
- | 304 | return c; |
|
- | 305 | } |
|
- | 306 | ||
- | 307 | static wchar_t parse_ms_start(kbd_event_t *ev) |
|
- | 308 | { |
|
- | 309 | wchar_t c; |
|
- | 310 | ||
- | 311 | /* Produce no characters when Ctrl or Alt is pressed. */ |
|
- | 312 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
|
- | 313 | return 0; |
|
- | 314 | ||
- | 315 | if (ev->key == KC_EQUALS) { |
|
- | 316 | if ((ev->mods & KM_SHIFT) != 0) |
|
- | 317 | mstate = ms_hacek; |
|
- | 318 | else |
|
- | 319 | mstate = ms_carka; |
|
- | 320 | ||
- | 321 | return 0; |
|
- | 322 | } |
|
- | 323 | ||
218 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t)); |
324 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t)); |
219 | if (c != 0) |
325 | if (c != 0) |
220 | return c; |
326 | return c; |
221 | 327 | ||
222 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
328 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
Line 241... | Line 347... | ||
241 | c = 0; |
347 | c = 0; |
242 | 348 | ||
243 | return c; |
349 | return c; |
244 | } |
350 | } |
245 | 351 | ||
- | 352 | static bool key_is_mod(unsigned key) |
|
- | 353 | { |
|
- | 354 | switch (key) { |
|
- | 355 | case KC_LSHIFT: |
|
- | 356 | case KC_RSHIFT: |
|
- | 357 | case KC_LALT: |
|
- | 358 | case KC_RALT: |
|
- | 359 | case KC_LCTRL: |
|
- | 360 | case KC_RCTRL: |
|
- | 361 | return true; |
|
- | 362 | default: |
|
- | 363 | return false; |
|
- | 364 | } |
|
- | 365 | } |
|
- | 366 | ||
- | 367 | static void layout_reset(void) |
|
- | 368 | { |
|
- | 369 | mstate = ms_start; |
|
- | 370 | } |
|
- | 371 | ||
- | 372 | static wchar_t layout_parse_ev(kbd_event_t *ev) |
|
- | 373 | { |
|
- | 374 | if (ev->type != KE_PRESS) |
|
- | 375 | return '\0'; |
|
- | 376 | ||
- | 377 | if (key_is_mod(ev->key)) |
|
- | 378 | return '\0'; |
|
- | 379 | ||
- | 380 | switch (mstate) { |
|
- | 381 | case ms_start: return parse_ms_start(ev); |
|
- | 382 | case ms_hacek: return parse_ms_hacek(ev); |
|
- | 383 | case ms_carka: return parse_ms_carka(ev); |
|
- | 384 | } |
|
- | 385 | } |
|
- | 386 | ||
246 | /** |
387 | /** |
247 | * @} |
388 | * @} |
248 | */ |
389 | */ |