Changeset e4f8c77 in mainline for uspace/srv/hid/input/layout/cz.c


Ignore:
Timestamp:
2011-07-13T22:39:18Z (13 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e6910c8
Parents:
5974661 (diff), 8ecef91 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge libposix.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/input/layout/cz.c

    r5974661 re4f8c77  
    11/*
    2  * Copyright (c) 2009 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup kbd
     29/** @addtogroup input
    3030 * @brief Czech QWERTZ layout.
    3131 * @{
    3232 */
    3333
    34 #include <kbd.h>
     34#include <errno.h>
     35#include <input.h>
    3536#include <io/console.h>
    3637#include <io/keycode.h>
    3738#include <bool.h>
    3839#include <layout.h>
    39 
    40 static void layout_reset(void);
    41 static wchar_t layout_parse_ev(kbd_event_t *ev);
     40#include <stdlib.h>
     41
     42static int cz_create(layout_t *);
     43static void cz_destroy(layout_t *);
     44static wchar_t cz_parse_ev(layout_t *, kbd_event_t *ev);
    4245
    4346enum m_state {
     
    4750};
    4851
    49 static enum m_state mstate;
    50 
    51 layout_op_t cz_op = {
    52         layout_reset,
    53         layout_parse_ev
     52typedef struct {
     53        enum m_state mstate;
     54} layout_cz_t;
     55
     56layout_ops_t cz_ops = {
     57        .create = cz_create,
     58        .destroy = cz_destroy,
     59        .parse_ev = cz_parse_ev
    5460};
    5561
     
    273279}
    274280
    275 static wchar_t parse_ms_hacek(kbd_event_t *ev)
     281static wchar_t parse_ms_hacek(layout_cz_t *cz_state, kbd_event_t *ev)
    276282{
    277283        wchar_t c;
    278284
    279         mstate = ms_start;
     285        cz_state->mstate = ms_start;
    280286
    281287        /* Produce no characters when Ctrl or Alt is pressed. */
     
    291297}
    292298
    293 static wchar_t parse_ms_carka(kbd_event_t *ev)
     299static wchar_t parse_ms_carka(layout_cz_t *cz_state, kbd_event_t *ev)
    294300{
    295301        wchar_t c;
    296302
    297         mstate = ms_start;
     303        cz_state->mstate = ms_start;
    298304
    299305        /* Produce no characters when Ctrl or Alt is pressed. */
     
    309315}
    310316
    311 static wchar_t parse_ms_start(kbd_event_t *ev)
     317static wchar_t parse_ms_start(layout_cz_t *cz_state, kbd_event_t *ev)
    312318{
    313319        wchar_t c;
     
    319325        if (ev->key == KC_EQUALS) {
    320326                if ((ev->mods & KM_SHIFT) != 0)
    321                         mstate = ms_hacek;
     327                        cz_state->mstate = ms_hacek;
    322328                else
    323                         mstate = ms_carka;
     329                        cz_state->mstate = ms_carka;
    324330
    325331                return 0;
     
    379385}
    380386
    381 static void layout_reset(void)
    382 {
    383         mstate = ms_start;
    384 }
    385 
    386 static wchar_t layout_parse_ev(kbd_event_t *ev)
    387 {
     387static int cz_create(layout_t *state)
     388{
     389        layout_cz_t *cz_state;
     390
     391        cz_state = malloc(sizeof(layout_cz_t));
     392        if (cz_state == NULL) {
     393                printf("%s: Out of memory.\n", NAME);
     394                return ENOMEM;
     395        }
     396
     397        cz_state->mstate = ms_start;
     398        state->layout_priv = (void *) cz_state;
     399
     400        return EOK;
     401}
     402
     403static void cz_destroy(layout_t *state)
     404{
     405        free(state->layout_priv);
     406}
     407
     408static 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
    388412        if (ev->type != KEY_PRESS)
    389413                return 0;
     
    392416                return 0;
    393417       
    394         switch (mstate) {
     418        switch (cz_state->mstate) {
    395419        case ms_start:
    396                 return parse_ms_start(ev);
     420                return parse_ms_start(cz_state, ev);
    397421        case ms_hacek:
    398                 return parse_ms_hacek(ev);
     422                return parse_ms_hacek(cz_state, ev);
    399423        case ms_carka:
    400                 return parse_ms_carka(ev);
     424                return parse_ms_carka(cz_state, ev);
    401425        }
    402426       
Note: See TracChangeset for help on using the changeset viewer.