source: mainline/uspace/srv/hid/input/layout/cz.c@ f1380b7

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f1380b7 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 8.3 KB
Line 
1/*
2 * Copyright (c) 2011 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
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
15 * derived from this software without specific prior written permission.
16 *
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
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup input
30 * @brief Czech QWERTZ layout.
31 * @{
32 */
33
34#include <errno.h>
35#include <io/console.h>
36#include <io/keycode.h>
37#include <stdbool.h>
38#include <stdlib.h>
39#include "../input.h"
40#include "../layout.h"
41
42static errno_t cz_create(layout_t *);
43static void cz_destroy(layout_t *);
44static wchar_t cz_parse_ev(layout_t *, kbd_event_t *ev);
45
46enum m_state {
47 ms_start,
48 ms_hacek,
49 ms_carka
50};
51
52typedef struct {
53 enum m_state mstate;
54} layout_cz_t;
55
56layout_ops_t cz_ops = {
57 .create = cz_create,
58 .destroy = cz_destroy,
59 .parse_ev = cz_parse_ev
60};
61
62static wchar_t map_lcase[] = {
63 [KC_Q] = 'q',
64 [KC_W] = 'w',
65 [KC_E] = 'e',
66 [KC_R] = 'r',
67 [KC_T] = 't',
68 [KC_Y] = 'z',
69 [KC_U] = 'u',
70 [KC_I] = 'i',
71 [KC_O] = 'o',
72 [KC_P] = 'p',
73
74 [KC_A] = 'a',
75 [KC_S] = 's',
76 [KC_D] = 'd',
77 [KC_F] = 'f',
78 [KC_G] = 'g',
79 [KC_H] = 'h',
80 [KC_J] = 'j',
81 [KC_K] = 'k',
82 [KC_L] = 'l',
83
84 [KC_Z] = 'y',
85 [KC_X] = 'x',
86 [KC_C] = 'c',
87 [KC_V] = 'v',
88 [KC_B] = 'b',
89 [KC_N] = 'n',
90 [KC_M] = 'm',
91};
92
93static wchar_t map_ucase[] = {
94 [KC_Q] = 'Q',
95 [KC_W] = 'W',
96 [KC_E] = 'E',
97 [KC_R] = 'R',
98 [KC_T] = 'T',
99 [KC_Y] = 'Z',
100 [KC_U] = 'U',
101 [KC_I] = 'I',
102 [KC_O] = 'O',
103 [KC_P] = 'P',
104
105 [KC_A] = 'A',
106 [KC_S] = 'S',
107 [KC_D] = 'D',
108 [KC_F] = 'F',
109 [KC_G] = 'G',
110 [KC_H] = 'H',
111 [KC_J] = 'J',
112 [KC_K] = 'K',
113 [KC_L] = 'L',
114
115 [KC_Z] = 'Y',
116 [KC_X] = 'X',
117 [KC_C] = 'C',
118 [KC_V] = 'V',
119 [KC_B] = 'B',
120 [KC_N] = 'N',
121 [KC_M] = 'M',
122};
123
124static wchar_t map_not_shifted[] = {
125 [KC_BACKTICK] = ';',
126
127 [KC_1] = '+',
128
129 [KC_MINUS] = '=',
130
131 [KC_RBRACKET] = ')',
132
133 [KC_QUOTE] = L'§',
134
135 [KC_COMMA] = ',',
136 [KC_PERIOD] = '.',
137 [KC_SLASH] = '-',
138};
139
140static wchar_t map_shifted[] = {
141 [KC_1] = '1',
142 [KC_2] = '2',
143 [KC_3] = '3',
144 [KC_4] = '4',
145 [KC_5] = '5',
146 [KC_6] = '6',
147 [KC_7] = '7',
148 [KC_8] = '8',
149 [KC_9] = '9',
150 [KC_0] = '0',
151
152 [KC_MINUS] = '%',
153
154 [KC_LBRACKET] = '/',
155 [KC_RBRACKET] = '(',
156
157 [KC_SEMICOLON] = '"',
158 [KC_QUOTE] = '!',
159 [KC_BACKSLASH] = '\'',
160
161 [KC_COMMA] = '?',
162 [KC_PERIOD] = ':',
163 [KC_SLASH] = '_',
164};
165
166static wchar_t map_ns_nocaps[] = {
167 [KC_2] = L'ě',
168 [KC_3] = L'š',
169 [KC_4] = L'č',
170 [KC_5] = L'ř',
171 [KC_6] = L'ž',
172 [KC_7] = L'ý',
173 [KC_8] = L'á',
174 [KC_9] = L'í',
175 [KC_0] = L'é',
176
177 [KC_LBRACKET] = L'ú',
178 [KC_SEMICOLON] = L'ů'
179};
180
181static wchar_t map_ns_caps[] = {
182 [KC_2] = L'Ě',
183 [KC_3] = L'Š',
184 [KC_4] = L'Č',
185 [KC_5] = L'Ř',
186 [KC_6] = L'Ž',
187 [KC_7] = L'Ý',
188 [KC_8] = L'Á',
189 [KC_9] = L'Í',
190 [KC_0] = L'É',
191
192 [KC_LBRACKET] = L'Ú',
193 [KC_SEMICOLON] = L'Ů'
194};
195
196static wchar_t map_neutral[] = {
197 [KC_BACKSPACE] = '\b',
198 [KC_TAB] = '\t',
199 [KC_ENTER] = '\n',
200 [KC_SPACE] = ' ',
201
202 [KC_NSLASH] = '/',
203 [KC_NTIMES] = '*',
204 [KC_NMINUS] = '-',
205 [KC_NPLUS] = '+',
206 [KC_NENTER] = '\n'
207};
208
209static wchar_t map_numeric[] = {
210 [KC_N7] = '7',
211 [KC_N8] = '8',
212 [KC_N9] = '9',
213 [KC_N4] = '4',
214 [KC_N5] = '5',
215 [KC_N6] = '6',
216 [KC_N1] = '1',
217 [KC_N2] = '2',
218 [KC_N3] = '3',
219
220 [KC_N0] = '0',
221 [KC_NPERIOD] = '.'
222};
223
224static wchar_t map_hacek_lcase[] = {
225 [KC_E] = L'ě',
226 [KC_R] = L'ř',
227 [KC_T] = L'ť',
228 [KC_Y] = L'ž',
229 [KC_U] = L'ů',
230
231 [KC_S] = L'š',
232 [KC_D] = L'ď',
233
234 [KC_C] = L'č',
235 [KC_N] = L'ň'
236};
237
238static wchar_t map_hacek_ucase[] = {
239 [KC_E] = L'Ě',
240 [KC_R] = L'Ř',
241 [KC_T] = L'Ť',
242 [KC_Y] = L'Ž',
243 [KC_U] = L'Ů',
244
245 [KC_S] = L'Š',
246 [KC_D] = L'Ď',
247
248 [KC_C] = L'Č',
249 [KC_N] = L'Ň'
250};
251
252static wchar_t map_carka_lcase[] = {
253 [KC_E] = L'é',
254 [KC_U] = L'ú',
255 [KC_I] = L'í',
256 [KC_O] = L'ó',
257
258 [KC_A] = L'á',
259
260 [KC_Z] = L'ý',
261};
262
263static wchar_t map_carka_ucase[] = {
264 [KC_E] = L'É',
265 [KC_U] = L'Ú',
266 [KC_I] = L'Í',
267 [KC_O] = L'Ó',
268
269 [KC_A] = L'Á',
270
271 [KC_Z] = L'Ý',
272};
273
274static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
275{
276 if (key >= map_length)
277 return 0;
278 return map[key];
279}
280
281static wchar_t parse_ms_hacek(layout_cz_t *cz_state, kbd_event_t *ev)
282{
283 wchar_t c;
284
285 cz_state->mstate = ms_start;
286
287 /* Produce no characters when Ctrl or Alt is pressed. */
288 if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
289 return 0;
290
291 if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
292 c = translate(ev->key, map_hacek_ucase, sizeof(map_hacek_ucase) / sizeof(wchar_t));
293 else
294 c = translate(ev->key, map_hacek_lcase, sizeof(map_hacek_lcase) / sizeof(wchar_t));
295
296 return c;
297}
298
299static wchar_t parse_ms_carka(layout_cz_t *cz_state, kbd_event_t *ev)
300{
301 wchar_t c;
302
303 cz_state->mstate = ms_start;
304
305 /* Produce no characters when Ctrl or Alt is pressed. */
306 if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
307 return 0;
308
309 if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
310 c = translate(ev->key, map_carka_ucase, sizeof(map_carka_ucase) / sizeof(wchar_t));
311 else
312 c = translate(ev->key, map_carka_lcase, sizeof(map_carka_lcase) / sizeof(wchar_t));
313
314 return c;
315}
316
317static wchar_t parse_ms_start(layout_cz_t *cz_state, kbd_event_t *ev)
318{
319 wchar_t c;
320
321 /* Produce no characters when Ctrl or Alt is pressed. */
322 if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
323 return 0;
324
325 if (ev->key == KC_EQUALS) {
326 if ((ev->mods & KM_SHIFT) != 0)
327 cz_state->mstate = ms_hacek;
328 else
329 cz_state->mstate = ms_carka;
330
331 return 0;
332 }
333
334 c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t));
335 if (c != 0)
336 return c;
337
338 if ((ev->mods & KM_SHIFT) == 0) {
339 if ((ev->mods & KM_CAPS_LOCK) != 0)
340 c = translate(ev->key, map_ns_caps, sizeof(map_ns_caps) / sizeof(wchar_t));
341 else
342 c = translate(ev->key, map_ns_nocaps, sizeof(map_ns_nocaps) / sizeof(wchar_t));
343
344 if (c != 0)
345 return c;
346 }
347
348 if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
349 c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t));
350 else
351 c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t));
352
353 if (c != 0)
354 return c;
355
356 if ((ev->mods & KM_SHIFT) != 0)
357 c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t));
358 else
359 c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t));
360
361 if (c != 0)
362 return c;
363
364 if ((ev->mods & KM_NUM_LOCK) != 0)
365 c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t));
366 else
367 c = 0;
368
369 return c;
370}
371
372static bool key_is_mod(unsigned key)
373{
374 switch (key) {
375 case KC_LSHIFT:
376 case KC_RSHIFT:
377 case KC_LALT:
378 case KC_RALT:
379 case KC_LCTRL:
380 case KC_RCTRL:
381 return true;
382 default:
383 return false;
384 }
385}
386
387static errno_t cz_create(layout_t *state)
388{
389 layout_cz_t *cz_state;
390
391 cz_state = malloc(sizeof(layout_cz_t));
392 if (cz_state == NULL) {
393 printf("%s: Out of memory.\n", NAME);
394 return ENOMEM;
395 }
396
397 cz_state->mstate = ms_start;
398 state->layout_priv = (void *) cz_state;
399
400 return EOK;
401}
402
403static void cz_destroy(layout_t *state)
404{
405 free(state->layout_priv);
406}
407
408static wchar_t cz_parse_ev(layout_t *state, kbd_event_t *ev)
409{
410 layout_cz_t *cz_state = (layout_cz_t *) state->layout_priv;
411
412 if (ev->type != KEY_PRESS)
413 return 0;
414
415 if (key_is_mod(ev->key))
416 return 0;
417
418 switch (cz_state->mstate) {
419 case ms_start:
420 return parse_ms_start(cz_state, ev);
421 case ms_hacek:
422 return parse_ms_hacek(cz_state, ev);
423 case ms_carka:
424 return parse_ms_carka(cz_state, ev);
425 }
426
427 return 0;
428}
429
430/**
431 * @}
432 */
Note: See TracBrowser for help on using the repository browser.