source: mainline/uspace/srv/hid/input/layout/fr_azerty.c

Last change on this file was b987eb4, checked in by Jiri Svoboda <jiri@…>, 3 years ago

Translate keys to characters even if modifiers are pressed.

So that we can match Alt-key to menu accelerators. Of course
this means clients must check Ctrl and Alt state to determine
if they should insert characters, not just just kbd_event_t.c.

  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 * Copyright (c) 2019 CHTCHEGLOV Ilia
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 * @{
31 */
32
33/** @file
34 * @brief French AZERTY layout
35 */
36
37#include <errno.h>
38#include <io/console.h>
39#include <io/keycode.h>
40#include "../layout.h"
41#include "../kbd.h"
42
43static errno_t fr_azerty_create (layout_t *);
44static void fr_azerty_destroy (layout_t *);
45static char32_t fr_azerty_parse_ev (layout_t *, kbd_event_t *);
46
47layout_ops_t fr_azerty_ops = {
48 .create = fr_azerty_create,
49 .destroy = fr_azerty_destroy,
50 .parse_ev = fr_azerty_parse_ev
51};
52
53static char32_t map_lcase[] = {
54 [KC_Q] = 'a',
55 [KC_W] = 'z',
56 [KC_E] = 'e',
57 [KC_R] = 'r',
58 [KC_T] = 't',
59 [KC_Y] = 'y',
60 [KC_U] = 'u',
61 [KC_I] = 'i',
62 [KC_O] = 'o',
63 [KC_P] = 'p',
64
65 [KC_A] = 'q',
66 [KC_S] = 's',
67 [KC_D] = 'd',
68 [KC_F] = 'f',
69 [KC_G] = 'g',
70 [KC_H] = 'h',
71 [KC_J] = 'j',
72 [KC_K] = 'k',
73 [KC_L] = 'l',
74
75 [KC_Z] = 'w',
76 [KC_X] = 'x',
77 [KC_C] = 'c',
78 [KC_V] = 'v',
79 [KC_B] = 'b',
80 [KC_N] = 'n',
81 [KC_M] = ',',
82};
83
84static char32_t map_ucase[] = {
85 [KC_Q] = 'A',
86 [KC_W] = 'Z',
87 [KC_E] = 'E',
88 [KC_R] = 'R',
89 [KC_T] = 'T',
90 [KC_Y] = 'Y',
91 [KC_U] = 'U',
92 [KC_I] = 'I',
93 [KC_O] = 'O',
94 [KC_P] = 'P',
95
96 [KC_A] = 'Q',
97 [KC_S] = 'S',
98 [KC_D] = 'D',
99 [KC_F] = 'F',
100 [KC_G] = 'G',
101 [KC_H] = 'H',
102 [KC_J] = 'J',
103 [KC_K] = 'K',
104 [KC_L] = 'L',
105
106 [KC_Z] = 'W',
107 [KC_X] = 'X',
108 [KC_C] = 'C',
109 [KC_V] = 'V',
110 [KC_B] = 'B',
111 [KC_N] = 'N',
112 [KC_2] = L'É',
113 [KC_7] = L'È',
114 [KC_9] = L'Ç',
115 [KC_0] = L'À',
116 [KC_M] = ','
117};
118
119static char32_t map_not_shifted[] = {
120 [KC_BACKTICK] = L'²',
121
122 [KC_1] = '&',
123 [KC_2] = L'é',
124 [KC_3] = '"',
125 [KC_4] = '\'',
126 [KC_5] = '(',
127 [KC_6] = '-',
128 [KC_7] = L'è',
129 [KC_8] = '_',
130 [KC_9] = L'ç',
131 [KC_0] = L'à',
132
133 [KC_MINUS] = ')',
134 [KC_EQUALS] = '=',
135
136 [KC_LBRACKET] = '^',
137 [KC_RBRACKET] = '$',
138
139 [KC_SEMICOLON] = 'm',
140 [KC_QUOTE] = L'ù',
141 [KC_BACKSLASH] = '*',
142
143 [KC_COMMA] = ';',
144 [KC_PERIOD] = ':',
145 [KC_SLASH] = '!',
146};
147
148static char32_t map_shifted[] = {
149 [KC_M] = '?',
150 [KC_BACKTICK] = '~',
151
152 [KC_1] = '1',
153 [KC_2] = '2',
154 [KC_3] = '3',
155 [KC_4] = '4',
156 [KC_5] = '5',
157 [KC_6] = '6',
158 [KC_7] = '7',
159 [KC_8] = '8',
160 [KC_9] = '9',
161 [KC_0] = '0',
162
163 [KC_MINUS] = L'°',
164 [KC_EQUALS] = '+',
165
166 [KC_LBRACKET] = L'¨',
167 [KC_RBRACKET] = L'£',
168
169 [KC_SEMICOLON] = 'M',
170 [KC_QUOTE] = '%',
171 [KC_BACKSLASH] = L'µ',
172
173 [KC_COMMA] = '.',
174 [KC_PERIOD] = '/',
175 [KC_SLASH] = '!',
176};
177
178static char32_t map_neutral[] = {
179 [KC_BACKSPACE] = '\b',
180 [KC_TAB] = '\t',
181 [KC_ENTER] = '\n',
182 [KC_SPACE] = ' ',
183
184 [KC_NSLASH] = '!',
185 [KC_NTIMES] = '*',
186 [KC_NMINUS] = '-',
187 [KC_NPLUS] = '+',
188 [KC_NENTER] = '\n'
189};
190
191static char32_t map_numeric[] = {
192 [KC_N7] = '7',
193 [KC_N8] = '8',
194 [KC_N9] = '9',
195 [KC_N4] = '4',
196 [KC_N5] = '5',
197 [KC_N6] = '6',
198 [KC_N1] = '1',
199 [KC_N2] = '2',
200 [KC_N3] = '3',
201
202 [KC_N0] = '0',
203 [KC_NPERIOD] = '.'
204};
205
206static char32_t translate (unsigned int key, char32_t *map, size_t map_len)
207{
208 if (key >= map_len)
209 return 0;
210 return map[key];
211}
212
213static errno_t fr_azerty_create (layout_t *s)
214{
215 return EOK;
216}
217
218static void fr_azerty_destroy (layout_t *s)
219{
220
221}
222
223static char32_t fr_azerty_parse_ev (layout_t *s, kbd_event_t *e)
224{
225 char32_t c = translate (e->key, map_neutral, sizeof (map_neutral) / sizeof (char32_t));
226 if (c)
227 return c;
228
229 if ((e->mods & KM_SHIFT))
230 c = translate (e->key, map_shifted, sizeof (map_shifted) / sizeof (char32_t));
231 else
232 c = translate (e->key, map_not_shifted, sizeof (map_not_shifted) / sizeof (char32_t));
233
234 if (c)
235 return c;
236
237 if (((e->mods & KM_SHIFT)) ^ ((e->mods & KM_CAPS_LOCK)))
238 c = translate (e->key, map_ucase, sizeof (map_ucase) / sizeof (char32_t));
239 else
240 c = translate (e->key, map_lcase, sizeof (map_lcase) / sizeof (char32_t));
241
242 if (c)
243 return c;
244
245 if ((e->mods & KM_NUM_LOCK))
246 c = translate (e->key, map_numeric, sizeof (map_numeric) / sizeof (char32_t));
247 else
248 c = 0;
249
250 return c;
251}
252
253/**
254 * @}
255 */
Note: See TracBrowser for help on using the repository browser.