Rev 3942 | Rev 4240 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3942 | Rev 4236 | ||
---|---|---|---|
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 char map_lcase[] = { |
39 | static wchar_t map_lcase[] = { |
40 | [KC_Q] = 'q', |
40 | [KC_Q] = 'q', |
41 | [KC_W] = 'w', |
41 | [KC_W] = 'w', |
42 | [KC_E] = 'e', |
42 | [KC_E] = 'e', |
43 | [KC_R] = 'r', |
43 | [KC_R] = 'r', |
44 | [KC_T] = 't', |
44 | [KC_T] = 't', |
Line 65... | Line 65... | ||
65 | [KC_B] = 'b', |
65 | [KC_B] = 'b', |
66 | [KC_N] = 'n', |
66 | [KC_N] = 'n', |
67 | [KC_M] = 'm', |
67 | [KC_M] = 'm', |
68 | }; |
68 | }; |
69 | 69 | ||
70 | static char map_ucase[] = { |
70 | static wchar_t map_ucase[] = { |
71 | [KC_Q] = 'Q', |
71 | [KC_Q] = 'Q', |
72 | [KC_W] = 'W', |
72 | [KC_W] = 'W', |
73 | [KC_E] = 'E', |
73 | [KC_E] = 'E', |
74 | [KC_R] = 'R', |
74 | [KC_R] = 'R', |
75 | [KC_T] = 'T', |
75 | [KC_T] = 'T', |
Line 96... | Line 96... | ||
96 | [KC_B] = 'B', |
96 | [KC_B] = 'B', |
97 | [KC_N] = 'N', |
97 | [KC_N] = 'N', |
98 | [KC_M] = 'M', |
98 | [KC_M] = 'M', |
99 | }; |
99 | }; |
100 | 100 | ||
101 | static char map_not_shifted[] = { |
101 | static wchar_t map_not_shifted[] = { |
102 | [KC_BACKTICK] = '`', |
102 | [KC_BACKTICK] = '`', |
103 | 103 | ||
104 | [KC_1] = '1', |
104 | [KC_1] = '1', |
105 | [KC_2] = '2', |
105 | [KC_2] = '2', |
106 | [KC_3] = '3', |
106 | [KC_3] = '3', |
Line 125... | Line 125... | ||
125 | [KC_COMMA] = ',', |
125 | [KC_COMMA] = ',', |
126 | [KC_PERIOD] = '.', |
126 | [KC_PERIOD] = '.', |
127 | [KC_SLASH] = '/', |
127 | [KC_SLASH] = '/', |
128 | }; |
128 | }; |
129 | 129 | ||
130 | static char map_shifted[] = { |
130 | static wchar_t map_shifted[] = { |
131 | [KC_BACKTICK] = '~', |
131 | [KC_BACKTICK] = '~', |
132 | 132 | ||
133 | [KC_1] = '!', |
133 | [KC_1] = '!', |
134 | [KC_2] = '@', |
134 | [KC_2] = '@', |
135 | [KC_3] = '#', |
135 | [KC_3] = '#', |
Line 154... | Line 154... | ||
154 | [KC_COMMA] = '<', |
154 | [KC_COMMA] = '<', |
155 | [KC_PERIOD] = '>', |
155 | [KC_PERIOD] = '>', |
156 | [KC_SLASH] = '?', |
156 | [KC_SLASH] = '?', |
157 | }; |
157 | }; |
158 | 158 | ||
159 | static char map_neutral[] = { |
159 | static wchar_t map_neutral[] = { |
160 | [KC_BACKSPACE] = '\b', |
160 | [KC_BACKSPACE] = '\b', |
161 | [KC_TAB] = '\t', |
161 | [KC_TAB] = '\t', |
162 | [KC_ENTER] = '\n', |
162 | [KC_ENTER] = '\n', |
163 | [KC_SPACE] = ' ', |
163 | [KC_SPACE] = ' ', |
164 | 164 | ||
Line 167... | Line 167... | ||
167 | [KC_NMINUS] = '-', |
167 | [KC_NMINUS] = '-', |
168 | [KC_NPLUS] = '+', |
168 | [KC_NPLUS] = '+', |
169 | [KC_NENTER] = '\n' |
169 | [KC_NENTER] = '\n' |
170 | }; |
170 | }; |
171 | 171 | ||
172 | static char map_numeric[] = { |
172 | static wchar_t map_numeric[] = { |
173 | [KC_N7] = '7', |
173 | [KC_N7] = '7', |
174 | [KC_N8] = '8', |
174 | [KC_N8] = '8', |
175 | [KC_N9] = '9', |
175 | [KC_N9] = '9', |
176 | [KC_N4] = '4', |
176 | [KC_N4] = '4', |
177 | [KC_N5] = '5', |
177 | [KC_N5] = '5', |
Line 182... | Line 182... | ||
182 | 182 | ||
183 | [KC_N0] = '0', |
183 | [KC_N0] = '0', |
184 | [KC_NPERIOD] = '.' |
184 | [KC_NPERIOD] = '.' |
185 | }; |
185 | }; |
186 | 186 | ||
187 | static int translate(unsigned int key, char *map, size_t map_length) |
187 | static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length) |
188 | { |
188 | { |
189 | if (key >= map_length) return 0; |
189 | if (key >= map_length) |
- | 190 | return 0; |
|
190 | return map[key]; |
191 | return map[key]; |
191 | } |
192 | } |
192 | 193 | ||
193 | char layout_parse_ev(kbd_event_t *ev) |
194 | wchar_t layout_parse_ev(kbd_event_t *ev) |
194 | { |
195 | { |
195 | char c; |
196 | wchar_t c; |
196 | 197 | ||
197 | /* Produce no characters when Ctrl or Alt is pressed. */ |
198 | /* Produce no characters when Ctrl or Alt is pressed. */ |
198 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
199 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
199 | return 0; |
200 | return 0; |
200 | 201 | ||
201 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(char)); |
202 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t)); |
202 | if (c != 0) return c; |
203 | if (c != 0) |
- | 204 | return c; |
|
203 | 205 | ||
204 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
206 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
205 | c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(char)); |
207 | c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t)); |
206 | else |
208 | else |
207 | c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(char)); |
209 | c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t)); |
208 | 210 | ||
209 | if (c != 0) return c; |
211 | if (c != 0) |
- | 212 | return c; |
|
210 | 213 | ||
211 | if ((ev->mods & KM_SHIFT) != 0) |
214 | if ((ev->mods & KM_SHIFT) != 0) |
212 | c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(char)); |
215 | c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t)); |
213 | else |
216 | else |
214 | c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(char)); |
217 | c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t)); |
215 | 218 | ||
216 | if (c != 0) return c; |
219 | if (c != 0) |
- | 220 | return c; |
|
217 | 221 | ||
218 | if ((ev->mods & KM_NUM_LOCK) != 0) |
222 | if ((ev->mods & KM_NUM_LOCK) != 0) |
219 | c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(char)); |
223 | c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t)); |
220 | else |
224 | else |
221 | c = 0; |
225 | c = 0; |
222 | 226 | ||
223 | return c; |
227 | return c; |
224 | } |
228 | } |