Rev 4419 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4419 | Rev 4420 | ||
---|---|---|---|
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 QWERTY leyout. |
30 | * @brief US QWERTY leyout. |
31 | * @{ |
31 | * @{ |
32 | */ |
32 | */ |
33 | 33 | ||
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 <bool.h> |
37 | #include <bool.h> |
38 | #include <layout.h> |
38 | #include <layout.h> |
39 | 39 | ||
40 | static void layout_reset(void); |
40 | static void layout_reset(void); |
41 | static wchar_t layout_parse_ev(kbd_event_t *ev); |
41 | static wchar_t layout_parse_ev(kbd_event_t *ev); |
42 | 42 | ||
43 | enum m_state { |
43 | enum m_state { |
44 | ms_start, |
44 | ms_start, |
45 | ms_hacek, |
45 | ms_hacek, |
46 | ms_carka |
46 | ms_carka |
47 | }; |
47 | }; |
48 | 48 | ||
49 | static enum m_state mstate; |
49 | static enum m_state mstate; |
50 | 50 | ||
51 | layout_op_t cz_op = { |
51 | layout_op_t cz_op = { |
52 | layout_reset, |
52 | layout_reset, |
53 | layout_parse_ev |
53 | layout_parse_ev |
54 | }; |
54 | }; |
55 | 55 | ||
56 | static wchar_t map_lcase[] = { |
56 | static wchar_t map_lcase[] = { |
57 | [KC_2] = L'ě', |
- | |
58 | [KC_3] = L'š', |
- | |
59 | [KC_4] = L'č', |
- | |
60 | [KC_5] = L'ř', |
- | |
61 | [KC_6] = L'ž', |
- | |
62 | [KC_7] = L'ý', |
- | |
63 | [KC_8] = L'á', |
- | |
64 | [KC_9] = L'í', |
- | |
65 | [KC_0] = L'é', |
- | |
66 | - | ||
67 | [KC_LBRACKET] = L'ú', |
- | |
68 | [KC_SEMICOLON] = L'ů', |
- | |
69 | - | ||
70 | [KC_Q] = 'q', |
57 | [KC_Q] = 'q', |
71 | [KC_W] = 'w', |
58 | [KC_W] = 'w', |
72 | [KC_E] = 'e', |
59 | [KC_E] = 'e', |
73 | [KC_R] = 'r', |
60 | [KC_R] = 'r', |
74 | [KC_T] = 't', |
61 | [KC_T] = 't', |
75 | [KC_Y] = 'z', |
62 | [KC_Y] = 'z', |
76 | [KC_U] = 'u', |
63 | [KC_U] = 'u', |
77 | [KC_I] = 'i', |
64 | [KC_I] = 'i', |
78 | [KC_O] = 'o', |
65 | [KC_O] = 'o', |
79 | [KC_P] = 'p', |
66 | [KC_P] = 'p', |
80 | 67 | ||
81 | [KC_A] = 'a', |
68 | [KC_A] = 'a', |
82 | [KC_S] = 's', |
69 | [KC_S] = 's', |
83 | [KC_D] = 'd', |
70 | [KC_D] = 'd', |
84 | [KC_F] = 'f', |
71 | [KC_F] = 'f', |
85 | [KC_G] = 'g', |
72 | [KC_G] = 'g', |
86 | [KC_H] = 'h', |
73 | [KC_H] = 'h', |
87 | [KC_J] = 'j', |
74 | [KC_J] = 'j', |
88 | [KC_K] = 'k', |
75 | [KC_K] = 'k', |
89 | [KC_L] = 'l', |
76 | [KC_L] = 'l', |
90 | 77 | ||
91 | [KC_Z] = 'y', |
78 | [KC_Z] = 'y', |
92 | [KC_X] = 'x', |
79 | [KC_X] = 'x', |
93 | [KC_C] = 'c', |
80 | [KC_C] = 'c', |
94 | [KC_V] = 'v', |
81 | [KC_V] = 'v', |
95 | [KC_B] = 'b', |
82 | [KC_B] = 'b', |
96 | [KC_N] = 'n', |
83 | [KC_N] = 'n', |
97 | [KC_M] = 'm', |
84 | [KC_M] = 'm', |
98 | }; |
85 | }; |
99 | 86 | ||
100 | static wchar_t map_ucase[] = { |
87 | static wchar_t map_ucase[] = { |
101 | [KC_2] = L'Ě', |
- | |
102 | [KC_3] = L'Š', |
- | |
103 | [KC_4] = L'Č', |
- | |
104 | [KC_5] = L'Ř', |
- | |
105 | [KC_6] = L'Ž', |
- | |
106 | [KC_7] = L'Ý', |
- | |
107 | [KC_8] = L'Á', |
- | |
108 | [KC_9] = L'Í', |
- | |
109 | [KC_0] = L'É', |
- | |
110 | - | ||
111 | [KC_LBRACKET] = L'Ú', |
- | |
112 | [KC_SEMICOLON] = L'Ů', |
- | |
113 | - | ||
114 | [KC_Q] = 'Q', |
88 | [KC_Q] = 'Q', |
115 | [KC_W] = 'W', |
89 | [KC_W] = 'W', |
116 | [KC_E] = 'E', |
90 | [KC_E] = 'E', |
117 | [KC_R] = 'R', |
91 | [KC_R] = 'R', |
118 | [KC_T] = 'T', |
92 | [KC_T] = 'T', |
119 | [KC_Y] = 'Z', |
93 | [KC_Y] = 'Z', |
120 | [KC_U] = 'U', |
94 | [KC_U] = 'U', |
121 | [KC_I] = 'I', |
95 | [KC_I] = 'I', |
122 | [KC_O] = 'O', |
96 | [KC_O] = 'O', |
123 | [KC_P] = 'P', |
97 | [KC_P] = 'P', |
124 | 98 | ||
125 | [KC_A] = 'A', |
99 | [KC_A] = 'A', |
126 | [KC_S] = 'S', |
100 | [KC_S] = 'S', |
127 | [KC_D] = 'D', |
101 | [KC_D] = 'D', |
128 | [KC_F] = 'F', |
102 | [KC_F] = 'F', |
129 | [KC_G] = 'G', |
103 | [KC_G] = 'G', |
130 | [KC_H] = 'H', |
104 | [KC_H] = 'H', |
131 | [KC_J] = 'J', |
105 | [KC_J] = 'J', |
132 | [KC_K] = 'K', |
106 | [KC_K] = 'K', |
133 | [KC_L] = 'L', |
107 | [KC_L] = 'L', |
134 | 108 | ||
135 | [KC_Z] = 'Y', |
109 | [KC_Z] = 'Y', |
136 | [KC_X] = 'X', |
110 | [KC_X] = 'X', |
137 | [KC_C] = 'C', |
111 | [KC_C] = 'C', |
138 | [KC_V] = 'V', |
112 | [KC_V] = 'V', |
139 | [KC_B] = 'B', |
113 | [KC_B] = 'B', |
140 | [KC_N] = 'N', |
114 | [KC_N] = 'N', |
141 | [KC_M] = 'M', |
115 | [KC_M] = 'M', |
142 | }; |
116 | }; |
143 | 117 | ||
144 | static wchar_t map_not_shifted[] = { |
118 | static wchar_t map_not_shifted[] = { |
145 | [KC_BACKTICK] = ';', |
119 | [KC_BACKTICK] = ';', |
146 | 120 | ||
147 | [KC_1] = '+', |
121 | [KC_1] = '+', |
148 | 122 | ||
149 | [KC_MINUS] = '=', |
123 | [KC_MINUS] = '=', |
150 | 124 | ||
151 | [KC_RBRACKET] = ')', |
125 | [KC_RBRACKET] = ')', |
152 | 126 | ||
153 | [KC_QUOTE] = L'§', |
127 | [KC_QUOTE] = L'§', |
154 | 128 | ||
155 | [KC_COMMA] = ',', |
129 | [KC_COMMA] = ',', |
156 | [KC_PERIOD] = '.', |
130 | [KC_PERIOD] = '.', |
157 | [KC_SLASH] = '-', |
131 | [KC_SLASH] = '-', |
158 | }; |
132 | }; |
159 | 133 | ||
160 | static wchar_t map_shifted[] = { |
134 | static wchar_t map_shifted[] = { |
161 | [KC_1] = '1', |
135 | [KC_1] = '1', |
162 | [KC_2] = '2', |
136 | [KC_2] = '2', |
163 | [KC_3] = '3', |
137 | [KC_3] = '3', |
164 | [KC_4] = '4', |
138 | [KC_4] = '4', |
165 | [KC_5] = '5', |
139 | [KC_5] = '5', |
166 | [KC_6] = '6', |
140 | [KC_6] = '6', |
167 | [KC_7] = '7', |
141 | [KC_7] = '7', |
168 | [KC_8] = '8', |
142 | [KC_8] = '8', |
169 | [KC_9] = '9', |
143 | [KC_9] = '9', |
170 | [KC_0] = '0', |
144 | [KC_0] = '0', |
171 | 145 | ||
172 | [KC_MINUS] = '%', |
146 | [KC_MINUS] = '%', |
173 | 147 | ||
174 | [KC_LBRACKET] = '/', |
148 | [KC_LBRACKET] = '/', |
175 | [KC_RBRACKET] = '(', |
149 | [KC_RBRACKET] = '(', |
176 | 150 | ||
177 | [KC_SEMICOLON] = '"', |
151 | [KC_SEMICOLON] = '"', |
178 | [KC_QUOTE] = '!', |
152 | [KC_QUOTE] = '!', |
179 | [KC_BACKSLASH] = '\'', |
153 | [KC_BACKSLASH] = '\'', |
180 | 154 | ||
181 | [KC_COMMA] = '?', |
155 | [KC_COMMA] = '?', |
182 | [KC_PERIOD] = ':', |
156 | [KC_PERIOD] = ':', |
183 | [KC_SLASH] = '_', |
157 | [KC_SLASH] = '_', |
184 | }; |
158 | }; |
185 | 159 | ||
- | 160 | static wchar_t map_ns_nocaps[] = { |
|
- | 161 | [KC_2] = L'ě', |
|
- | 162 | [KC_3] = L'š', |
|
- | 163 | [KC_4] = L'č', |
|
- | 164 | [KC_5] = L'ř', |
|
- | 165 | [KC_6] = L'ž', |
|
- | 166 | [KC_7] = L'ý', |
|
- | 167 | [KC_8] = L'á', |
|
- | 168 | [KC_9] = L'í', |
|
- | 169 | [KC_0] = L'é', |
|
- | 170 | ||
- | 171 | [KC_LBRACKET] = L'ú', |
|
- | 172 | [KC_SEMICOLON] = L'ů' |
|
- | 173 | }; |
|
- | 174 | ||
- | 175 | static wchar_t map_ns_caps[] = { |
|
- | 176 | [KC_2] = L'Ě', |
|
- | 177 | [KC_3] = L'Š', |
|
- | 178 | [KC_4] = L'Č', |
|
- | 179 | [KC_5] = L'Ř', |
|
- | 180 | [KC_6] = L'Ž', |
|
- | 181 | [KC_7] = L'Ý', |
|
- | 182 | [KC_8] = L'Á', |
|
- | 183 | [KC_9] = L'Í', |
|
- | 184 | [KC_0] = L'É', |
|
- | 185 | ||
- | 186 | [KC_LBRACKET] = L'Ú', |
|
- | 187 | [KC_SEMICOLON] = L'Ů' |
|
- | 188 | }; |
|
- | 189 | ||
186 | static wchar_t map_neutral[] = { |
190 | static wchar_t map_neutral[] = { |
187 | [KC_BACKSPACE] = '\b', |
191 | [KC_BACKSPACE] = '\b', |
188 | [KC_TAB] = '\t', |
192 | [KC_TAB] = '\t', |
189 | [KC_ENTER] = '\n', |
193 | [KC_ENTER] = '\n', |
190 | [KC_SPACE] = ' ', |
194 | [KC_SPACE] = ' ', |
191 | 195 | ||
192 | [KC_NSLASH] = '/', |
196 | [KC_NSLASH] = '/', |
193 | [KC_NTIMES] = '*', |
197 | [KC_NTIMES] = '*', |
194 | [KC_NMINUS] = '-', |
198 | [KC_NMINUS] = '-', |
195 | [KC_NPLUS] = '+', |
199 | [KC_NPLUS] = '+', |
196 | [KC_NENTER] = '\n' |
200 | [KC_NENTER] = '\n' |
197 | }; |
201 | }; |
198 | 202 | ||
199 | static wchar_t map_numeric[] = { |
203 | static wchar_t map_numeric[] = { |
200 | [KC_N7] = '7', |
204 | [KC_N7] = '7', |
201 | [KC_N8] = '8', |
205 | [KC_N8] = '8', |
202 | [KC_N9] = '9', |
206 | [KC_N9] = '9', |
203 | [KC_N4] = '4', |
207 | [KC_N4] = '4', |
204 | [KC_N5] = '5', |
208 | [KC_N5] = '5', |
205 | [KC_N6] = '6', |
209 | [KC_N6] = '6', |
206 | [KC_N1] = '1', |
210 | [KC_N1] = '1', |
207 | [KC_N2] = '2', |
211 | [KC_N2] = '2', |
208 | [KC_N3] = '3', |
212 | [KC_N3] = '3', |
209 | 213 | ||
210 | [KC_N0] = '0', |
214 | [KC_N0] = '0', |
211 | [KC_NPERIOD] = '.' |
215 | [KC_NPERIOD] = '.' |
212 | }; |
216 | }; |
213 | 217 | ||
214 | static wchar_t map_hacek_lcase[] = { |
218 | static wchar_t map_hacek_lcase[] = { |
215 | [KC_E] = L'ě', |
219 | [KC_E] = L'ě', |
216 | [KC_R] = L'ř', |
220 | [KC_R] = L'ř', |
217 | [KC_T] = L'ť', |
221 | [KC_T] = L'ť', |
218 | [KC_Y] = L'ž', |
222 | [KC_Y] = L'ž', |
219 | [KC_U] = L'ů', |
223 | [KC_U] = L'ů', |
220 | 224 | ||
221 | [KC_S] = L'š', |
225 | [KC_S] = L'š', |
222 | [KC_D] = L'ď', |
226 | [KC_D] = L'ď', |
223 | 227 | ||
224 | [KC_C] = L'č', |
228 | [KC_C] = L'č', |
225 | [KC_N] = L'ň' |
229 | [KC_N] = L'ň' |
226 | }; |
230 | }; |
227 | 231 | ||
228 | static wchar_t map_hacek_ucase[] = { |
232 | static wchar_t map_hacek_ucase[] = { |
229 | [KC_E] = L'Ě', |
233 | [KC_E] = L'Ě', |
230 | [KC_R] = L'Ř', |
234 | [KC_R] = L'Ř', |
231 | [KC_T] = L'Ť', |
235 | [KC_T] = L'Ť', |
232 | [KC_Y] = L'Ž', |
236 | [KC_Y] = L'Ž', |
233 | [KC_U] = L'Ů', |
237 | [KC_U] = L'Ů', |
234 | 238 | ||
235 | [KC_S] = L'Š', |
239 | [KC_S] = L'Š', |
236 | [KC_D] = L'Ď', |
240 | [KC_D] = L'Ď', |
237 | 241 | ||
238 | [KC_C] = L'Č', |
242 | [KC_C] = L'Č', |
239 | [KC_N] = L'Ň' |
243 | [KC_N] = L'Ň' |
240 | }; |
244 | }; |
241 | 245 | ||
242 | static wchar_t map_carka_lcase[] = { |
246 | static wchar_t map_carka_lcase[] = { |
243 | [KC_E] = L'é', |
247 | [KC_E] = L'é', |
244 | [KC_U] = L'ú', |
248 | [KC_U] = L'ú', |
245 | [KC_I] = L'í', |
249 | [KC_I] = L'í', |
246 | [KC_O] = L'ó', |
250 | [KC_O] = L'ó', |
247 | 251 | ||
248 | [KC_A] = L'á', |
252 | [KC_A] = L'á', |
249 | 253 | ||
250 | [KC_Z] = L'ý', |
254 | [KC_Z] = L'ý', |
251 | }; |
255 | }; |
252 | 256 | ||
253 | static wchar_t map_carka_ucase[] = { |
257 | static wchar_t map_carka_ucase[] = { |
254 | [KC_E] = L'É', |
258 | [KC_E] = L'É', |
255 | [KC_U] = L'Ú', |
259 | [KC_U] = L'Ú', |
256 | [KC_I] = L'Í', |
260 | [KC_I] = L'Í', |
257 | [KC_O] = L'Ó', |
261 | [KC_O] = L'Ó', |
258 | 262 | ||
259 | [KC_A] = L'Á', |
263 | [KC_A] = L'Á', |
260 | 264 | ||
261 | [KC_Z] = L'Ý', |
265 | [KC_Z] = L'Ý', |
262 | }; |
266 | }; |
263 | 267 | ||
264 | static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length) |
268 | static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length) |
265 | { |
269 | { |
266 | if (key >= map_length) |
270 | if (key >= map_length) |
267 | return 0; |
271 | return 0; |
268 | return map[key]; |
272 | return map[key]; |
269 | } |
273 | } |
270 | 274 | ||
271 | static wchar_t parse_ms_hacek(kbd_event_t *ev) |
275 | static wchar_t parse_ms_hacek(kbd_event_t *ev) |
272 | { |
276 | { |
273 | wchar_t c; |
277 | wchar_t c; |
274 | 278 | ||
275 | mstate = ms_start; |
279 | mstate = ms_start; |
276 | 280 | ||
277 | /* Produce no characters when Ctrl or Alt is pressed. */ |
281 | /* Produce no characters when Ctrl or Alt is pressed. */ |
278 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
282 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
279 | return 0; |
283 | return 0; |
280 | 284 | ||
281 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
285 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
282 | c = translate(ev->key, map_hacek_ucase, sizeof(map_hacek_ucase) / sizeof(wchar_t)); |
286 | c = translate(ev->key, map_hacek_ucase, sizeof(map_hacek_ucase) / sizeof(wchar_t)); |
283 | else |
287 | else |
284 | c = translate(ev->key, map_hacek_lcase, sizeof(map_hacek_lcase) / sizeof(wchar_t)); |
288 | c = translate(ev->key, map_hacek_lcase, sizeof(map_hacek_lcase) / sizeof(wchar_t)); |
285 | 289 | ||
286 | return c; |
290 | return c; |
287 | } |
291 | } |
288 | 292 | ||
289 | static wchar_t parse_ms_carka(kbd_event_t *ev) |
293 | static wchar_t parse_ms_carka(kbd_event_t *ev) |
290 | { |
294 | { |
291 | wchar_t c; |
295 | wchar_t c; |
292 | 296 | ||
293 | mstate = ms_start; |
297 | mstate = ms_start; |
294 | 298 | ||
295 | /* Produce no characters when Ctrl or Alt is pressed. */ |
299 | /* Produce no characters when Ctrl or Alt is pressed. */ |
296 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
300 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
297 | return 0; |
301 | return 0; |
298 | 302 | ||
299 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
303 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
300 | c = translate(ev->key, map_carka_ucase, sizeof(map_carka_ucase) / sizeof(wchar_t)); |
304 | c = translate(ev->key, map_carka_ucase, sizeof(map_carka_ucase) / sizeof(wchar_t)); |
301 | else |
305 | else |
302 | c = translate(ev->key, map_carka_lcase, sizeof(map_carka_lcase) / sizeof(wchar_t)); |
306 | c = translate(ev->key, map_carka_lcase, sizeof(map_carka_lcase) / sizeof(wchar_t)); |
303 | 307 | ||
304 | return c; |
308 | return c; |
305 | } |
309 | } |
306 | 310 | ||
307 | static wchar_t parse_ms_start(kbd_event_t *ev) |
311 | static wchar_t parse_ms_start(kbd_event_t *ev) |
308 | { |
312 | { |
309 | wchar_t c; |
313 | wchar_t c; |
310 | 314 | ||
311 | /* Produce no characters when Ctrl or Alt is pressed. */ |
315 | /* Produce no characters when Ctrl or Alt is pressed. */ |
312 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
316 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
313 | return 0; |
317 | return 0; |
314 | 318 | ||
315 | if (ev->key == KC_EQUALS) { |
319 | if (ev->key == KC_EQUALS) { |
316 | if ((ev->mods & KM_SHIFT) != 0) |
320 | if ((ev->mods & KM_SHIFT) != 0) |
317 | mstate = ms_hacek; |
321 | mstate = ms_hacek; |
318 | else |
322 | else |
319 | mstate = ms_carka; |
323 | mstate = ms_carka; |
320 | 324 | ||
321 | return 0; |
325 | return 0; |
322 | } |
326 | } |
323 | 327 | ||
324 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t)); |
328 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t)); |
325 | if (c != 0) |
329 | if (c != 0) |
326 | return c; |
330 | return c; |
327 | 331 | ||
- | 332 | if ((ev->mods & KM_SHIFT) == 0) { |
|
- | 333 | if ((ev->mods & KM_CAPS_LOCK) != 0) |
|
- | 334 | c = translate(ev->key, map_ns_caps, sizeof(map_ns_caps) / sizeof(wchar_t)); |
|
- | 335 | else |
|
- | 336 | c = translate(ev->key, map_ns_nocaps, sizeof(map_ns_nocaps) / sizeof(wchar_t)); |
|
- | 337 | ||
- | 338 | if (c != 0) |
|
- | 339 | return c; |
|
- | 340 | } |
|
- | 341 | ||
328 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
342 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
329 | c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t)); |
343 | c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t)); |
330 | else |
344 | else |
331 | c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t)); |
345 | c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t)); |
332 | 346 | ||
333 | if (c != 0) |
347 | if (c != 0) |
334 | return c; |
348 | return c; |
335 | 349 | ||
336 | if ((ev->mods & KM_SHIFT) != 0) |
350 | if ((ev->mods & KM_SHIFT) != 0) |
337 | c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t)); |
351 | c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t)); |
338 | else |
352 | else |
339 | c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t)); |
353 | c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t)); |
340 | 354 | ||
341 | if (c != 0) |
355 | if (c != 0) |
342 | return c; |
356 | return c; |
343 | 357 | ||
344 | if ((ev->mods & KM_NUM_LOCK) != 0) |
358 | if ((ev->mods & KM_NUM_LOCK) != 0) |
345 | c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t)); |
359 | c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t)); |
346 | else |
360 | else |
347 | c = 0; |
361 | c = 0; |
348 | 362 | ||
349 | return c; |
363 | return c; |
350 | } |
364 | } |
351 | 365 | ||
352 | static bool key_is_mod(unsigned key) |
366 | static bool key_is_mod(unsigned key) |
353 | { |
367 | { |
354 | switch (key) { |
368 | switch (key) { |
355 | case KC_LSHIFT: |
369 | case KC_LSHIFT: |
356 | case KC_RSHIFT: |
370 | case KC_RSHIFT: |
357 | case KC_LALT: |
371 | case KC_LALT: |
358 | case KC_RALT: |
372 | case KC_RALT: |
359 | case KC_LCTRL: |
373 | case KC_LCTRL: |
360 | case KC_RCTRL: |
374 | case KC_RCTRL: |
361 | return true; |
375 | return true; |
362 | default: |
376 | default: |
363 | return false; |
377 | return false; |
364 | } |
378 | } |
365 | } |
379 | } |
366 | 380 | ||
367 | static void layout_reset(void) |
381 | static void layout_reset(void) |
368 | { |
382 | { |
369 | mstate = ms_start; |
383 | mstate = ms_start; |
370 | } |
384 | } |
371 | 385 | ||
372 | static wchar_t layout_parse_ev(kbd_event_t *ev) |
386 | static wchar_t layout_parse_ev(kbd_event_t *ev) |
373 | { |
387 | { |
374 | if (ev->type != KE_PRESS) |
388 | if (ev->type != KE_PRESS) |
375 | return '\0'; |
389 | return '\0'; |
376 | 390 | ||
377 | if (key_is_mod(ev->key)) |
391 | if (key_is_mod(ev->key)) |
378 | return '\0'; |
392 | return '\0'; |
379 | 393 | ||
380 | switch (mstate) { |
394 | switch (mstate) { |
381 | case ms_start: return parse_ms_start(ev); |
395 | case ms_start: return parse_ms_start(ev); |
382 | case ms_hacek: return parse_ms_hacek(ev); |
396 | case ms_hacek: return parse_ms_hacek(ev); |
383 | case ms_carka: return parse_ms_carka(ev); |
397 | case ms_carka: return parse_ms_carka(ev); |
384 | } |
398 | } |
385 | } |
399 | } |
386 | 400 | ||
387 | /** |
401 | /** |
388 | * @} |
402 | * @} |
389 | */ |
403 | */ |
390 | 404 |