Rev 4419 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4419 | Rev 4537 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Jiri Svoboda |
2 | * Copyright (c) 2009 Jiri Svoboda |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup kbd |
29 | /** @addtogroup kbd |
30 | * @brief US Dvorak Simplified Keyboard layout. |
30 | * @brief US Dvorak Simplified Keyboard layout. |
31 | * @{ |
31 | * @{ |
32 | */ |
32 | */ |
33 | 33 | ||
34 | #include <kbd.h> |
34 | #include <kbd.h> |
35 | #include <kbd/kbd.h> |
35 | #include <io/console.h> |
36 | #include <kbd/keycode.h> |
36 | #include <io/keycode.h> |
37 | #include <layout.h> |
37 | #include <layout.h> |
38 | 38 | ||
39 | static void layout_reset(void); |
39 | static void layout_reset(void); |
40 | static wchar_t layout_parse_ev(kbd_event_t *ev); |
40 | static wchar_t layout_parse_ev(console_event_t *ev); |
41 | 41 | ||
42 | layout_op_t us_dvorak_op = { |
42 | layout_op_t us_dvorak_op = { |
43 | layout_reset, |
43 | layout_reset, |
44 | layout_parse_ev |
44 | layout_parse_ev |
45 | }; |
45 | }; |
46 | 46 | ||
47 | static wchar_t map_lcase[] = { |
47 | static wchar_t map_lcase[] = { |
48 | [KC_R] = 'p', |
48 | [KC_R] = 'p', |
49 | [KC_T] = 'y', |
49 | [KC_T] = 'y', |
50 | [KC_Y] = 'f', |
50 | [KC_Y] = 'f', |
51 | [KC_U] = 'g', |
51 | [KC_U] = 'g', |
52 | [KC_I] = 'c', |
52 | [KC_I] = 'c', |
53 | [KC_O] = 'r', |
53 | [KC_O] = 'r', |
54 | [KC_P] = 'l', |
54 | [KC_P] = 'l', |
55 | 55 | ||
56 | [KC_A] = 'a', |
56 | [KC_A] = 'a', |
57 | [KC_S] = 'o', |
57 | [KC_S] = 'o', |
58 | [KC_D] = 'e', |
58 | [KC_D] = 'e', |
59 | [KC_F] = 'u', |
59 | [KC_F] = 'u', |
60 | [KC_G] = 'i', |
60 | [KC_G] = 'i', |
61 | [KC_H] = 'd', |
61 | [KC_H] = 'd', |
62 | [KC_J] = 'h', |
62 | [KC_J] = 'h', |
63 | [KC_K] = 't', |
63 | [KC_K] = 't', |
64 | [KC_L] = 'n', |
64 | [KC_L] = 'n', |
65 | 65 | ||
66 | [KC_SEMICOLON] = 's', |
66 | [KC_SEMICOLON] = 's', |
67 | 67 | ||
68 | [KC_X] = 'q', |
68 | [KC_X] = 'q', |
69 | [KC_C] = 'j', |
69 | [KC_C] = 'j', |
70 | [KC_V] = 'k', |
70 | [KC_V] = 'k', |
71 | [KC_B] = 'x', |
71 | [KC_B] = 'x', |
72 | [KC_N] = 'b', |
72 | [KC_N] = 'b', |
73 | [KC_M] = 'm', |
73 | [KC_M] = 'm', |
74 | 74 | ||
75 | [KC_COMMA] = 'w', |
75 | [KC_COMMA] = 'w', |
76 | [KC_PERIOD] = 'v', |
76 | [KC_PERIOD] = 'v', |
77 | [KC_SLASH] = 'z', |
77 | [KC_SLASH] = 'z', |
78 | }; |
78 | }; |
79 | 79 | ||
80 | static wchar_t map_ucase[] = { |
80 | static wchar_t map_ucase[] = { |
81 | [KC_R] = 'P', |
81 | [KC_R] = 'P', |
82 | [KC_T] = 'Y', |
82 | [KC_T] = 'Y', |
83 | [KC_Y] = 'F', |
83 | [KC_Y] = 'F', |
84 | [KC_U] = 'G', |
84 | [KC_U] = 'G', |
85 | [KC_I] = 'C', |
85 | [KC_I] = 'C', |
86 | [KC_O] = 'R', |
86 | [KC_O] = 'R', |
87 | [KC_P] = 'L', |
87 | [KC_P] = 'L', |
88 | 88 | ||
89 | [KC_A] = 'A', |
89 | [KC_A] = 'A', |
90 | [KC_S] = 'O', |
90 | [KC_S] = 'O', |
91 | [KC_D] = 'E', |
91 | [KC_D] = 'E', |
92 | [KC_F] = 'U', |
92 | [KC_F] = 'U', |
93 | [KC_G] = 'I', |
93 | [KC_G] = 'I', |
94 | [KC_H] = 'D', |
94 | [KC_H] = 'D', |
95 | [KC_J] = 'H', |
95 | [KC_J] = 'H', |
96 | [KC_K] = 'T', |
96 | [KC_K] = 'T', |
97 | [KC_L] = 'N', |
97 | [KC_L] = 'N', |
98 | 98 | ||
99 | [KC_SEMICOLON] = 'S', |
99 | [KC_SEMICOLON] = 'S', |
100 | 100 | ||
101 | [KC_X] = 'Q', |
101 | [KC_X] = 'Q', |
102 | [KC_C] = 'J', |
102 | [KC_C] = 'J', |
103 | [KC_V] = 'K', |
103 | [KC_V] = 'K', |
104 | [KC_B] = 'X', |
104 | [KC_B] = 'X', |
105 | [KC_N] = 'B', |
105 | [KC_N] = 'B', |
106 | [KC_M] = 'M', |
106 | [KC_M] = 'M', |
107 | 107 | ||
108 | [KC_COMMA] = 'W', |
108 | [KC_COMMA] = 'W', |
109 | [KC_PERIOD] = 'V', |
109 | [KC_PERIOD] = 'V', |
110 | [KC_SLASH] = 'Z', |
110 | [KC_SLASH] = 'Z', |
111 | }; |
111 | }; |
112 | 112 | ||
113 | static wchar_t map_not_shifted[] = { |
113 | static wchar_t map_not_shifted[] = { |
114 | [KC_BACKTICK] = '`', |
114 | [KC_BACKTICK] = '`', |
115 | 115 | ||
116 | [KC_1] = '1', |
116 | [KC_1] = '1', |
117 | [KC_2] = '2', |
117 | [KC_2] = '2', |
118 | [KC_3] = '3', |
118 | [KC_3] = '3', |
119 | [KC_4] = '4', |
119 | [KC_4] = '4', |
120 | [KC_5] = '5', |
120 | [KC_5] = '5', |
121 | [KC_6] = '6', |
121 | [KC_6] = '6', |
122 | [KC_7] = '7', |
122 | [KC_7] = '7', |
123 | [KC_8] = '8', |
123 | [KC_8] = '8', |
124 | [KC_9] = '9', |
124 | [KC_9] = '9', |
125 | [KC_0] = '0', |
125 | [KC_0] = '0', |
126 | 126 | ||
127 | [KC_MINUS] = '[', |
127 | [KC_MINUS] = '[', |
128 | [KC_EQUALS] = ']', |
128 | [KC_EQUALS] = ']', |
129 | 129 | ||
130 | [KC_Q] = '\'', |
130 | [KC_Q] = '\'', |
131 | [KC_W] = ',', |
131 | [KC_W] = ',', |
132 | [KC_E] = '.', |
132 | [KC_E] = '.', |
133 | 133 | ||
134 | [KC_LBRACKET] = '/', |
134 | [KC_LBRACKET] = '/', |
135 | [KC_RBRACKET] = '=', |
135 | [KC_RBRACKET] = '=', |
136 | 136 | ||
137 | [KC_QUOTE] = '-', |
137 | [KC_QUOTE] = '-', |
138 | [KC_BACKSLASH] = '\\', |
138 | [KC_BACKSLASH] = '\\', |
139 | 139 | ||
140 | [KC_Z] = ';', |
140 | [KC_Z] = ';', |
141 | }; |
141 | }; |
142 | 142 | ||
143 | static wchar_t map_shifted[] = { |
143 | static wchar_t map_shifted[] = { |
144 | [KC_BACKTICK] = '~', |
144 | [KC_BACKTICK] = '~', |
145 | 145 | ||
146 | [KC_1] = '!', |
146 | [KC_1] = '!', |
147 | [KC_2] = '@', |
147 | [KC_2] = '@', |
148 | [KC_3] = '#', |
148 | [KC_3] = '#', |
149 | [KC_4] = '$', |
149 | [KC_4] = '$', |
150 | [KC_5] = '%', |
150 | [KC_5] = '%', |
151 | [KC_6] = '^', |
151 | [KC_6] = '^', |
152 | [KC_7] = '&', |
152 | [KC_7] = '&', |
153 | [KC_8] = '*', |
153 | [KC_8] = '*', |
154 | [KC_9] = '(', |
154 | [KC_9] = '(', |
155 | [KC_0] = ')', |
155 | [KC_0] = ')', |
156 | 156 | ||
157 | [KC_MINUS] = '{', |
157 | [KC_MINUS] = '{', |
158 | [KC_EQUALS] = '}', |
158 | [KC_EQUALS] = '}', |
159 | 159 | ||
160 | [KC_Q] = '"', |
160 | [KC_Q] = '"', |
161 | [KC_W] = '<', |
161 | [KC_W] = '<', |
162 | [KC_E] = '>', |
162 | [KC_E] = '>', |
163 | 163 | ||
164 | [KC_LBRACKET] = '?', |
164 | [KC_LBRACKET] = '?', |
165 | [KC_RBRACKET] = '+', |
165 | [KC_RBRACKET] = '+', |
166 | 166 | ||
167 | [KC_QUOTE] = '_', |
167 | [KC_QUOTE] = '_', |
168 | [KC_BACKSLASH] = '|', |
168 | [KC_BACKSLASH] = '|', |
169 | 169 | ||
170 | [KC_Z] = ':', |
170 | [KC_Z] = ':', |
171 | }; |
171 | }; |
172 | 172 | ||
173 | static wchar_t map_neutral[] = { |
173 | static wchar_t map_neutral[] = { |
174 | [KC_BACKSPACE] = '\b', |
174 | [KC_BACKSPACE] = '\b', |
175 | [KC_TAB] = '\t', |
175 | [KC_TAB] = '\t', |
176 | [KC_ENTER] = '\n', |
176 | [KC_ENTER] = '\n', |
177 | [KC_SPACE] = ' ', |
177 | [KC_SPACE] = ' ', |
178 | 178 | ||
179 | [KC_NSLASH] = '/', |
179 | [KC_NSLASH] = '/', |
180 | [KC_NTIMES] = '*', |
180 | [KC_NTIMES] = '*', |
181 | [KC_NMINUS] = '-', |
181 | [KC_NMINUS] = '-', |
182 | [KC_NPLUS] = '+', |
182 | [KC_NPLUS] = '+', |
183 | [KC_NENTER] = '\n' |
183 | [KC_NENTER] = '\n' |
184 | }; |
184 | }; |
185 | 185 | ||
186 | static wchar_t map_numeric[] = { |
186 | static wchar_t map_numeric[] = { |
187 | [KC_N7] = '7', |
187 | [KC_N7] = '7', |
188 | [KC_N8] = '8', |
188 | [KC_N8] = '8', |
189 | [KC_N9] = '9', |
189 | [KC_N9] = '9', |
190 | [KC_N4] = '4', |
190 | [KC_N4] = '4', |
191 | [KC_N5] = '5', |
191 | [KC_N5] = '5', |
192 | [KC_N6] = '6', |
192 | [KC_N6] = '6', |
193 | [KC_N1] = '1', |
193 | [KC_N1] = '1', |
194 | [KC_N2] = '2', |
194 | [KC_N2] = '2', |
195 | [KC_N3] = '3', |
195 | [KC_N3] = '3', |
196 | 196 | ||
197 | [KC_N0] = '0', |
197 | [KC_N0] = '0', |
198 | [KC_NPERIOD] = '.' |
198 | [KC_NPERIOD] = '.' |
199 | }; |
199 | }; |
200 | 200 | ||
201 | static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length) |
201 | static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length) |
202 | { |
202 | { |
203 | if (key >= map_length) |
203 | if (key >= map_length) |
204 | return 0; |
204 | return 0; |
205 | return map[key]; |
205 | return map[key]; |
206 | } |
206 | } |
207 | 207 | ||
208 | static void layout_reset(void) |
208 | static void layout_reset(void) |
209 | { |
209 | { |
210 | } |
210 | } |
211 | 211 | ||
212 | static wchar_t layout_parse_ev(kbd_event_t *ev) |
212 | static wchar_t layout_parse_ev(console_event_t *ev) |
213 | { |
213 | { |
214 | wchar_t c; |
214 | wchar_t c; |
215 | 215 | ||
216 | /* Produce no characters when Ctrl or Alt is pressed. */ |
216 | /* Produce no characters when Ctrl or Alt is pressed. */ |
217 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
217 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
218 | return 0; |
218 | return 0; |
219 | 219 | ||
220 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t)); |
220 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t)); |
221 | if (c != 0) |
221 | if (c != 0) |
222 | return c; |
222 | return c; |
223 | 223 | ||
224 | 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)) |
225 | c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t)); |
225 | c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t)); |
226 | else |
226 | else |
227 | c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t)); |
227 | c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t)); |
228 | 228 | ||
229 | if (c != 0) |
229 | if (c != 0) |
230 | return c; |
230 | return c; |
231 | 231 | ||
232 | if ((ev->mods & KM_SHIFT) != 0) |
232 | if ((ev->mods & KM_SHIFT) != 0) |
233 | c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t)); |
233 | c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t)); |
234 | else |
234 | else |
235 | c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t)); |
235 | c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t)); |
236 | 236 | ||
237 | if (c != 0) |
237 | if (c != 0) |
238 | return c; |
238 | return c; |
239 | 239 | ||
240 | if ((ev->mods & KM_NUM_LOCK) != 0) |
240 | if ((ev->mods & KM_NUM_LOCK) != 0) |
241 | c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t)); |
241 | c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t)); |
242 | else |
242 | else |
243 | c = 0; |
243 | c = 0; |
244 | 244 | ||
245 | return c; |
245 | return c; |
246 | } |
246 | } |
247 | 247 | ||
248 | /** |
248 | /** |
249 | * @} |
249 | * @} |
250 | */ |
250 | */ |
251 | 251 |