Rev 4239 | Rev 4285 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4239 | Rev 4240 | ||
---|---|---|---|
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 <layout.h> |
37 | #include <layout.h> |
38 | 38 | ||
- | 39 | static wchar_t layout_parse_ev(kbd_event_t *ev); |
|
- | 40 | ||
- | 41 | layout_op_t cz_op = { |
|
- | 42 | layout_parse_ev |
|
- | 43 | }; |
|
- | 44 | ||
39 | static wchar_t map_lcase[] = { |
45 | static wchar_t map_lcase[] = { |
40 | [KC_2] = L'ě', |
46 | [KC_2] = L'ě', |
41 | [KC_3] = L'š', |
47 | [KC_3] = L'š', |
42 | [KC_4] = L'č', |
48 | [KC_4] = L'č', |
43 | [KC_5] = L'ř', |
49 | [KC_5] = L'ř', |
44 | [KC_6] = L'ž', |
50 | [KC_6] = L'ž', |
45 | [KC_7] = L'ý', |
51 | [KC_7] = L'ý', |
46 | [KC_8] = L'á', |
52 | [KC_8] = L'á', |
47 | [KC_9] = L'í', |
53 | [KC_9] = L'í', |
48 | [KC_0] = L'é', |
54 | [KC_0] = L'é', |
49 | 55 | ||
50 | [KC_LBRACKET] = L'ú', |
56 | [KC_LBRACKET] = L'ú', |
51 | [KC_SEMICOLON] = L'ů', |
57 | [KC_SEMICOLON] = L'ů', |
52 | 58 | ||
53 | [KC_Q] = 'q', |
59 | [KC_Q] = 'q', |
54 | [KC_W] = 'w', |
60 | [KC_W] = 'w', |
55 | [KC_E] = 'e', |
61 | [KC_E] = 'e', |
56 | [KC_R] = 'r', |
62 | [KC_R] = 'r', |
57 | [KC_T] = 't', |
63 | [KC_T] = 't', |
58 | [KC_Y] = 'z', |
64 | [KC_Y] = 'z', |
59 | [KC_U] = 'u', |
65 | [KC_U] = 'u', |
60 | [KC_I] = 'i', |
66 | [KC_I] = 'i', |
61 | [KC_O] = 'o', |
67 | [KC_O] = 'o', |
62 | [KC_P] = 'p', |
68 | [KC_P] = 'p', |
63 | 69 | ||
64 | [KC_A] = 'a', |
70 | [KC_A] = 'a', |
65 | [KC_S] = 's', |
71 | [KC_S] = 's', |
66 | [KC_D] = 'd', |
72 | [KC_D] = 'd', |
67 | [KC_F] = 'f', |
73 | [KC_F] = 'f', |
68 | [KC_G] = 'g', |
74 | [KC_G] = 'g', |
69 | [KC_H] = 'h', |
75 | [KC_H] = 'h', |
70 | [KC_J] = 'j', |
76 | [KC_J] = 'j', |
71 | [KC_K] = 'k', |
77 | [KC_K] = 'k', |
72 | [KC_L] = 'l', |
78 | [KC_L] = 'l', |
73 | 79 | ||
74 | [KC_Z] = 'y', |
80 | [KC_Z] = 'y', |
75 | [KC_X] = 'x', |
81 | [KC_X] = 'x', |
76 | [KC_C] = 'c', |
82 | [KC_C] = 'c', |
77 | [KC_V] = 'v', |
83 | [KC_V] = 'v', |
78 | [KC_B] = 'b', |
84 | [KC_B] = 'b', |
79 | [KC_N] = 'n', |
85 | [KC_N] = 'n', |
80 | [KC_M] = 'm', |
86 | [KC_M] = 'm', |
81 | }; |
87 | }; |
82 | 88 | ||
83 | static wchar_t map_ucase[] = { |
89 | static wchar_t map_ucase[] = { |
84 | [KC_2] = L'Ě', |
90 | [KC_2] = L'Ě', |
85 | [KC_3] = L'Š', |
91 | [KC_3] = L'Š', |
86 | [KC_4] = L'Č', |
92 | [KC_4] = L'Č', |
87 | [KC_5] = L'Ř', |
93 | [KC_5] = L'Ř', |
88 | [KC_6] = L'Ž', |
94 | [KC_6] = L'Ž', |
89 | [KC_7] = L'Ý', |
95 | [KC_7] = L'Ý', |
90 | [KC_8] = L'Á', |
96 | [KC_8] = L'Á', |
91 | [KC_9] = L'Í', |
97 | [KC_9] = L'Í', |
92 | [KC_0] = L'É', |
98 | [KC_0] = L'É', |
93 | 99 | ||
94 | [KC_LBRACKET] = L'Ú', |
100 | [KC_LBRACKET] = L'Ú', |
95 | [KC_SEMICOLON] = L'Ů', |
101 | [KC_SEMICOLON] = L'Ů', |
96 | 102 | ||
97 | [KC_Q] = 'Q', |
103 | [KC_Q] = 'Q', |
98 | [KC_W] = 'W', |
104 | [KC_W] = 'W', |
99 | [KC_E] = 'E', |
105 | [KC_E] = 'E', |
100 | [KC_R] = 'R', |
106 | [KC_R] = 'R', |
101 | [KC_T] = 'T', |
107 | [KC_T] = 'T', |
102 | [KC_Y] = 'Z', |
108 | [KC_Y] = 'Z', |
103 | [KC_U] = 'U', |
109 | [KC_U] = 'U', |
104 | [KC_I] = 'I', |
110 | [KC_I] = 'I', |
105 | [KC_O] = 'O', |
111 | [KC_O] = 'O', |
106 | [KC_P] = 'P', |
112 | [KC_P] = 'P', |
107 | 113 | ||
108 | [KC_A] = 'A', |
114 | [KC_A] = 'A', |
109 | [KC_S] = 'S', |
115 | [KC_S] = 'S', |
110 | [KC_D] = 'D', |
116 | [KC_D] = 'D', |
111 | [KC_F] = 'F', |
117 | [KC_F] = 'F', |
112 | [KC_G] = 'G', |
118 | [KC_G] = 'G', |
113 | [KC_H] = 'H', |
119 | [KC_H] = 'H', |
114 | [KC_J] = 'J', |
120 | [KC_J] = 'J', |
115 | [KC_K] = 'K', |
121 | [KC_K] = 'K', |
116 | [KC_L] = 'L', |
122 | [KC_L] = 'L', |
117 | 123 | ||
118 | [KC_Z] = 'Y', |
124 | [KC_Z] = 'Y', |
119 | [KC_X] = 'X', |
125 | [KC_X] = 'X', |
120 | [KC_C] = 'C', |
126 | [KC_C] = 'C', |
121 | [KC_V] = 'V', |
127 | [KC_V] = 'V', |
122 | [KC_B] = 'B', |
128 | [KC_B] = 'B', |
123 | [KC_N] = 'N', |
129 | [KC_N] = 'N', |
124 | [KC_M] = 'M', |
130 | [KC_M] = 'M', |
125 | }; |
131 | }; |
126 | 132 | ||
127 | static wchar_t map_not_shifted[] = { |
133 | static wchar_t map_not_shifted[] = { |
128 | [KC_BACKTICK] = ';', |
134 | [KC_BACKTICK] = ';', |
129 | 135 | ||
130 | [KC_1] = '+', |
136 | [KC_1] = '+', |
131 | 137 | ||
132 | [KC_MINUS] = '=', |
138 | [KC_MINUS] = '=', |
133 | 139 | ||
134 | [KC_RBRACKET] = ')', |
140 | [KC_RBRACKET] = ')', |
135 | 141 | ||
136 | [KC_QUOTE] = L'§', |
142 | [KC_QUOTE] = L'§', |
137 | 143 | ||
138 | [KC_COMMA] = ',', |
144 | [KC_COMMA] = ',', |
139 | [KC_PERIOD] = '.', |
145 | [KC_PERIOD] = '.', |
140 | [KC_SLASH] = '-', |
146 | [KC_SLASH] = '-', |
141 | }; |
147 | }; |
142 | 148 | ||
143 | static wchar_t map_shifted[] = { |
149 | static wchar_t map_shifted[] = { |
144 | [KC_1] = '1', |
150 | [KC_1] = '1', |
145 | [KC_2] = '2', |
151 | [KC_2] = '2', |
146 | [KC_3] = '3', |
152 | [KC_3] = '3', |
147 | [KC_4] = '4', |
153 | [KC_4] = '4', |
148 | [KC_5] = '5', |
154 | [KC_5] = '5', |
149 | [KC_6] = '6', |
155 | [KC_6] = '6', |
150 | [KC_7] = '7', |
156 | [KC_7] = '7', |
151 | [KC_8] = '8', |
157 | [KC_8] = '8', |
152 | [KC_9] = '9', |
158 | [KC_9] = '9', |
153 | [KC_0] = '0', |
159 | [KC_0] = '0', |
154 | 160 | ||
155 | [KC_MINUS] = '%', |
161 | [KC_MINUS] = '%', |
156 | 162 | ||
157 | [KC_LBRACKET] = '/', |
163 | [KC_LBRACKET] = '/', |
158 | [KC_RBRACKET] = '(', |
164 | [KC_RBRACKET] = '(', |
159 | 165 | ||
160 | [KC_SEMICOLON] = '"', |
166 | [KC_SEMICOLON] = '"', |
161 | [KC_QUOTE] = '!', |
167 | [KC_QUOTE] = '!', |
162 | [KC_BACKSLASH] = '\'', |
168 | [KC_BACKSLASH] = '\'', |
163 | 169 | ||
164 | [KC_COMMA] = '?', |
170 | [KC_COMMA] = '?', |
165 | [KC_PERIOD] = ':', |
171 | [KC_PERIOD] = ':', |
166 | [KC_SLASH] = '_', |
172 | [KC_SLASH] = '_', |
167 | }; |
173 | }; |
168 | 174 | ||
169 | static wchar_t map_neutral[] = { |
175 | static wchar_t map_neutral[] = { |
170 | [KC_BACKSPACE] = '\b', |
176 | [KC_BACKSPACE] = '\b', |
171 | [KC_TAB] = '\t', |
177 | [KC_TAB] = '\t', |
172 | [KC_ENTER] = '\n', |
178 | [KC_ENTER] = '\n', |
173 | [KC_SPACE] = ' ', |
179 | [KC_SPACE] = ' ', |
174 | 180 | ||
175 | [KC_NSLASH] = '/', |
181 | [KC_NSLASH] = '/', |
176 | [KC_NTIMES] = '*', |
182 | [KC_NTIMES] = '*', |
177 | [KC_NMINUS] = '-', |
183 | [KC_NMINUS] = '-', |
178 | [KC_NPLUS] = '+', |
184 | [KC_NPLUS] = '+', |
179 | [KC_NENTER] = '\n' |
185 | [KC_NENTER] = '\n' |
180 | }; |
186 | }; |
181 | 187 | ||
182 | static wchar_t map_numeric[] = { |
188 | static wchar_t map_numeric[] = { |
183 | [KC_N7] = '7', |
189 | [KC_N7] = '7', |
184 | [KC_N8] = '8', |
190 | [KC_N8] = '8', |
185 | [KC_N9] = '9', |
191 | [KC_N9] = '9', |
186 | [KC_N4] = '4', |
192 | [KC_N4] = '4', |
187 | [KC_N5] = '5', |
193 | [KC_N5] = '5', |
188 | [KC_N6] = '6', |
194 | [KC_N6] = '6', |
189 | [KC_N1] = '1', |
195 | [KC_N1] = '1', |
190 | [KC_N2] = '2', |
196 | [KC_N2] = '2', |
191 | [KC_N3] = '3', |
197 | [KC_N3] = '3', |
192 | 198 | ||
193 | [KC_N0] = '0', |
199 | [KC_N0] = '0', |
194 | [KC_NPERIOD] = '.' |
200 | [KC_NPERIOD] = '.' |
195 | }; |
201 | }; |
196 | 202 | ||
197 | static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length) |
203 | static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length) |
198 | { |
204 | { |
199 | if (key >= map_length) |
205 | if (key >= map_length) |
200 | return 0; |
206 | return 0; |
201 | return map[key]; |
207 | return map[key]; |
202 | } |
208 | } |
203 | 209 | ||
204 | wchar_t layout_parse_ev(kbd_event_t *ev) |
210 | static wchar_t layout_parse_ev(kbd_event_t *ev) |
205 | { |
211 | { |
206 | wchar_t c; |
212 | wchar_t c; |
207 | 213 | ||
208 | /* Produce no characters when Ctrl or Alt is pressed. */ |
214 | /* Produce no characters when Ctrl or Alt is pressed. */ |
209 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
215 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
210 | return 0; |
216 | return 0; |
211 | 217 | ||
212 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t)); |
218 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t)); |
213 | if (c != 0) |
219 | if (c != 0) |
214 | return c; |
220 | return c; |
215 | 221 | ||
216 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
222 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
217 | c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t)); |
223 | c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t)); |
218 | else |
224 | else |
219 | c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t)); |
225 | c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t)); |
220 | 226 | ||
221 | if (c != 0) |
227 | if (c != 0) |
222 | return c; |
228 | return c; |
223 | 229 | ||
224 | if ((ev->mods & KM_SHIFT) != 0) |
230 | if ((ev->mods & KM_SHIFT) != 0) |
225 | c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t)); |
231 | c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t)); |
226 | else |
232 | else |
227 | c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t)); |
233 | c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t)); |
228 | 234 | ||
229 | if (c != 0) |
235 | if (c != 0) |
230 | return c; |
236 | return c; |
231 | 237 | ||
232 | if ((ev->mods & KM_NUM_LOCK) != 0) |
238 | if ((ev->mods & KM_NUM_LOCK) != 0) |
233 | c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t)); |
239 | c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t)); |
234 | else |
240 | else |
235 | c = 0; |
241 | c = 0; |
236 | 242 | ||
237 | return c; |
243 | return c; |
238 | } |
244 | } |
239 | 245 | ||
240 | /** |
246 | /** |
241 | * @} |
247 | * @} |
242 | */ |
248 | */ |
243 | 249 |