HelenOS sources
This source file includes following definitions.
- translate
- us_dvorak_create
- us_dvorak_destroy
- us_dvorak_parse_ev
#include <errno.h>
#include <io/console.h>
#include <io/keycode.h>
#include "../layout.h"
#include "../kbd.h"
static errno_t us_dvorak_create(layout_t *);
static void us_dvorak_destroy(layout_t *);
static char32_t us_dvorak_parse_ev(layout_t *, kbd_event_t *ev);
layout_ops_t us_dvorak_ops = {
.create = us_dvorak_create,
.destroy = us_dvorak_destroy,
.parse_ev = us_dvorak_parse_ev
};
static char32_t map_lcase[] = {
[KC_R] = 'p',
[KC_T] = 'y',
[KC_Y] = 'f',
[KC_U] = 'g',
[KC_I] = 'c',
[KC_O] = 'r',
[KC_P] = 'l',
[KC_A] = 'a',
[KC_S] = 'o',
[KC_D] = 'e',
[KC_F] = 'u',
[KC_G] = 'i',
[KC_H] = 'd',
[KC_J] = 'h',
[KC_K] = 't',
[KC_L] = 'n',
[KC_SEMICOLON] = 's',
[KC_X] = 'q',
[KC_C] = 'j',
[KC_V] = 'k',
[KC_B] = 'x',
[KC_N] = 'b',
[KC_M] = 'm',
[KC_COMMA] = 'w',
[KC_PERIOD] = 'v',
[KC_SLASH] = 'z',
};
static char32_t map_ucase[] = {
[KC_R] = 'P',
[KC_T] = 'Y',
[KC_Y] = 'F',
[KC_U] = 'G',
[KC_I] = 'C',
[KC_O] = 'R',
[KC_P] = 'L',
[KC_A] = 'A',
[KC_S] = 'O',
[KC_D] = 'E',
[KC_F] = 'U',
[KC_G] = 'I',
[KC_H] = 'D',
[KC_J] = 'H',
[KC_K] = 'T',
[KC_L] = 'N',
[KC_SEMICOLON] = 'S',
[KC_X] = 'Q',
[KC_C] = 'J',
[KC_V] = 'K',
[KC_B] = 'X',
[KC_N] = 'B',
[KC_M] = 'M',
[KC_COMMA] = 'W',
[KC_PERIOD] = 'V',
[KC_SLASH] = 'Z',
};
static char32_t map_not_shifted[] = {
[KC_BACKTICK] = '`',
[KC_1] = '1',
[KC_2] = '2',
[KC_3] = '3',
[KC_4] = '4',
[KC_5] = '5',
[KC_6] = '6',
[KC_7] = '7',
[KC_8] = '8',
[KC_9] = '9',
[KC_0] = '0',
[KC_MINUS] = '[',
[KC_EQUALS] = ']',
[KC_Q] = '\'',
[KC_W] = ',',
[KC_E] = '.',
[KC_LBRACKET] = '/',
[KC_RBRACKET] = '=',
[KC_QUOTE] = '-',
[KC_BACKSLASH] = '\\',
[KC_Z] = ';',
};
static char32_t map_shifted[] = {
[KC_BACKTICK] = '~',
[KC_1] = '!',
[KC_2] = '@',
[KC_3] = '#',
[KC_4] = '$',
[KC_5] = '%',
[KC_6] = '^',
[KC_7] = '&',
[KC_8] = '*',
[KC_9] = '(',
[KC_0] = ')',
[KC_MINUS] = '{',
[KC_EQUALS] = '}',
[KC_Q] = '"',
[KC_W] = '<',
[KC_E] = '>',
[KC_LBRACKET] = '?',
[KC_RBRACKET] = '+',
[KC_QUOTE] = '_',
[KC_BACKSLASH] = '|',
[KC_Z] = ':',
};
static char32_t map_neutral[] = {
[KC_BACKSPACE] = '\b',
[KC_TAB] = '\t',
[KC_ENTER] = '\n',
[KC_SPACE] = ' ',
[KC_NSLASH] = '/',
[KC_NTIMES] = '*',
[KC_NMINUS] = '-',
[KC_NPLUS] = '+',
[KC_NENTER] = '\n'
};
static char32_t map_numeric[] = {
[KC_N7] = '7',
[KC_N8] = '8',
[KC_N9] = '9',
[KC_N4] = '4',
[KC_N5] = '5',
[KC_N6] = '6',
[KC_N1] = '1',
[KC_N2] = '2',
[KC_N3] = '3',
[KC_N0] = '0',
[KC_NPERIOD] = '.'
};
static char32_t translate(unsigned int key, char32_t *map, size_t map_length)
{
if (key >= map_length)
return 0;
return map[key];
}
static errno_t us_dvorak_create(layout_t *state)
{
return EOK;
}
static void us_dvorak_destroy(layout_t *state)
{
}
static char32_t us_dvorak_parse_ev(layout_t *state, kbd_event_t *ev)
{
char32_t c;
c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(char32_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(char32_t));
else
c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(char32_t));
if (c != 0)
return c;
if ((ev->mods & KM_SHIFT) != 0)
c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(char32_t));
else
c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(char32_t));
if (c != 0)
return c;
if ((ev->mods & KM_NUM_LOCK) != 0)
c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(char32_t));
else
c = 0;
return c;
}
HelenOS homepage, sources at GitHub