2
* Copyright (c) 2009 Jiri Svoboda
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
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.
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.
30
* @brief Czech QWERTZ layout.
35
#include <io/console.h>
36
#include <io/keycode.h>
40
static void layout_reset(void);
41
static wchar_t layout_parse_ev(console_event_t *ev);
49
static enum m_state mstate;
56
static wchar_t map_lcase[] = {
87
static wchar_t map_ucase[] = {
118
static wchar_t map_not_shifted[] = {
134
static wchar_t map_shifted[] = {
151
[KC_SEMICOLON] = '"',
153
[KC_BACKSLASH] = '\'',
160
static wchar_t map_ns_nocaps[] = {
171
[KC_LBRACKET] = L'ú',
172
[KC_SEMICOLON] = L'ů'
175
static wchar_t map_ns_caps[] = {
186
[KC_LBRACKET] = L'Ú',
187
[KC_SEMICOLON] = L'Ů'
190
static wchar_t map_neutral[] = {
191
[KC_BACKSPACE] = '\b',
203
static wchar_t map_numeric[] = {
218
static wchar_t map_hacek_lcase[] = {
232
static wchar_t map_hacek_ucase[] = {
246
static wchar_t map_carka_lcase[] = {
257
static wchar_t map_carka_ucase[] = {
268
static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
270
if (key >= map_length)
275
static wchar_t parse_ms_hacek(console_event_t *ev)
281
/* Produce no characters when Ctrl or Alt is pressed. */
282
if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
285
if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
286
c = translate(ev->key, map_hacek_ucase, sizeof(map_hacek_ucase) / sizeof(wchar_t));
288
c = translate(ev->key, map_hacek_lcase, sizeof(map_hacek_lcase) / sizeof(wchar_t));
293
static wchar_t parse_ms_carka(console_event_t *ev)
299
/* Produce no characters when Ctrl or Alt is pressed. */
300
if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
303
if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
304
c = translate(ev->key, map_carka_ucase, sizeof(map_carka_ucase) / sizeof(wchar_t));
306
c = translate(ev->key, map_carka_lcase, sizeof(map_carka_lcase) / sizeof(wchar_t));
311
static wchar_t parse_ms_start(console_event_t *ev)
315
/* Produce no characters when Ctrl or Alt is pressed. */
316
if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
319
if (ev->key == KC_EQUALS) {
320
if ((ev->mods & KM_SHIFT) != 0)
328
c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t));
332
if ((ev->mods & KM_SHIFT) == 0) {
333
if ((ev->mods & KM_CAPS_LOCK) != 0)
334
c = translate(ev->key, map_ns_caps, sizeof(map_ns_caps) / sizeof(wchar_t));
336
c = translate(ev->key, map_ns_nocaps, sizeof(map_ns_nocaps) / sizeof(wchar_t));
342
if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
343
c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t));
345
c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t));
350
if ((ev->mods & KM_SHIFT) != 0)
351
c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t));
353
c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t));
358
if ((ev->mods & KM_NUM_LOCK) != 0)
359
c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t));
366
static bool key_is_mod(unsigned key)
381
static void layout_reset(void)
386
static wchar_t layout_parse_ev(console_event_t *ev)
388
if (ev->type != KEY_PRESS)
391
if (key_is_mod(ev->key))
396
return parse_ms_start(ev);
398
return parse_ms_hacek(ev);
400
return parse_ms_carka(ev);