Subversion Repositories HelenOS

Rev

Rev 4153 | Rev 4327 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4153 Rev 4263
Line 34... Line 34...
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',
Line 65... Line 71...
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',
Line 96... Line 102...
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',
Line 125... Line 131...
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] = '#',
Line 154... Line 160...
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
 
Line 167... Line 173...
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',
Line 182... Line 188...
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
}