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