Subversion Repositories HelenOS

Rev

Rev 4153 | Rev 4327 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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