34,28 → 34,26 |
#include <kbd.h> |
#include <kbd/kbd.h> |
#include <kbd/keycode.h> |
#include <bool.h> |
#include <layout.h> |
|
static void layout_reset(void); |
static wchar_t layout_parse_ev(kbd_event_t *ev); |
|
enum m_state { |
ms_start, |
ms_hacek, |
ms_carka |
}; |
|
static enum m_state mstate; |
|
layout_op_t cz_op = { |
layout_reset, |
layout_parse_ev |
}; |
|
static wchar_t map_lcase[] = { |
[KC_2] = L'ě', |
[KC_3] = L'š', |
[KC_4] = L'č', |
[KC_5] = L'ř', |
[KC_6] = L'ž', |
[KC_7] = L'ý', |
[KC_8] = L'á', |
[KC_9] = L'í', |
[KC_0] = L'é', |
|
[KC_LBRACKET] = L'ú', |
[KC_SEMICOLON] = L'ů', |
|
[KC_Q] = 'q', |
[KC_W] = 'w', |
[KC_E] = 'e', |
87,19 → 85,6 |
}; |
|
static wchar_t map_ucase[] = { |
[KC_2] = L'Ě', |
[KC_3] = L'Š', |
[KC_4] = L'Č', |
[KC_5] = L'Ř', |
[KC_6] = L'Ž', |
[KC_7] = L'Ý', |
[KC_8] = L'Á', |
[KC_9] = L'Í', |
[KC_0] = L'É', |
|
[KC_LBRACKET] = L'Ú', |
[KC_SEMICOLON] = L'Ů', |
|
[KC_Q] = 'Q', |
[KC_W] = 'W', |
[KC_E] = 'E', |
172,6 → 157,36 |
[KC_SLASH] = '_', |
}; |
|
static wchar_t map_ns_nocaps[] = { |
[KC_2] = L'ě', |
[KC_3] = L'š', |
[KC_4] = L'č', |
[KC_5] = L'ř', |
[KC_6] = L'ž', |
[KC_7] = L'ý', |
[KC_8] = L'á', |
[KC_9] = L'í', |
[KC_0] = L'é', |
|
[KC_LBRACKET] = L'ú', |
[KC_SEMICOLON] = L'ů' |
}; |
|
static wchar_t map_ns_caps[] = { |
[KC_2] = L'Ě', |
[KC_3] = L'Š', |
[KC_4] = L'Č', |
[KC_5] = L'Ř', |
[KC_6] = L'Ž', |
[KC_7] = L'Ý', |
[KC_8] = L'Á', |
[KC_9] = L'Í', |
[KC_0] = L'É', |
|
[KC_LBRACKET] = L'Ú', |
[KC_SEMICOLON] = L'Ů' |
}; |
|
static wchar_t map_neutral[] = { |
[KC_BACKSPACE] = '\b', |
[KC_TAB] = '\t', |
200,6 → 215,56 |
[KC_NPERIOD] = '.' |
}; |
|
static wchar_t map_hacek_lcase[] = { |
[KC_E] = L'ě', |
[KC_R] = L'ř', |
[KC_T] = L'ť', |
[KC_Y] = L'ž', |
[KC_U] = L'ů', |
|
[KC_S] = L'š', |
[KC_D] = L'ď', |
|
[KC_C] = L'č', |
[KC_N] = L'ň' |
}; |
|
static wchar_t map_hacek_ucase[] = { |
[KC_E] = L'Ě', |
[KC_R] = L'Ř', |
[KC_T] = L'Ť', |
[KC_Y] = L'Ž', |
[KC_U] = L'Ů', |
|
[KC_S] = L'Š', |
[KC_D] = L'Ď', |
|
[KC_C] = L'Č', |
[KC_N] = L'Ň' |
}; |
|
static wchar_t map_carka_lcase[] = { |
[KC_E] = L'é', |
[KC_U] = L'ú', |
[KC_I] = L'í', |
[KC_O] = L'ó', |
|
[KC_A] = L'á', |
|
[KC_Z] = L'ý', |
}; |
|
static wchar_t map_carka_ucase[] = { |
[KC_E] = L'É', |
[KC_U] = L'Ú', |
[KC_I] = L'Í', |
[KC_O] = L'Ó', |
|
[KC_A] = L'Á', |
|
[KC_Z] = L'Ý', |
}; |
|
static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length) |
{ |
if (key >= map_length) |
207,18 → 272,73 |
return map[key]; |
} |
|
static wchar_t layout_parse_ev(kbd_event_t *ev) |
static wchar_t parse_ms_hacek(kbd_event_t *ev) |
{ |
wchar_t c; |
|
mstate = ms_start; |
|
/* Produce no characters when Ctrl or Alt is pressed. */ |
if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
return 0; |
|
if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
c = translate(ev->key, map_hacek_ucase, sizeof(map_hacek_ucase) / sizeof(wchar_t)); |
else |
c = translate(ev->key, map_hacek_lcase, sizeof(map_hacek_lcase) / sizeof(wchar_t)); |
|
return c; |
} |
|
static wchar_t parse_ms_carka(kbd_event_t *ev) |
{ |
wchar_t c; |
|
mstate = ms_start; |
|
/* Produce no characters when Ctrl or Alt is pressed. */ |
if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
return 0; |
|
if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
c = translate(ev->key, map_carka_ucase, sizeof(map_carka_ucase) / sizeof(wchar_t)); |
else |
c = translate(ev->key, map_carka_lcase, sizeof(map_carka_lcase) / sizeof(wchar_t)); |
|
return c; |
} |
|
static wchar_t parse_ms_start(kbd_event_t *ev) |
{ |
wchar_t c; |
|
/* Produce no characters when Ctrl or Alt is pressed. */ |
if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
return 0; |
|
if (ev->key == KC_EQUALS) { |
if ((ev->mods & KM_SHIFT) != 0) |
mstate = ms_hacek; |
else |
mstate = ms_carka; |
|
return 0; |
} |
|
c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t)); |
if (c != 0) |
return c; |
|
if ((ev->mods & KM_SHIFT) == 0) { |
if ((ev->mods & KM_CAPS_LOCK) != 0) |
c = translate(ev->key, map_ns_caps, sizeof(map_ns_caps) / sizeof(wchar_t)); |
else |
c = translate(ev->key, map_ns_nocaps, sizeof(map_ns_nocaps) / sizeof(wchar_t)); |
|
if (c != 0) |
return c; |
} |
|
if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t)); |
else |
243,6 → 363,41 |
return c; |
} |
|
static bool key_is_mod(unsigned key) |
{ |
switch (key) { |
case KC_LSHIFT: |
case KC_RSHIFT: |
case KC_LALT: |
case KC_RALT: |
case KC_LCTRL: |
case KC_RCTRL: |
return true; |
default: |
return false; |
} |
} |
|
static void layout_reset(void) |
{ |
mstate = ms_start; |
} |
|
static wchar_t layout_parse_ev(kbd_event_t *ev) |
{ |
if (ev->type != KE_PRESS) |
return '\0'; |
|
if (key_is_mod(ev->key)) |
return '\0'; |
|
switch (mstate) { |
case ms_start: return parse_ms_start(ev); |
case ms_hacek: return parse_ms_hacek(ev); |
case ms_carka: return parse_ms_carka(ev); |
} |
} |
|
/** |
* @} |
*/ |