Changeset d15815e2 in mainline for uspace/srv/kbd/layout/cz.c


Ignore:
Timestamp:
2009-04-15T22:01:18Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f0707ab
Parents:
9239333
Message:

Implement Czech combinator keys (hacek and carka).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/kbd/layout/cz.c

    r9239333 rd15815e2  
    3535#include <kbd/kbd.h>
    3636#include <kbd/keycode.h>
     37#include <bool.h>
    3738#include <layout.h>
    3839
     40static void layout_reset(void);
    3941static wchar_t layout_parse_ev(kbd_event_t *ev);
    4042
     43enum m_state {
     44        ms_start,
     45        ms_hacek,
     46        ms_carka       
     47};
     48
     49static enum m_state mstate;
     50
    4151layout_op_t cz_op = {
     52        layout_reset,
    4253        layout_parse_ev
    4354};
     
    201212};
    202213
     214static 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
     228static 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
     242static 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
     253static 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
    203264static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
    204265{
     
    208269}
    209270
    210 static wchar_t layout_parse_ev(kbd_event_t *ev)
     271static wchar_t parse_ms_hacek(kbd_event_t *ev)
    211272{
    212273        wchar_t c;
     274
     275        mstate = ms_start;
    213276
    214277        /* Produce no characters when Ctrl or Alt is pressed. */
    215278        if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
    216279                return 0;
     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
     289static 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
     307static 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        }
    217323
    218324        c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t));
     
    244350}
    245351
     352static 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
     367static void layout_reset(void)
     368{
     369        mstate = ms_start;
     370}
     371
     372static 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
    246387/**
    247388 * @}
Note: See TracChangeset for help on using the changeset viewer.