Subversion Repositories HelenOS

Rev

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

Rev 3923 Rev 3933
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 int map_normal[] = {
39
static char map_lcase[] = {
40
    [KC_BACKTICK] = '`',
-
 
41
 
-
 
42
    [KC_1] = '1',
-
 
43
    [KC_2] = '2',
-
 
44
    [KC_3] = '3',
-
 
45
    [KC_4] = '4',
-
 
46
    [KC_5] = '5',
-
 
47
    [KC_6] = '6',
-
 
48
    [KC_7] = '7',
-
 
49
    [KC_8] = '8',
-
 
50
    [KC_9] = '9',
-
 
51
    [KC_0] = '0',
-
 
52
 
-
 
53
    [KC_MINUS] = '-',
-
 
54
    [KC_EQUALS] = '=',
-
 
55
    [KC_BACKSPACE] = '\b',
-
 
56
 
-
 
57
    [KC_TAB] = '\t',
-
 
58
 
-
 
59
    [KC_Q] = 'q',
40
    [KC_Q] = 'q',
60
    [KC_W] = 'w',
41
    [KC_W] = 'w',
61
    [KC_E] = 'e',
42
    [KC_E] = 'e',
62
    [KC_R] = 'r',
43
    [KC_R] = 'r',
63
    [KC_T] = 't',
44
    [KC_T] = 't',
Line 65... Line 46...
65
    [KC_U] = 'u',
46
    [KC_U] = 'u',
66
    [KC_I] = 'i',
47
    [KC_I] = 'i',
67
    [KC_O] = 'o',
48
    [KC_O] = 'o',
68
    [KC_P] = 'p',
49
    [KC_P] = 'p',
69
 
50
 
70
    [KC_LBRACKET] = '[',
-
 
71
    [KC_RBRACKET] = ']',
-
 
72
 
-
 
73
    [KC_A] = 'a',
51
    [KC_A] = 'a',
74
    [KC_S] = 's',
52
    [KC_S] = 's',
75
    [KC_D] = 'd',
53
    [KC_D] = 'd',
76
    [KC_F] = 'f',
54
    [KC_F] = 'f',
77
    [KC_G] = 'g',
55
    [KC_G] = 'g',
78
    [KC_H] = 'h',
56
    [KC_H] = 'h',
79
    [KC_J] = 'j',
57
    [KC_J] = 'j',
80
    [KC_K] = 'k',
58
    [KC_K] = 'k',
81
    [KC_L] = 'l',
59
    [KC_L] = 'l',
82
 
60
 
83
    [KC_SEMICOLON] = ';',
-
 
84
    [KC_QUOTE] = '\'',
-
 
85
    [KC_BACKSLASH] = '\\',
-
 
86
    [KC_ENTER] = '\n',
-
 
87
 
-
 
88
    [KC_Z] = 'z',
61
    [KC_Z] = 'z',
89
    [KC_X] = 'x',
62
    [KC_X] = 'x',
90
    [KC_C] = 'c',
63
    [KC_C] = 'c',
91
    [KC_V] = 'v',
64
    [KC_V] = 'v',
92
    [KC_B] = 'b',
65
    [KC_B] = 'b',
93
    [KC_N] = 'n',
66
    [KC_N] = 'n',
94
    [KC_M] = 'm',
67
    [KC_M] = 'm',
-
 
68
};
-
 
69
 
-
 
70
static char map_ucase[] = {
-
 
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
 
-
 
101
static char map_not_shifted[] = {
-
 
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] = '\\',
95
 
124
 
96
    [KC_COMMA] = ',',
125
    [KC_COMMA] = ',',
97
    [KC_PERIOD] = '.',
126
    [KC_PERIOD] = '.',
98
    [KC_SLASH] = '/',
127
    [KC_SLASH] = '/',
-
 
128
};
-
 
129
 
-
 
130
static char map_shifted[] = {
-
 
131
    [KC_BACKTICK] = '~',
99
 
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
 
-
 
159
static char map_neutral[] = {
-
 
160
    [KC_BACKSPACE] = '\b',
-
 
161
    [KC_TAB] = '\t',
-
 
162
    [KC_ENTER] = '\n',
100
    [KC_SPACE] = ' '
163
    [KC_SPACE] = ' '
101
};
164
};
102
 
165
 
-
 
166
static int translate(unsigned int key, char *map, size_t map_length)
-
 
167
{
-
 
168
    if (key >= map_length) return 0;
-
 
169
    return map[key];   
-
 
170
}
-
 
171
 
103
char layout_parse_ev(kbd_event_t *ev)
172
char layout_parse_ev(kbd_event_t *ev)
104
{
173
{
-
 
174
    char c;
-
 
175
 
-
 
176
    /* Produce no characters when Ctrl or Alt is pressed. */
105
    if (ev->key >= sizeof(map_normal) / sizeof(int))
177
    if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
106
        return 0;
178
        return 0;
107
 
179
 
-
 
180
    c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(char));
-
 
181
    if (c != 0) return c;
-
 
182
 
-
 
183
    if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
-
 
184
        c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(char));
-
 
185
    else
-
 
186
        c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(char));
-
 
187
 
108
    return map_normal[ev->key];
188
    if (c != 0) return c;
-
 
189
 
-
 
190
    if ((ev->mods & KM_SHIFT) != 0)
-
 
191
        c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(char));
-
 
192
    else
-
 
193
        c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(char));
-
 
194
 
-
 
195
    if (c != 0 ) return c;
-
 
196
 
109
}
197
}
110
 
198
 
111
/**
199
/**
112
 * @}
200
 * @}
113
 */
201
 */