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