source: mainline/uspace/srv/hid/kbd/layout/us_qwerty.c@ 79ae36dd

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 79ae36dd was 79ae36dd, checked in by Martin Decky <martin@…>, 14 years ago

new async framework with integrated exchange tracking

  • strict isolation between low-level IPC and high-level async framework with integrated exchange tracking
    • each IPC connection is represented by an async_sess_t structure
    • each IPC exchange is represented by an async_exch_t structure
    • exchange management is either based on atomic messages (EXCHANGE_ATOMIC), locking (EXCHANGE_SERIALIZE) or connection cloning (EXCHANGE_CLONE)
  • async_obsolete: temporary compatibility layer to keep old async clients working (several pieces of code are currently broken, but only non-essential functionality)
  • IPC_M_PHONE_HANGUP is now method no. 0 (for elegant boolean evaluation)
  • IPC_M_DEBUG_ALL has been renamed to IPC_M_DEBUG
  • IPC_M_PING has been removed (VFS protocol now has VFS_IN_PING)
  • console routines in libc have been rewritten for better abstraction
  • additional use for libc-private header files (FILE structure opaque to the client)
  • various cstyle changes (typos, indentation, missing externs in header files, improved comments, etc.)
  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 * Copyright (c) 2009 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 kbd
30 * @brief US QWERTY layout.
31 * @{
32 */
33
34#include <kbd.h>
35#include <io/console.h>
36#include <io/keycode.h>
37#include <layout.h>
38
39static void layout_reset(void);
40static wchar_t layout_parse_ev(kbd_event_t *ev);
41
42layout_op_t us_qwerty_op = {
43 layout_reset,
44 layout_parse_ev
45};
46
47static wchar_t map_lcase[] = {
48 [KC_Q] = 'q',
49 [KC_W] = 'w',
50 [KC_E] = 'e',
51 [KC_R] = 'r',
52 [KC_T] = 't',
53 [KC_Y] = 'y',
54 [KC_U] = 'u',
55 [KC_I] = 'i',
56 [KC_O] = 'o',
57 [KC_P] = 'p',
58
59 [KC_A] = 'a',
60 [KC_S] = 's',
61 [KC_D] = 'd',
62 [KC_F] = 'f',
63 [KC_G] = 'g',
64 [KC_H] = 'h',
65 [KC_J] = 'j',
66 [KC_K] = 'k',
67 [KC_L] = 'l',
68
69 [KC_Z] = 'z',
70 [KC_X] = 'x',
71 [KC_C] = 'c',
72 [KC_V] = 'v',
73 [KC_B] = 'b',
74 [KC_N] = 'n',
75 [KC_M] = 'm',
76};
77
78static wchar_t map_ucase[] = {
79 [KC_Q] = 'Q',
80 [KC_W] = 'W',
81 [KC_E] = 'E',
82 [KC_R] = 'R',
83 [KC_T] = 'T',
84 [KC_Y] = 'Y',
85 [KC_U] = 'U',
86 [KC_I] = 'I',
87 [KC_O] = 'O',
88 [KC_P] = 'P',
89
90 [KC_A] = 'A',
91 [KC_S] = 'S',
92 [KC_D] = 'D',
93 [KC_F] = 'F',
94 [KC_G] = 'G',
95 [KC_H] = 'H',
96 [KC_J] = 'J',
97 [KC_K] = 'K',
98 [KC_L] = 'L',
99
100 [KC_Z] = 'Z',
101 [KC_X] = 'X',
102 [KC_C] = 'C',
103 [KC_V] = 'V',
104 [KC_B] = 'B',
105 [KC_N] = 'N',
106 [KC_M] = 'M',
107};
108
109static wchar_t map_not_shifted[] = {
110 [KC_BACKTICK] = '`',
111
112 [KC_1] = '1',
113 [KC_2] = '2',
114 [KC_3] = '3',
115 [KC_4] = '4',
116 [KC_5] = '5',
117 [KC_6] = '6',
118 [KC_7] = '7',
119 [KC_8] = '8',
120 [KC_9] = '9',
121 [KC_0] = '0',
122
123 [KC_MINUS] = '-',
124 [KC_EQUALS] = '=',
125
126 [KC_LBRACKET] = '[',
127 [KC_RBRACKET] = ']',
128
129 [KC_SEMICOLON] = ';',
130 [KC_QUOTE] = '\'',
131 [KC_BACKSLASH] = '\\',
132
133 [KC_COMMA] = ',',
134 [KC_PERIOD] = '.',
135 [KC_SLASH] = '/',
136};
137
138static wchar_t map_shifted[] = {
139 [KC_BACKTICK] = '~',
140
141 [KC_1] = '!',
142 [KC_2] = '@',
143 [KC_3] = '#',
144 [KC_4] = '$',
145 [KC_5] = '%',
146 [KC_6] = '^',
147 [KC_7] = '&',
148 [KC_8] = '*',
149 [KC_9] = '(',
150 [KC_0] = ')',
151
152 [KC_MINUS] = '_',
153 [KC_EQUALS] = '+',
154
155 [KC_LBRACKET] = '{',
156 [KC_RBRACKET] = '}',
157
158 [KC_SEMICOLON] = ':',
159 [KC_QUOTE] = '"',
160 [KC_BACKSLASH] = '|',
161
162 [KC_COMMA] = '<',
163 [KC_PERIOD] = '>',
164 [KC_SLASH] = '?',
165};
166
167static wchar_t map_neutral[] = {
168 [KC_BACKSPACE] = '\b',
169 [KC_TAB] = '\t',
170 [KC_ENTER] = '\n',
171 [KC_SPACE] = ' ',
172
173 [KC_NSLASH] = '/',
174 [KC_NTIMES] = '*',
175 [KC_NMINUS] = '-',
176 [KC_NPLUS] = '+',
177 [KC_NENTER] = '\n'
178};
179
180static wchar_t map_numeric[] = {
181 [KC_N7] = '7',
182 [KC_N8] = '8',
183 [KC_N9] = '9',
184 [KC_N4] = '4',
185 [KC_N5] = '5',
186 [KC_N6] = '6',
187 [KC_N1] = '1',
188 [KC_N2] = '2',
189 [KC_N3] = '3',
190
191 [KC_N0] = '0',
192 [KC_NPERIOD] = '.'
193};
194
195static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
196{
197 if (key >= map_length)
198 return 0;
199 return map[key];
200}
201
202static void layout_reset(void)
203{
204}
205
206static wchar_t layout_parse_ev(kbd_event_t *ev)
207{
208 wchar_t c;
209
210 /* Produce no characters when Ctrl or Alt is pressed. */
211 if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
212 return 0;
213
214 c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t));
215 if (c != 0)
216 return c;
217
218 if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
219 c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t));
220 else
221 c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t));
222
223 if (c != 0)
224 return c;
225
226 if ((ev->mods & KM_SHIFT) != 0)
227 c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t));
228 else
229 c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t));
230
231 if (c != 0)
232 return c;
233
234 if ((ev->mods & KM_NUM_LOCK) != 0)
235 c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t));
236 else
237 c = 0;
238
239 return c;
240}
241
242/**
243 * @}
244 */
Note: See TracBrowser for help on using the repository browser.