Subversion Repositories HelenOS

Rev

Rev 4239 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4237 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
 
39
static wchar_t map_lcase[] = {
40
    [KC_2] = 'ě',
41
    [KC_3] = 'š',
42
    [KC_4] = 'č',
43
    [KC_5] = 'ř',
44
    [KC_6] = 'ž',
45
    [KC_7] = 'ý',
46
    [KC_8] = 'á',
47
    [KC_9] = 'í',
48
    [KC_0] = 'é',
49
 
50
    [KC_LBRACKET] = 'ú',
51
    [KC_SEMICOLON] = 'ů',
52
 
53
    [KC_Q] = 'q',
54
    [KC_W] = 'w',
55
    [KC_E] = 'e',
56
    [KC_R] = 'r',
57
    [KC_T] = 't',
58
    [KC_Y] = 'z',
59
    [KC_U] = 'u',
60
    [KC_I] = 'i',
61
    [KC_O] = 'o',
62
    [KC_P] = 'p',
63
 
64
    [KC_A] = 'a',
65
    [KC_S] = 's',
66
    [KC_D] = 'd',
67
    [KC_F] = 'f',
68
    [KC_G] = 'g',
69
    [KC_H] = 'h',
70
    [KC_J] = 'j',
71
    [KC_K] = 'k',
72
    [KC_L] = 'l',
73
 
74
    [KC_Z] = 'y',
75
    [KC_X] = 'x',
76
    [KC_C] = 'c',
77
    [KC_V] = 'v',
78
    [KC_B] = 'b',
79
    [KC_N] = 'n',
80
    [KC_M] = 'm',
81
};
82
 
83
static wchar_t map_ucase[] = {
84
    [KC_2] = 'Ě',
85
    [KC_3] = 'Š',
86
    [KC_4] = 'Č',
87
    [KC_5] = 'Ř',
88
    [KC_6] = 'Ž',
89
    [KC_7] = 'Ý',
90
    [KC_8] = 'Á',
91
    [KC_9] = 'Í',
92
    [KC_0] = 'É',
93
 
94
    [KC_LBRACKET] = 'Ú',
95
    [KC_SEMICOLON] = 'Ů',
96
 
97
    [KC_Q] = 'Q',
98
    [KC_W] = 'W',
99
    [KC_E] = 'E',
100
    [KC_R] = 'R',
101
    [KC_T] = 'T',
102
    [KC_Y] = 'Z',
103
    [KC_U] = 'U',
104
    [KC_I] = 'I',
105
    [KC_O] = 'O',
106
    [KC_P] = 'P',
107
 
108
    [KC_A] = 'A',
109
    [KC_S] = 'S',
110
    [KC_D] = 'D',
111
    [KC_F] = 'F',
112
    [KC_G] = 'G',
113
    [KC_H] = 'H',
114
    [KC_J] = 'J',
115
    [KC_K] = 'K',
116
    [KC_L] = 'L',
117
 
118
    [KC_Z] = 'Y',
119
    [KC_X] = 'X',
120
    [KC_C] = 'C',
121
    [KC_V] = 'V',
122
    [KC_B] = 'B',
123
    [KC_N] = 'N',
124
    [KC_M] = 'M',
125
};
126
 
127
static wchar_t map_not_shifted[] = {
128
    [KC_BACKTICK] = ';',
129
 
130
    [KC_1] = '+',
131
 
132
    [KC_MINUS] = '=',
133
 
134
    [KC_RBRACKET] = ')',
135
 
136
    [KC_QUOTE] = '§',
137
 
138
    [KC_COMMA] = ',',
139
    [KC_PERIOD] = '.',
140
    [KC_SLASH] = '-',
141
};
142
 
143
static wchar_t map_shifted[] = {
144
    [KC_1] = '1',
145
    [KC_2] = '2',
146
    [KC_3] = '3',
147
    [KC_4] = '4',
148
    [KC_5] = '5',
149
    [KC_6] = '6',
150
    [KC_7] = '7',
151
    [KC_8] = '8',
152
    [KC_9] = '9',
153
    [KC_0] = '0',
154
 
155
    [KC_MINUS] = '%',
156
 
157
    [KC_LBRACKET] = '/',
158
    [KC_RBRACKET] = '(',
159
 
160
    [KC_SEMICOLON] = '"',
161
    [KC_QUOTE] = '!',
162
    [KC_BACKSLASH] = '\'',
163
 
164
    [KC_COMMA] = '?',
165
    [KC_PERIOD] = ':',
166
    [KC_SLASH] = '_',
167
};
168
 
169
static wchar_t map_neutral[] = {
170
    [KC_BACKSPACE] = '\b',
171
    [KC_TAB] = '\t',
172
    [KC_ENTER] = '\n',
173
    [KC_SPACE] = ' ',
174
 
175
    [KC_NSLASH] = '/',
176
    [KC_NTIMES] = '*',
177
    [KC_NMINUS] = '-',
178
    [KC_NPLUS] = '+',
179
    [KC_NENTER] = '\n'
180
};
181
 
182
static wchar_t map_numeric[] = {
183
    [KC_N7] = '7',
184
    [KC_N8] = '8',
185
    [KC_N9] = '9',
186
    [KC_N4] = '4',
187
    [KC_N5] = '5',
188
    [KC_N6] = '6',
189
    [KC_N1] = '1',
190
    [KC_N2] = '2',
191
    [KC_N3] = '3',
192
 
193
    [KC_N0] = '0',
194
    [KC_NPERIOD] = '.'
195
};
196
 
197
static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
198
{
199
    if (key >= map_length)
200
        return 0;
201
    return map[key];
202
}
203
 
204
wchar_t layout_parse_ev(kbd_event_t *ev)
205
{
206
    wchar_t c;
207
 
208
    /* Produce no characters when Ctrl or Alt is pressed. */
209
    if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
210
        return 0;
211
 
212
    c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t));
213
    if (c != 0)
214
        return c;
215
 
216
    if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
217
        c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t));
218
    else
219
        c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t));
220
 
221
    if (c != 0)
222
        return c;
223
 
224
    if ((ev->mods & KM_SHIFT) != 0)
225
        c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t));
226
    else
227
        c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t));
228
 
229
    if (c != 0)
230
        return c;
231
 
232
    if ((ev->mods & KM_NUM_LOCK) != 0)
233
        c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t));
234
    else
235
        c = 0;
236
 
237
    return c;
238
}
239
 
240
/**
241
 * @}
242
 */