[cee8d3e] | 1 | /*
|
---|
[2f7a564] | 2 | * Copyright (c) 2011 Jiri Svoboda
|
---|
[cee8d3e] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[5f88293] | 29 | /** @addtogroup input
|
---|
[aa7954f] | 30 | * @brief Czech QWERTZ layout.
|
---|
[cee8d3e] | 31 | * @{
|
---|
[215abc1] | 32 | */
|
---|
[cee8d3e] | 33 |
|
---|
[2f7a564] | 34 | #include <errno.h>
|
---|
[215abc1] | 35 | #include <io/console.h>
|
---|
| 36 | #include <io/keycode.h>
|
---|
[3e6a98c5] | 37 | #include <stdbool.h>
|
---|
[2f7a564] | 38 | #include <stdlib.h>
|
---|
[b6a088f] | 39 | #include "../input.h"
|
---|
| 40 | #include "../layout.h"
|
---|
[cee8d3e] | 41 |
|
---|
[2f7a564] | 42 | static int cz_create(layout_t *);
|
---|
| 43 | static void cz_destroy(layout_t *);
|
---|
| 44 | static wchar_t cz_parse_ev(layout_t *, kbd_event_t *ev);
|
---|
[0175246] | 45 |
|
---|
[d15815e2] | 46 | enum m_state {
|
---|
| 47 | ms_start,
|
---|
| 48 | ms_hacek,
|
---|
[215abc1] | 49 | ms_carka
|
---|
[d15815e2] | 50 | };
|
---|
| 51 |
|
---|
[2f7a564] | 52 | typedef struct {
|
---|
| 53 | enum m_state mstate;
|
---|
| 54 | } layout_cz_t;
|
---|
[d15815e2] | 55 |
|
---|
[2f7a564] | 56 | layout_ops_t cz_ops = {
|
---|
| 57 | .create = cz_create,
|
---|
| 58 | .destroy = cz_destroy,
|
---|
| 59 | .parse_ev = cz_parse_ev
|
---|
[0175246] | 60 | };
|
---|
| 61 |
|
---|
[cee8d3e] | 62 | static wchar_t map_lcase[] = {
|
---|
| 63 | [KC_Q] = 'q',
|
---|
| 64 | [KC_W] = 'w',
|
---|
| 65 | [KC_E] = 'e',
|
---|
| 66 | [KC_R] = 'r',
|
---|
| 67 | [KC_T] = 't',
|
---|
| 68 | [KC_Y] = 'z',
|
---|
| 69 | [KC_U] = 'u',
|
---|
| 70 | [KC_I] = 'i',
|
---|
| 71 | [KC_O] = 'o',
|
---|
| 72 | [KC_P] = 'p',
|
---|
| 73 |
|
---|
| 74 | [KC_A] = 'a',
|
---|
| 75 | [KC_S] = 's',
|
---|
| 76 | [KC_D] = 'd',
|
---|
| 77 | [KC_F] = 'f',
|
---|
| 78 | [KC_G] = 'g',
|
---|
| 79 | [KC_H] = 'h',
|
---|
| 80 | [KC_J] = 'j',
|
---|
| 81 | [KC_K] = 'k',
|
---|
| 82 | [KC_L] = 'l',
|
---|
| 83 |
|
---|
| 84 | [KC_Z] = 'y',
|
---|
| 85 | [KC_X] = 'x',
|
---|
| 86 | [KC_C] = 'c',
|
---|
| 87 | [KC_V] = 'v',
|
---|
| 88 | [KC_B] = 'b',
|
---|
| 89 | [KC_N] = 'n',
|
---|
| 90 | [KC_M] = 'm',
|
---|
| 91 | };
|
---|
| 92 |
|
---|
| 93 | static wchar_t map_ucase[] = {
|
---|
| 94 | [KC_Q] = 'Q',
|
---|
| 95 | [KC_W] = 'W',
|
---|
| 96 | [KC_E] = 'E',
|
---|
| 97 | [KC_R] = 'R',
|
---|
| 98 | [KC_T] = 'T',
|
---|
| 99 | [KC_Y] = 'Z',
|
---|
| 100 | [KC_U] = 'U',
|
---|
| 101 | [KC_I] = 'I',
|
---|
| 102 | [KC_O] = 'O',
|
---|
| 103 | [KC_P] = 'P',
|
---|
| 104 |
|
---|
| 105 | [KC_A] = 'A',
|
---|
| 106 | [KC_S] = 'S',
|
---|
| 107 | [KC_D] = 'D',
|
---|
| 108 | [KC_F] = 'F',
|
---|
| 109 | [KC_G] = 'G',
|
---|
| 110 | [KC_H] = 'H',
|
---|
| 111 | [KC_J] = 'J',
|
---|
| 112 | [KC_K] = 'K',
|
---|
| 113 | [KC_L] = 'L',
|
---|
| 114 |
|
---|
| 115 | [KC_Z] = 'Y',
|
---|
| 116 | [KC_X] = 'X',
|
---|
| 117 | [KC_C] = 'C',
|
---|
| 118 | [KC_V] = 'V',
|
---|
| 119 | [KC_B] = 'B',
|
---|
| 120 | [KC_N] = 'N',
|
---|
| 121 | [KC_M] = 'M',
|
---|
| 122 | };
|
---|
| 123 |
|
---|
| 124 | static wchar_t map_not_shifted[] = {
|
---|
| 125 | [KC_BACKTICK] = ';',
|
---|
| 126 |
|
---|
| 127 | [KC_1] = '+',
|
---|
| 128 |
|
---|
| 129 | [KC_MINUS] = '=',
|
---|
| 130 |
|
---|
| 131 | [KC_RBRACKET] = ')',
|
---|
| 132 |
|
---|
[56fa418] | 133 | [KC_QUOTE] = L'§',
|
---|
[cee8d3e] | 134 |
|
---|
| 135 | [KC_COMMA] = ',',
|
---|
| 136 | [KC_PERIOD] = '.',
|
---|
| 137 | [KC_SLASH] = '-',
|
---|
| 138 | };
|
---|
| 139 |
|
---|
| 140 | static wchar_t map_shifted[] = {
|
---|
| 141 | [KC_1] = '1',
|
---|
| 142 | [KC_2] = '2',
|
---|
| 143 | [KC_3] = '3',
|
---|
| 144 | [KC_4] = '4',
|
---|
| 145 | [KC_5] = '5',
|
---|
| 146 | [KC_6] = '6',
|
---|
| 147 | [KC_7] = '7',
|
---|
| 148 | [KC_8] = '8',
|
---|
| 149 | [KC_9] = '9',
|
---|
| 150 | [KC_0] = '0',
|
---|
| 151 |
|
---|
| 152 | [KC_MINUS] = '%',
|
---|
| 153 |
|
---|
| 154 | [KC_LBRACKET] = '/',
|
---|
| 155 | [KC_RBRACKET] = '(',
|
---|
| 156 |
|
---|
| 157 | [KC_SEMICOLON] = '"',
|
---|
| 158 | [KC_QUOTE] = '!',
|
---|
| 159 | [KC_BACKSLASH] = '\'',
|
---|
| 160 |
|
---|
| 161 | [KC_COMMA] = '?',
|
---|
| 162 | [KC_PERIOD] = ':',
|
---|
| 163 | [KC_SLASH] = '_',
|
---|
| 164 | };
|
---|
| 165 |
|
---|
[fe24a52] | 166 | static wchar_t map_ns_nocaps[] = {
|
---|
| 167 | [KC_2] = L'ě',
|
---|
| 168 | [KC_3] = L'š',
|
---|
| 169 | [KC_4] = L'č',
|
---|
| 170 | [KC_5] = L'ř',
|
---|
| 171 | [KC_6] = L'ž',
|
---|
| 172 | [KC_7] = L'ý',
|
---|
| 173 | [KC_8] = L'á',
|
---|
| 174 | [KC_9] = L'í',
|
---|
| 175 | [KC_0] = L'é',
|
---|
| 176 |
|
---|
| 177 | [KC_LBRACKET] = L'ú',
|
---|
| 178 | [KC_SEMICOLON] = L'ů'
|
---|
| 179 | };
|
---|
| 180 |
|
---|
| 181 | static wchar_t map_ns_caps[] = {
|
---|
| 182 | [KC_2] = L'Ě',
|
---|
| 183 | [KC_3] = L'Š',
|
---|
| 184 | [KC_4] = L'Č',
|
---|
| 185 | [KC_5] = L'Ř',
|
---|
| 186 | [KC_6] = L'Ž',
|
---|
| 187 | [KC_7] = L'Ý',
|
---|
| 188 | [KC_8] = L'Á',
|
---|
| 189 | [KC_9] = L'Í',
|
---|
| 190 | [KC_0] = L'É',
|
---|
| 191 |
|
---|
| 192 | [KC_LBRACKET] = L'Ú',
|
---|
| 193 | [KC_SEMICOLON] = L'Ů'
|
---|
| 194 | };
|
---|
| 195 |
|
---|
[cee8d3e] | 196 | static wchar_t map_neutral[] = {
|
---|
| 197 | [KC_BACKSPACE] = '\b',
|
---|
| 198 | [KC_TAB] = '\t',
|
---|
| 199 | [KC_ENTER] = '\n',
|
---|
| 200 | [KC_SPACE] = ' ',
|
---|
| 201 |
|
---|
| 202 | [KC_NSLASH] = '/',
|
---|
| 203 | [KC_NTIMES] = '*',
|
---|
| 204 | [KC_NMINUS] = '-',
|
---|
| 205 | [KC_NPLUS] = '+',
|
---|
| 206 | [KC_NENTER] = '\n'
|
---|
| 207 | };
|
---|
| 208 |
|
---|
| 209 | static wchar_t map_numeric[] = {
|
---|
| 210 | [KC_N7] = '7',
|
---|
| 211 | [KC_N8] = '8',
|
---|
| 212 | [KC_N9] = '9',
|
---|
| 213 | [KC_N4] = '4',
|
---|
| 214 | [KC_N5] = '5',
|
---|
| 215 | [KC_N6] = '6',
|
---|
| 216 | [KC_N1] = '1',
|
---|
| 217 | [KC_N2] = '2',
|
---|
| 218 | [KC_N3] = '3',
|
---|
| 219 |
|
---|
| 220 | [KC_N0] = '0',
|
---|
| 221 | [KC_NPERIOD] = '.'
|
---|
| 222 | };
|
---|
| 223 |
|
---|
[d15815e2] | 224 | static wchar_t map_hacek_lcase[] = {
|
---|
| 225 | [KC_E] = L'ě',
|
---|
| 226 | [KC_R] = L'ř',
|
---|
| 227 | [KC_T] = L'ť',
|
---|
| 228 | [KC_Y] = L'ž',
|
---|
| 229 | [KC_U] = L'ů',
|
---|
| 230 |
|
---|
| 231 | [KC_S] = L'š',
|
---|
| 232 | [KC_D] = L'ď',
|
---|
| 233 |
|
---|
| 234 | [KC_C] = L'č',
|
---|
| 235 | [KC_N] = L'ň'
|
---|
| 236 | };
|
---|
| 237 |
|
---|
| 238 | static wchar_t map_hacek_ucase[] = {
|
---|
| 239 | [KC_E] = L'Ě',
|
---|
| 240 | [KC_R] = L'Ř',
|
---|
| 241 | [KC_T] = L'Ť',
|
---|
| 242 | [KC_Y] = L'Ž',
|
---|
| 243 | [KC_U] = L'Ů',
|
---|
| 244 |
|
---|
| 245 | [KC_S] = L'Š',
|
---|
| 246 | [KC_D] = L'Ď',
|
---|
| 247 |
|
---|
| 248 | [KC_C] = L'Č',
|
---|
| 249 | [KC_N] = L'Ň'
|
---|
| 250 | };
|
---|
| 251 |
|
---|
| 252 | static wchar_t map_carka_lcase[] = {
|
---|
| 253 | [KC_E] = L'é',
|
---|
| 254 | [KC_U] = L'ú',
|
---|
| 255 | [KC_I] = L'í',
|
---|
| 256 | [KC_O] = L'ó',
|
---|
| 257 |
|
---|
| 258 | [KC_A] = L'á',
|
---|
| 259 |
|
---|
| 260 | [KC_Z] = L'ý',
|
---|
| 261 | };
|
---|
| 262 |
|
---|
| 263 | static wchar_t map_carka_ucase[] = {
|
---|
| 264 | [KC_E] = L'É',
|
---|
| 265 | [KC_U] = L'Ú',
|
---|
| 266 | [KC_I] = L'Í',
|
---|
| 267 | [KC_O] = L'Ó',
|
---|
| 268 |
|
---|
| 269 | [KC_A] = L'Á',
|
---|
| 270 |
|
---|
| 271 | [KC_Z] = L'Ý',
|
---|
| 272 | };
|
---|
| 273 |
|
---|
[cee8d3e] | 274 | static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
|
---|
| 275 | {
|
---|
| 276 | if (key >= map_length)
|
---|
| 277 | return 0;
|
---|
| 278 | return map[key];
|
---|
| 279 | }
|
---|
| 280 |
|
---|
[2f7a564] | 281 | static wchar_t parse_ms_hacek(layout_cz_t *cz_state, kbd_event_t *ev)
|
---|
[cee8d3e] | 282 | {
|
---|
| 283 | wchar_t c;
|
---|
| 284 |
|
---|
[2f7a564] | 285 | cz_state->mstate = ms_start;
|
---|
[d15815e2] | 286 |
|
---|
[cee8d3e] | 287 | /* Produce no characters when Ctrl or Alt is pressed. */
|
---|
| 288 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
|
---|
| 289 | return 0;
|
---|
| 290 |
|
---|
[d15815e2] | 291 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
|
---|
| 292 | c = translate(ev->key, map_hacek_ucase, sizeof(map_hacek_ucase) / sizeof(wchar_t));
|
---|
| 293 | else
|
---|
| 294 | c = translate(ev->key, map_hacek_lcase, sizeof(map_hacek_lcase) / sizeof(wchar_t));
|
---|
| 295 |
|
---|
| 296 | return c;
|
---|
| 297 | }
|
---|
| 298 |
|
---|
[2f7a564] | 299 | static wchar_t parse_ms_carka(layout_cz_t *cz_state, kbd_event_t *ev)
|
---|
[d15815e2] | 300 | {
|
---|
| 301 | wchar_t c;
|
---|
| 302 |
|
---|
[2f7a564] | 303 | cz_state->mstate = ms_start;
|
---|
[d15815e2] | 304 |
|
---|
| 305 | /* Produce no characters when Ctrl or Alt is pressed. */
|
---|
| 306 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
|
---|
| 307 | return 0;
|
---|
| 308 |
|
---|
| 309 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
|
---|
| 310 | c = translate(ev->key, map_carka_ucase, sizeof(map_carka_ucase) / sizeof(wchar_t));
|
---|
| 311 | else
|
---|
| 312 | c = translate(ev->key, map_carka_lcase, sizeof(map_carka_lcase) / sizeof(wchar_t));
|
---|
| 313 |
|
---|
| 314 | return c;
|
---|
| 315 | }
|
---|
| 316 |
|
---|
[2f7a564] | 317 | static wchar_t parse_ms_start(layout_cz_t *cz_state, kbd_event_t *ev)
|
---|
[d15815e2] | 318 | {
|
---|
| 319 | wchar_t c;
|
---|
| 320 |
|
---|
| 321 | /* Produce no characters when Ctrl or Alt is pressed. */
|
---|
| 322 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
|
---|
| 323 | return 0;
|
---|
| 324 |
|
---|
| 325 | if (ev->key == KC_EQUALS) {
|
---|
| 326 | if ((ev->mods & KM_SHIFT) != 0)
|
---|
[2f7a564] | 327 | cz_state->mstate = ms_hacek;
|
---|
[d15815e2] | 328 | else
|
---|
[2f7a564] | 329 | cz_state->mstate = ms_carka;
|
---|
[d15815e2] | 330 |
|
---|
| 331 | return 0;
|
---|
| 332 | }
|
---|
| 333 |
|
---|
[cee8d3e] | 334 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t));
|
---|
| 335 | if (c != 0)
|
---|
| 336 | return c;
|
---|
| 337 |
|
---|
[fe24a52] | 338 | if ((ev->mods & KM_SHIFT) == 0) {
|
---|
| 339 | if ((ev->mods & KM_CAPS_LOCK) != 0)
|
---|
| 340 | c = translate(ev->key, map_ns_caps, sizeof(map_ns_caps) / sizeof(wchar_t));
|
---|
| 341 | else
|
---|
| 342 | c = translate(ev->key, map_ns_nocaps, sizeof(map_ns_nocaps) / sizeof(wchar_t));
|
---|
| 343 |
|
---|
| 344 | if (c != 0)
|
---|
| 345 | return c;
|
---|
| 346 | }
|
---|
| 347 |
|
---|
[cee8d3e] | 348 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
|
---|
| 349 | c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t));
|
---|
| 350 | else
|
---|
| 351 | c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t));
|
---|
| 352 |
|
---|
| 353 | if (c != 0)
|
---|
| 354 | return c;
|
---|
| 355 |
|
---|
| 356 | if ((ev->mods & KM_SHIFT) != 0)
|
---|
| 357 | c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t));
|
---|
| 358 | else
|
---|
| 359 | c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t));
|
---|
| 360 |
|
---|
| 361 | if (c != 0)
|
---|
| 362 | return c;
|
---|
| 363 |
|
---|
| 364 | if ((ev->mods & KM_NUM_LOCK) != 0)
|
---|
| 365 | c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t));
|
---|
| 366 | else
|
---|
| 367 | c = 0;
|
---|
| 368 |
|
---|
| 369 | return c;
|
---|
| 370 | }
|
---|
| 371 |
|
---|
[d15815e2] | 372 | static bool key_is_mod(unsigned key)
|
---|
| 373 | {
|
---|
| 374 | switch (key) {
|
---|
| 375 | case KC_LSHIFT:
|
---|
| 376 | case KC_RSHIFT:
|
---|
| 377 | case KC_LALT:
|
---|
| 378 | case KC_RALT:
|
---|
| 379 | case KC_LCTRL:
|
---|
| 380 | case KC_RCTRL:
|
---|
| 381 | return true;
|
---|
| 382 | default:
|
---|
| 383 | return false;
|
---|
| 384 | }
|
---|
| 385 | }
|
---|
| 386 |
|
---|
[2f7a564] | 387 | static int cz_create(layout_t *state)
|
---|
[d15815e2] | 388 | {
|
---|
[2f7a564] | 389 | layout_cz_t *cz_state;
|
---|
| 390 |
|
---|
| 391 | cz_state = malloc(sizeof(layout_cz_t));
|
---|
| 392 | if (cz_state == NULL) {
|
---|
[1875a0c] | 393 | printf("%s: Out of memory.\n", NAME);
|
---|
[2f7a564] | 394 | return ENOMEM;
|
---|
| 395 | }
|
---|
| 396 |
|
---|
| 397 | cz_state->mstate = ms_start;
|
---|
| 398 | state->layout_priv = (void *) cz_state;
|
---|
| 399 |
|
---|
| 400 | return EOK;
|
---|
[d15815e2] | 401 | }
|
---|
| 402 |
|
---|
[2f7a564] | 403 | static void cz_destroy(layout_t *state)
|
---|
[d15815e2] | 404 | {
|
---|
[2f7a564] | 405 | free(state->layout_priv);
|
---|
| 406 | }
|
---|
| 407 |
|
---|
| 408 | static wchar_t cz_parse_ev(layout_t *state, kbd_event_t *ev)
|
---|
| 409 | {
|
---|
| 410 | layout_cz_t *cz_state = (layout_cz_t *) state->layout_priv;
|
---|
| 411 |
|
---|
[215abc1] | 412 | if (ev->type != KEY_PRESS)
|
---|
| 413 | return 0;
|
---|
| 414 |
|
---|
[d15815e2] | 415 | if (key_is_mod(ev->key))
|
---|
[215abc1] | 416 | return 0;
|
---|
| 417 |
|
---|
[2f7a564] | 418 | switch (cz_state->mstate) {
|
---|
[215abc1] | 419 | case ms_start:
|
---|
[2f7a564] | 420 | return parse_ms_start(cz_state, ev);
|
---|
[215abc1] | 421 | case ms_hacek:
|
---|
[2f7a564] | 422 | return parse_ms_hacek(cz_state, ev);
|
---|
[215abc1] | 423 | case ms_carka:
|
---|
[2f7a564] | 424 | return parse_ms_carka(cz_state, ev);
|
---|
[d15815e2] | 425 | }
|
---|
[f954906] | 426 |
|
---|
| 427 | return 0;
|
---|
[d15815e2] | 428 | }
|
---|
| 429 |
|
---|
[cee8d3e] | 430 | /**
|
---|
| 431 | * @}
|
---|
[215abc1] | 432 | */
|
---|