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