Subversion Repositories HelenOS

Rev

Rev 3942 | Rev 4240 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3923 svoboda 1
/*
2
 * Copyright (c) 2009 Jiri Svoboda
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
29
/** @addtogroup kbd
30
 * @brief   US QWERTY leyout.
31
 * @{
32
 */
33
 
34
#include <kbd.h>
35
#include <kbd/kbd.h>
36
#include <kbd/keycode.h>
37
#include <layout.h>
38
 
4236 svoboda 39
static wchar_t map_lcase[] = {
3923 svoboda 40
    [KC_Q] = 'q',
41
    [KC_W] = 'w',
42
    [KC_E] = 'e',
43
    [KC_R] = 'r',
44
    [KC_T] = 't',
45
    [KC_Y] = 'y',
46
    [KC_U] = 'u',
47
    [KC_I] = 'i',
48
    [KC_O] = 'o',
49
    [KC_P] = 'p',
50
 
51
    [KC_A] = 'a',
52
    [KC_S] = 's',
53
    [KC_D] = 'd',
54
    [KC_F] = 'f',
55
    [KC_G] = 'g',
56
    [KC_H] = 'h',
57
    [KC_J] = 'j',
58
    [KC_K] = 'k',
59
    [KC_L] = 'l',
60
 
61
    [KC_Z] = 'z',
62
    [KC_X] = 'x',
63
    [KC_C] = 'c',
64
    [KC_V] = 'v',
65
    [KC_B] = 'b',
66
    [KC_N] = 'n',
67
    [KC_M] = 'm',
3933 svoboda 68
};
3923 svoboda 69
 
4236 svoboda 70
static wchar_t map_ucase[] = {
3933 svoboda 71
    [KC_Q] = 'Q',
72
    [KC_W] = 'W',
73
    [KC_E] = 'E',
74
    [KC_R] = 'R',
75
    [KC_T] = 'T',
76
    [KC_Y] = 'Y',
77
    [KC_U] = 'U',
78
    [KC_I] = 'I',
79
    [KC_O] = 'O',
80
    [KC_P] = 'P',
81
 
82
    [KC_A] = 'A',
83
    [KC_S] = 'S',
84
    [KC_D] = 'D',
85
    [KC_F] = 'F',
86
    [KC_G] = 'G',
87
    [KC_H] = 'H',
88
    [KC_J] = 'J',
89
    [KC_K] = 'K',
90
    [KC_L] = 'L',
91
 
92
    [KC_Z] = 'Z',
93
    [KC_X] = 'X',
94
    [KC_C] = 'C',
95
    [KC_V] = 'V',
96
    [KC_B] = 'B',
97
    [KC_N] = 'N',
98
    [KC_M] = 'M',
99
};
100
 
4236 svoboda 101
static wchar_t map_not_shifted[] = {
3933 svoboda 102
    [KC_BACKTICK] = '`',
103
 
104
    [KC_1] = '1',
105
    [KC_2] = '2',
106
    [KC_3] = '3',
107
    [KC_4] = '4',
108
    [KC_5] = '5',
109
    [KC_6] = '6',
110
    [KC_7] = '7',
111
    [KC_8] = '8',
112
    [KC_9] = '9',
113
    [KC_0] = '0',
114
 
115
    [KC_MINUS] = '-',
116
    [KC_EQUALS] = '=',
117
 
118
    [KC_LBRACKET] = '[',
119
    [KC_RBRACKET] = ']',
120
 
121
    [KC_SEMICOLON] = ';',
122
    [KC_QUOTE] = '\'',
123
    [KC_BACKSLASH] = '\\',
124
 
3923 svoboda 125
    [KC_COMMA] = ',',
126
    [KC_PERIOD] = '.',
127
    [KC_SLASH] = '/',
3933 svoboda 128
};
3923 svoboda 129
 
4236 svoboda 130
static wchar_t map_shifted[] = {
3933 svoboda 131
    [KC_BACKTICK] = '~',
132
 
133
    [KC_1] = '!',
134
    [KC_2] = '@',
135
    [KC_3] = '#',
136
    [KC_4] = '$',
137
    [KC_5] = '%',
138
    [KC_6] = '^',
139
    [KC_7] = '&',
140
    [KC_8] = '*',
141
    [KC_9] = '(',
142
    [KC_0] = ')',
143
 
144
    [KC_MINUS] = '_',
145
    [KC_EQUALS] = '+',
146
 
147
    [KC_LBRACKET] = '{',
148
    [KC_RBRACKET] = '}',
149
 
150
    [KC_SEMICOLON] = ':',
151
    [KC_QUOTE] = '"',
152
    [KC_BACKSLASH] = '|',
153
 
154
    [KC_COMMA] = '<',
155
    [KC_PERIOD] = '>',
156
    [KC_SLASH] = '?',
157
};
158
 
4236 svoboda 159
static wchar_t map_neutral[] = {
3933 svoboda 160
    [KC_BACKSPACE] = '\b',
161
    [KC_TAB] = '\t',
162
    [KC_ENTER] = '\n',
3942 svoboda 163
    [KC_SPACE] = ' ',
164
 
165
    [KC_NSLASH] = '/',
166
    [KC_NTIMES] = '*',
167
    [KC_NMINUS] = '-',
168
    [KC_NPLUS] = '+',
169
    [KC_NENTER] = '\n'
3923 svoboda 170
};
171
 
4236 svoboda 172
static wchar_t map_numeric[] = {
3942 svoboda 173
    [KC_N7] = '7',
174
    [KC_N8] = '8',
175
    [KC_N9] = '9',
176
    [KC_N4] = '4',
177
    [KC_N5] = '5',
178
    [KC_N6] = '6',
179
    [KC_N1] = '1',
180
    [KC_N2] = '2',
181
    [KC_N3] = '3',
182
 
183
    [KC_N0] = '0',
184
    [KC_NPERIOD] = '.'
185
};
186
 
4236 svoboda 187
static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
3933 svoboda 188
{
4236 svoboda 189
    if (key >= map_length)
190
        return 0;
191
    return map[key];
3933 svoboda 192
}
193
 
4236 svoboda 194
wchar_t layout_parse_ev(kbd_event_t *ev)
3923 svoboda 195
{
4236 svoboda 196
    wchar_t c;
3933 svoboda 197
 
198
    /* Produce no characters when Ctrl or Alt is pressed. */
199
    if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
3923 svoboda 200
        return 0;
201
 
4236 svoboda 202
    c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t));
203
    if (c != 0)
204
        return c;
3933 svoboda 205
 
206
    if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
4236 svoboda 207
        c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t));
3933 svoboda 208
    else
4236 svoboda 209
        c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t));
3933 svoboda 210
 
4236 svoboda 211
    if (c != 0)
212
        return c;
3933 svoboda 213
 
214
    if ((ev->mods & KM_SHIFT) != 0)
4236 svoboda 215
        c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t));
3933 svoboda 216
    else
4236 svoboda 217
        c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t));
3933 svoboda 218
 
4236 svoboda 219
    if (c != 0)
220
        return c;
3933 svoboda 221
 
3942 svoboda 222
    if ((ev->mods & KM_NUM_LOCK) != 0)
4236 svoboda 223
        c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t));
3942 svoboda 224
    else
225
        c = 0;
226
 
227
    return c;
3923 svoboda 228
}
229
 
230
/**
231
 * @}
232
 */