source: mainline/uspace/srv/hid/input/layout/us_qwerty.c@ cb9313e

Last change on this file since cb9313e was cb9313e, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago

Adding a configuration flag which allows to define which is
the default keyboard layout

This commit adds a new configuration flag which defines the
default keyboard layout. This layout will be hardcoded into
the system. Changing to this keyboard layout can be done by
pressing CTRL+F1.

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