Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4262 → Rev 4263

/branches/network/uspace/srv/kbd/include/layout.h
38,9 → 38,16
#define KBD_LAYOUT_H_
 
#include <kbd/kbd.h>
#include <sys/types.h>
 
extern char layout_parse_ev(kbd_event_t *);
typedef struct {
wchar_t (*parse_ev)(kbd_event_t *);
} layout_op_t;
 
extern layout_op_t us_qwerty_op;
extern layout_op_t us_dvorak_op;
extern layout_op_t cz_op;
 
#endif
 
/**
/branches/network/uspace/srv/kbd/include/key_buffer.h
55,7 → 55,6
extern int keybuffer_available(keybuffer_t *);
extern int keybuffer_empty(keybuffer_t *);
extern void keybuffer_push(keybuffer_t *, const kbd_event_t *);
extern void keybuffer_push0(keybuffer_t *, int c);
extern int keybuffer_pop(keybuffer_t *, kbd_event_t *);
 
#endif
/branches/network/uspace/srv/kbd/generic/kbd.c
70,6 → 70,16
int cir_service = 0;
int cir_phone = -1;
 
#define NUM_LAYOUTS 3
 
static layout_op_t *layout[NUM_LAYOUTS] = {
&us_qwerty_op,
&us_dvorak_op,
&cz_op
};
 
static int active_layout = 0;
 
void kbd_push_scancode(int scancode)
{
/* printf("scancode: 0x%x\n", scancode);*/
123,11 → 133,29
printf("mods: 0x%x\n", mods);
printf("keycode: %u\n", key);
*/
if (type == KE_PRESS && (mods & KM_LCTRL) &&
key == KC_F1) {
active_layout = 0;
return;
}
 
if (type == KE_PRESS && (mods & KM_LCTRL) &&
key == KC_F2) {
active_layout = 1;
return;
}
 
if (type == KE_PRESS && (mods & KM_LCTRL) &&
key == KC_F3) {
active_layout = 2;
return;
}
 
ev.type = type;
ev.key = key;
ev.mods = mods;
 
ev.c = layout_parse_ev(&ev);
ev.c = layout[active_layout]->parse_ev(&ev);
 
async_msg_4(phone2cons, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c);
}
/branches/network/uspace/srv/kbd/generic/key_buffer.c
93,14 → 93,6
futex_up(&keybuffer_futex);
}
 
void keybuffer_push0(keybuffer_t *keybuffer, int c)
{
kbd_event_t ev;
 
ev.key = c; ev.mods = 0; ev.c = c;
keybuffer_push(keybuffer, &ev);
}
 
/** Pop event from buffer.
*
* @param edst Pointer to where the event should be saved.
/branches/network/uspace/srv/kbd/Makefile
49,15 → 49,11
generic/key_buffer.c
 
ARCH_SOURCES =
GENARCH_SOURCES =
GENARCH_SOURCES = \
layout/cz.c \
layout/us_qwerty.c \
layout/us_dvorak.c
 
ifeq ($(KBD_LAYOUT), us_qwerty)
GENARCH_SOURCES += layout/us_qwerty.c
endif
ifeq ($(KBD_LAYOUT), us_dvorak)
GENARCH_SOURCES += layout/us_dvorak.c
endif
 
ifeq ($(UARCH), amd64)
GENARCH_SOURCES += \
port/i8042.c \
/branches/network/uspace/srv/kbd/layout/us_qwerty.c
36,7 → 36,13
#include <kbd/keycode.h>
#include <layout.h>
 
static char map_lcase[] = {
static wchar_t layout_parse_ev(kbd_event_t *ev);
 
layout_op_t us_qwerty_op = {
layout_parse_ev
};
 
static wchar_t map_lcase[] = {
[KC_Q] = 'q',
[KC_W] = 'w',
[KC_E] = 'e',
67,7 → 73,7
[KC_M] = 'm',
};
 
static char map_ucase[] = {
static wchar_t map_ucase[] = {
[KC_Q] = 'Q',
[KC_W] = 'W',
[KC_E] = 'E',
98,7 → 104,7
[KC_M] = 'M',
};
 
static char map_not_shifted[] = {
static wchar_t map_not_shifted[] = {
[KC_BACKTICK] = '`',
 
[KC_1] = '1',
127,7 → 133,7
[KC_SLASH] = '/',
};
 
static char map_shifted[] = {
static wchar_t map_shifted[] = {
[KC_BACKTICK] = '~',
 
[KC_1] = '!',
156,7 → 162,7
[KC_SLASH] = '?',
};
 
static char map_neutral[] = {
static wchar_t map_neutral[] = {
[KC_BACKSPACE] = '\b',
[KC_TAB] = '\t',
[KC_ENTER] = '\n',
169,7 → 175,7
[KC_NENTER] = '\n'
};
 
static char map_numeric[] = {
static wchar_t map_numeric[] = {
[KC_N7] = '7',
[KC_N8] = '8',
[KC_N9] = '9',
184,39 → 190,43
[KC_NPERIOD] = '.'
};
 
static int translate(unsigned int key, char *map, size_t map_length)
static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
{
if (key >= map_length) return 0;
return map[key];
if (key >= map_length)
return 0;
return map[key];
}
 
char layout_parse_ev(kbd_event_t *ev)
static wchar_t layout_parse_ev(kbd_event_t *ev)
{
char c;
wchar_t c;
 
/* Produce no characters when Ctrl or Alt is pressed. */
if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
return 0;
 
c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(char));
if (c != 0) return c;
c = translate(ev->key, map_neutral, sizeof(map_neutral) / 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(char));
c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t));
else
c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(char));
c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t));
 
if (c != 0) return c;
if (c != 0)
return c;
 
if ((ev->mods & KM_SHIFT) != 0)
c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(char));
c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t));
else
c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(char));
c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t));
 
if (c != 0) return c;
if (c != 0)
return c;
 
if ((ev->mods & KM_NUM_LOCK) != 0)
c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(char));
c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t));
else
c = 0;
 
/branches/network/uspace/srv/kbd/layout/cz.c
0,0 → 1,248
/*
* Copyright (c) 2009 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup kbd
* @brief US QWERTY leyout.
* @{
*/
 
#include <kbd.h>
#include <kbd/kbd.h>
#include <kbd/keycode.h>
#include <layout.h>
 
static wchar_t layout_parse_ev(kbd_event_t *ev);
 
layout_op_t cz_op = {
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',
[KC_R] = 'r',
[KC_T] = 't',
[KC_Y] = 'z',
[KC_U] = 'u',
[KC_I] = 'i',
[KC_O] = 'o',
[KC_P] = 'p',
 
[KC_A] = 'a',
[KC_S] = 's',
[KC_D] = 'd',
[KC_F] = 'f',
[KC_G] = 'g',
[KC_H] = 'h',
[KC_J] = 'j',
[KC_K] = 'k',
[KC_L] = 'l',
 
[KC_Z] = 'y',
[KC_X] = 'x',
[KC_C] = 'c',
[KC_V] = 'v',
[KC_B] = 'b',
[KC_N] = 'n',
[KC_M] = 'm',
};
 
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',
[KC_R] = 'R',
[KC_T] = 'T',
[KC_Y] = 'Z',
[KC_U] = 'U',
[KC_I] = 'I',
[KC_O] = 'O',
[KC_P] = 'P',
 
[KC_A] = 'A',
[KC_S] = 'S',
[KC_D] = 'D',
[KC_F] = 'F',
[KC_G] = 'G',
[KC_H] = 'H',
[KC_J] = 'J',
[KC_K] = 'K',
[KC_L] = 'L',
 
[KC_Z] = 'Y',
[KC_X] = 'X',
[KC_C] = 'C',
[KC_V] = 'V',
[KC_B] = 'B',
[KC_N] = 'N',
[KC_M] = 'M',
};
 
static wchar_t map_not_shifted[] = {
[KC_BACKTICK] = ';',
 
[KC_1] = '+',
 
[KC_MINUS] = '=',
 
[KC_RBRACKET] = ')',
 
[KC_QUOTE] = L'§',
 
[KC_COMMA] = ',',
[KC_PERIOD] = '.',
[KC_SLASH] = '-',
};
 
static wchar_t map_shifted[] = {
[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_LBRACKET] = '/',
[KC_RBRACKET] = '(',
 
[KC_SEMICOLON] = '"',
[KC_QUOTE] = '!',
[KC_BACKSLASH] = '\'',
 
[KC_COMMA] = '?',
[KC_PERIOD] = ':',
[KC_SLASH] = '_',
};
 
static wchar_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 wchar_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 wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
{
if (key >= map_length)
return 0;
return map[key];
}
 
static wchar_t layout_parse_ev(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;
 
c = translate(ev->key, map_neutral, sizeof(map_neutral) / 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
c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t));
 
if (c != 0)
return c;
 
if ((ev->mods & KM_SHIFT) != 0)
c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t));
else
c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t));
 
if (c != 0)
return c;
 
if ((ev->mods & KM_NUM_LOCK) != 0)
c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t));
else
c = 0;
 
return c;
}
 
/**
* @}
*/
/branches/network/uspace/srv/kbd/layout/us_dvorak.c
36,7 → 36,13
#include <kbd/keycode.h>
#include <layout.h>
 
static char map_lcase[] = {
static wchar_t layout_parse_ev(kbd_event_t *ev);
 
layout_op_t us_dvorak_op = {
layout_parse_ev
};
 
static wchar_t map_lcase[] = {
[KC_R] = 'p',
[KC_T] = 'y',
[KC_Y] = 'f',
69,7 → 75,7
[KC_SLASH] = 'z',
};
 
static char map_ucase[] = {
static wchar_t map_ucase[] = {
[KC_R] = 'P',
[KC_T] = 'Y',
[KC_Y] = 'F',
102,7 → 108,7
[KC_SLASH] = 'Z',
};
 
static char map_not_shifted[] = {
static wchar_t map_not_shifted[] = {
[KC_BACKTICK] = '`',
 
[KC_1] = '1',
132,7 → 138,7
[KC_Z] = ';',
};
 
static char map_shifted[] = {
static wchar_t map_shifted[] = {
[KC_BACKTICK] = '~',
 
[KC_1] = '!',
162,7 → 168,7
[KC_Z] = ':',
};
 
static char map_neutral[] = {
static wchar_t map_neutral[] = {
[KC_BACKSPACE] = '\b',
[KC_TAB] = '\t',
[KC_ENTER] = '\n',
175,7 → 181,7
[KC_NENTER] = '\n'
};
 
static char map_numeric[] = {
static wchar_t map_numeric[] = {
[KC_N7] = '7',
[KC_N8] = '8',
[KC_N9] = '9',
190,7 → 196,7
[KC_NPERIOD] = '.'
};
 
static int translate(unsigned int key, char *map, size_t map_length)
static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
{
if (key >= map_length)
return 0;
197,36 → 203,36
return map[key];
}
 
char layout_parse_ev(kbd_event_t *ev)
static wchar_t layout_parse_ev(kbd_event_t *ev)
{
char c;
wchar_t c;
 
/* Produce no characters when Ctrl or Alt is pressed. */
if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
return 0;
 
c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(char));
c = translate(ev->key, map_neutral, sizeof(map_neutral) / 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(char));
c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t));
else
c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(char));
c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t));
 
if (c != 0)
return c;
 
if ((ev->mods & KM_SHIFT) != 0)
c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(char));
c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t));
else
c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(char));
c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t));
 
if (c != 0)
return c;
 
if ((ev->mods & KM_NUM_LOCK) != 0)
c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(char));
c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t));
else
c = 0;