Rev 4345 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4345 | 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_dvorak_op = { |
|
- | 43 | layout_reset, |
|
- | 44 | layout_parse_ev |
|
- | 45 | }; |
|
- | 46 | ||
39 | static char map_lcase[] = { |
47 | static wchar_t map_lcase[] = { |
40 | [KC_R] = 'p', |
48 | [KC_R] = 'p', |
41 | [KC_T] = 'y', |
49 | [KC_T] = 'y', |
42 | [KC_Y] = 'f', |
50 | [KC_Y] = 'f', |
43 | [KC_U] = 'g', |
51 | [KC_U] = 'g', |
44 | [KC_I] = 'c', |
52 | [KC_I] = 'c', |
Line 67... | Line 75... | ||
67 | [KC_COMMA] = 'w', |
75 | [KC_COMMA] = 'w', |
68 | [KC_PERIOD] = 'v', |
76 | [KC_PERIOD] = 'v', |
69 | [KC_SLASH] = 'z', |
77 | [KC_SLASH] = 'z', |
70 | }; |
78 | }; |
71 | 79 | ||
72 | static char map_ucase[] = { |
80 | static wchar_t map_ucase[] = { |
73 | [KC_R] = 'P', |
81 | [KC_R] = 'P', |
74 | [KC_T] = 'Y', |
82 | [KC_T] = 'Y', |
75 | [KC_Y] = 'F', |
83 | [KC_Y] = 'F', |
76 | [KC_U] = 'G', |
84 | [KC_U] = 'G', |
77 | [KC_I] = 'C', |
85 | [KC_I] = 'C', |
Line 100... | Line 108... | ||
100 | [KC_COMMA] = 'W', |
108 | [KC_COMMA] = 'W', |
101 | [KC_PERIOD] = 'V', |
109 | [KC_PERIOD] = 'V', |
102 | [KC_SLASH] = 'Z', |
110 | [KC_SLASH] = 'Z', |
103 | }; |
111 | }; |
104 | 112 | ||
105 | static char map_not_shifted[] = { |
113 | static wchar_t map_not_shifted[] = { |
106 | [KC_BACKTICK] = '`', |
114 | [KC_BACKTICK] = '`', |
107 | 115 | ||
108 | [KC_1] = '1', |
116 | [KC_1] = '1', |
109 | [KC_2] = '2', |
117 | [KC_2] = '2', |
110 | [KC_3] = '3', |
118 | [KC_3] = '3', |
Line 130... | Line 138... | ||
130 | [KC_BACKSLASH] = '\\', |
138 | [KC_BACKSLASH] = '\\', |
131 | 139 | ||
132 | [KC_Z] = ';', |
140 | [KC_Z] = ';', |
133 | }; |
141 | }; |
134 | 142 | ||
135 | static char map_shifted[] = { |
143 | static wchar_t map_shifted[] = { |
136 | [KC_BACKTICK] = '~', |
144 | [KC_BACKTICK] = '~', |
137 | 145 | ||
138 | [KC_1] = '!', |
146 | [KC_1] = '!', |
139 | [KC_2] = '@', |
147 | [KC_2] = '@', |
140 | [KC_3] = '#', |
148 | [KC_3] = '#', |
Line 160... | Line 168... | ||
160 | [KC_BACKSLASH] = '|', |
168 | [KC_BACKSLASH] = '|', |
161 | 169 | ||
162 | [KC_Z] = ':', |
170 | [KC_Z] = ':', |
163 | }; |
171 | }; |
164 | 172 | ||
165 | static char map_neutral[] = { |
173 | static wchar_t map_neutral[] = { |
166 | [KC_BACKSPACE] = '\b', |
174 | [KC_BACKSPACE] = '\b', |
167 | [KC_TAB] = '\t', |
175 | [KC_TAB] = '\t', |
168 | [KC_ENTER] = '\n', |
176 | [KC_ENTER] = '\n', |
169 | [KC_SPACE] = ' ', |
177 | [KC_SPACE] = ' ', |
170 | 178 | ||
Line 173... | Line 181... | ||
173 | [KC_NMINUS] = '-', |
181 | [KC_NMINUS] = '-', |
174 | [KC_NPLUS] = '+', |
182 | [KC_NPLUS] = '+', |
175 | [KC_NENTER] = '\n' |
183 | [KC_NENTER] = '\n' |
176 | }; |
184 | }; |
177 | 185 | ||
178 | static char map_numeric[] = { |
186 | static wchar_t map_numeric[] = { |
179 | [KC_N7] = '7', |
187 | [KC_N7] = '7', |
180 | [KC_N8] = '8', |
188 | [KC_N8] = '8', |
181 | [KC_N9] = '9', |
189 | [KC_N9] = '9', |
182 | [KC_N4] = '4', |
190 | [KC_N4] = '4', |
183 | [KC_N5] = '5', |
191 | [KC_N5] = '5', |
Line 188... | Line 196... | ||
188 | 196 | ||
189 | [KC_N0] = '0', |
197 | [KC_N0] = '0', |
190 | [KC_NPERIOD] = '.' |
198 | [KC_NPERIOD] = '.' |
191 | }; |
199 | }; |
192 | 200 | ||
193 | static int translate(unsigned int key, char *map, size_t map_length) |
201 | static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length) |
194 | { |
202 | { |
195 | if (key >= map_length) |
203 | if (key >= map_length) |
196 | return 0; |
204 | return 0; |
197 | return map[key]; |
205 | return map[key]; |
198 | } |
206 | } |
199 | 207 | ||
- | 208 | static void layout_reset(void) |
|
- | 209 | { |
|
- | 210 | } |
|
- | 211 | ||
200 | char layout_parse_ev(kbd_event_t *ev) |
212 | static wchar_t layout_parse_ev(kbd_event_t *ev) |
201 | { |
213 | { |
202 | char c; |
214 | wchar_t c; |
203 | 215 | ||
204 | /* Produce no characters when Ctrl or Alt is pressed. */ |
216 | /* Produce no characters when Ctrl or Alt is pressed. */ |
205 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
217 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
206 | return 0; |
218 | return 0; |
207 | 219 | ||
208 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(char)); |
220 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t)); |
209 | if (c != 0) |
221 | if (c != 0) |
210 | return c; |
222 | return c; |
211 | 223 | ||
212 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
224 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
213 | c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(char)); |
225 | c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t)); |
214 | else |
226 | else |
215 | c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(char)); |
227 | c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t)); |
216 | 228 | ||
217 | if (c != 0) |
229 | if (c != 0) |
218 | return c; |
230 | return c; |
219 | 231 | ||
220 | if ((ev->mods & KM_SHIFT) != 0) |
232 | if ((ev->mods & KM_SHIFT) != 0) |
221 | c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(char)); |
233 | c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t)); |
222 | else |
234 | else |
223 | c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(char)); |
235 | c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t)); |
224 | 236 | ||
225 | if (c != 0) |
237 | if (c != 0) |
226 | return c; |
238 | return c; |
227 | 239 | ||
228 | if ((ev->mods & KM_NUM_LOCK) != 0) |
240 | if ((ev->mods & KM_NUM_LOCK) != 0) |
229 | c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(char)); |
241 | c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t)); |
230 | else |
242 | else |
231 | c = 0; |
243 | c = 0; |
232 | 244 | ||
233 | return c; |
245 | return c; |
234 | } |
246 | } |