Rev 4036 | Rev 4240 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4036 | 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_R] = 'p', |
40 | [KC_R] = 'p', |
| 41 | [KC_T] = 'y', |
41 | [KC_T] = 'y', |
| 42 | [KC_Y] = 'f', |
42 | [KC_Y] = 'f', |
| 43 | [KC_U] = 'g', |
43 | [KC_U] = 'g', |
| 44 | [KC_I] = 'c', |
44 | [KC_I] = 'c', |
| Line 67... | Line 67... | ||
| 67 | [KC_COMMA] = 'w', |
67 | [KC_COMMA] = 'w', |
| 68 | [KC_PERIOD] = 'v', |
68 | [KC_PERIOD] = 'v', |
| 69 | [KC_SLASH] = 'z', |
69 | [KC_SLASH] = 'z', |
| 70 | }; |
70 | }; |
| 71 | 71 | ||
| 72 | static char map_ucase[] = { |
72 | static wchar_t map_ucase[] = { |
| 73 | [KC_R] = 'P', |
73 | [KC_R] = 'P', |
| 74 | [KC_T] = 'Y', |
74 | [KC_T] = 'Y', |
| 75 | [KC_Y] = 'F', |
75 | [KC_Y] = 'F', |
| 76 | [KC_U] = 'G', |
76 | [KC_U] = 'G', |
| 77 | [KC_I] = 'C', |
77 | [KC_I] = 'C', |
| Line 100... | Line 100... | ||
| 100 | [KC_COMMA] = 'W', |
100 | [KC_COMMA] = 'W', |
| 101 | [KC_PERIOD] = 'V', |
101 | [KC_PERIOD] = 'V', |
| 102 | [KC_SLASH] = 'Z', |
102 | [KC_SLASH] = 'Z', |
| 103 | }; |
103 | }; |
| 104 | 104 | ||
| 105 | static char map_not_shifted[] = { |
105 | static wchar_t map_not_shifted[] = { |
| 106 | [KC_BACKTICK] = '`', |
106 | [KC_BACKTICK] = '`', |
| 107 | 107 | ||
| 108 | [KC_1] = '1', |
108 | [KC_1] = '1', |
| 109 | [KC_2] = '2', |
109 | [KC_2] = '2', |
| 110 | [KC_3] = '3', |
110 | [KC_3] = '3', |
| Line 130... | Line 130... | ||
| 130 | [KC_BACKSLASH] = '\\', |
130 | [KC_BACKSLASH] = '\\', |
| 131 | 131 | ||
| 132 | [KC_Z] = ';', |
132 | [KC_Z] = ';', |
| 133 | }; |
133 | }; |
| 134 | 134 | ||
| 135 | static char map_shifted[] = { |
135 | static wchar_t map_shifted[] = { |
| 136 | [KC_BACKTICK] = '~', |
136 | [KC_BACKTICK] = '~', |
| 137 | 137 | ||
| 138 | [KC_1] = '!', |
138 | [KC_1] = '!', |
| 139 | [KC_2] = '@', |
139 | [KC_2] = '@', |
| 140 | [KC_3] = '#', |
140 | [KC_3] = '#', |
| Line 160... | Line 160... | ||
| 160 | [KC_BACKSLASH] = '|', |
160 | [KC_BACKSLASH] = '|', |
| 161 | 161 | ||
| 162 | [KC_Z] = ':', |
162 | [KC_Z] = ':', |
| 163 | }; |
163 | }; |
| 164 | 164 | ||
| 165 | static char map_neutral[] = { |
165 | static wchar_t map_neutral[] = { |
| 166 | [KC_BACKSPACE] = '\b', |
166 | [KC_BACKSPACE] = '\b', |
| 167 | [KC_TAB] = '\t', |
167 | [KC_TAB] = '\t', |
| 168 | [KC_ENTER] = '\n', |
168 | [KC_ENTER] = '\n', |
| 169 | [KC_SPACE] = ' ', |
169 | [KC_SPACE] = ' ', |
| 170 | 170 | ||
| Line 173... | Line 173... | ||
| 173 | [KC_NMINUS] = '-', |
173 | [KC_NMINUS] = '-', |
| 174 | [KC_NPLUS] = '+', |
174 | [KC_NPLUS] = '+', |
| 175 | [KC_NENTER] = '\n' |
175 | [KC_NENTER] = '\n' |
| 176 | }; |
176 | }; |
| 177 | 177 | ||
| 178 | static char map_numeric[] = { |
178 | static wchar_t map_numeric[] = { |
| 179 | [KC_N7] = '7', |
179 | [KC_N7] = '7', |
| 180 | [KC_N8] = '8', |
180 | [KC_N8] = '8', |
| 181 | [KC_N9] = '9', |
181 | [KC_N9] = '9', |
| 182 | [KC_N4] = '4', |
182 | [KC_N4] = '4', |
| 183 | [KC_N5] = '5', |
183 | [KC_N5] = '5', |
| Line 188... | Line 188... | ||
| 188 | 188 | ||
| 189 | [KC_N0] = '0', |
189 | [KC_N0] = '0', |
| 190 | [KC_NPERIOD] = '.' |
190 | [KC_NPERIOD] = '.' |
| 191 | }; |
191 | }; |
| 192 | 192 | ||
| 193 | 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) |
| 194 | { |
194 | { |
| 195 | if (key >= map_length) |
195 | if (key >= map_length) |
| 196 | return 0; |
196 | return 0; |
| 197 | return map[key]; |
197 | return map[key]; |
| 198 | } |
198 | } |
| 199 | 199 | ||
| 200 | char layout_parse_ev(kbd_event_t *ev) |
200 | wchar_t layout_parse_ev(kbd_event_t *ev) |
| 201 | { |
201 | { |
| 202 | char c; |
202 | wchar_t c; |
| 203 | 203 | ||
| 204 | /* Produce no characters when Ctrl or Alt is pressed. */ |
204 | /* Produce no characters when Ctrl or Alt is pressed. */ |
| 205 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
205 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
| 206 | return 0; |
206 | return 0; |
| 207 | 207 | ||
| 208 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(char)); |
208 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t)); |
| 209 | if (c != 0) |
209 | if (c != 0) |
| 210 | return c; |
210 | return c; |
| 211 | 211 | ||
| 212 | 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)) |
| 213 | c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(char)); |
213 | c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t)); |
| 214 | else |
214 | else |
| 215 | c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(char)); |
215 | c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t)); |
| 216 | 216 | ||
| 217 | if (c != 0) |
217 | if (c != 0) |
| 218 | return c; |
218 | return c; |
| 219 | 219 | ||
| 220 | if ((ev->mods & KM_SHIFT) != 0) |
220 | if ((ev->mods & KM_SHIFT) != 0) |
| 221 | c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(char)); |
221 | c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t)); |
| 222 | else |
222 | else |
| 223 | 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)); |
| 224 | 224 | ||
| 225 | if (c != 0) |
225 | if (c != 0) |
| 226 | return c; |
226 | return c; |
| 227 | 227 | ||
| 228 | if ((ev->mods & KM_NUM_LOCK) != 0) |
228 | if ((ev->mods & KM_NUM_LOCK) != 0) |
| 229 | c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(char)); |
229 | c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t)); |
| 230 | else |
230 | else |
| 231 | c = 0; |
231 | c = 0; |
| 232 | 232 | ||
| 233 | return c; |
233 | return c; |
| 234 | } |
234 | } |