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