[f89979b] | 1 | /*
|
---|
[2f7a564] | 2 | * Copyright (c) 2011 Jiri Svoboda
|
---|
[f89979b] | 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 |
|
---|
[5f88293] | 29 | /** @addtogroup input
|
---|
[f89979b] | 30 | * @{
|
---|
[5f88293] | 31 | */
|
---|
[f89979b] | 32 |
|
---|
[4122410] | 33 | /** @file
|
---|
| 34 | * @brief US QWERTY layout
|
---|
| 35 | */
|
---|
| 36 |
|
---|
[2f7a564] | 37 | #include <errno.h>
|
---|
[215abc1] | 38 | #include <io/console.h>
|
---|
| 39 | #include <io/keycode.h>
|
---|
[b6a088f] | 40 | #include "../layout.h"
|
---|
| 41 | #include "../kbd.h"
|
---|
[f89979b] | 42 |
|
---|
[b7fd2a0] | 43 | static errno_t us_qwerty_create(layout_t *);
|
---|
[2f7a564] | 44 | static void us_qwerty_destroy(layout_t *);
|
---|
[28a5ebd] | 45 | static char32_t us_qwerty_parse_ev(layout_t *, kbd_event_t *ev);
|
---|
[0175246] | 46 |
|
---|
[2f7a564] | 47 | layout_ops_t us_qwerty_ops = {
|
---|
| 48 | .create = us_qwerty_create,
|
---|
| 49 | .destroy = us_qwerty_destroy,
|
---|
| 50 | .parse_ev = us_qwerty_parse_ev
|
---|
[0175246] | 51 | };
|
---|
| 52 |
|
---|
[28a5ebd] | 53 | static char32_t map_lcase[] = {
|
---|
[f89979b] | 54 | [KC_Q] = 'q',
|
---|
| 55 | [KC_W] = 'w',
|
---|
| 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] = 'a',
|
---|
| 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] = 'z',
|
---|
| 76 | [KC_X] = 'x',
|
---|
| 77 | [KC_C] = 'c',
|
---|
| 78 | [KC_V] = 'v',
|
---|
| 79 | [KC_B] = 'b',
|
---|
| 80 | [KC_N] = 'n',
|
---|
| 81 | [KC_M] = 'm',
|
---|
[d1eece6] | 82 | };
|
---|
| 83 |
|
---|
[28a5ebd] | 84 | static char32_t map_ucase[] = {
|
---|
[d1eece6] | 85 | [KC_Q] = 'Q',
|
---|
| 86 | [KC_W] = 'W',
|
---|
| 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] = 'A',
|
---|
| 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] = 'Z',
|
---|
| 107 | [KC_X] = 'X',
|
---|
| 108 | [KC_C] = 'C',
|
---|
| 109 | [KC_V] = 'V',
|
---|
| 110 | [KC_B] = 'B',
|
---|
| 111 | [KC_N] = 'N',
|
---|
| 112 | [KC_M] = 'M',
|
---|
| 113 | };
|
---|
| 114 |
|
---|
[28a5ebd] | 115 | static char32_t map_not_shifted[] = {
|
---|
[d1eece6] | 116 | [KC_BACKTICK] = '`',
|
---|
| 117 |
|
---|
| 118 | [KC_1] = '1',
|
---|
| 119 | [KC_2] = '2',
|
---|
| 120 | [KC_3] = '3',
|
---|
| 121 | [KC_4] = '4',
|
---|
| 122 | [KC_5] = '5',
|
---|
| 123 | [KC_6] = '6',
|
---|
| 124 | [KC_7] = '7',
|
---|
| 125 | [KC_8] = '8',
|
---|
| 126 | [KC_9] = '9',
|
---|
| 127 | [KC_0] = '0',
|
---|
| 128 |
|
---|
| 129 | [KC_MINUS] = '-',
|
---|
| 130 | [KC_EQUALS] = '=',
|
---|
| 131 |
|
---|
| 132 | [KC_LBRACKET] = '[',
|
---|
| 133 | [KC_RBRACKET] = ']',
|
---|
| 134 |
|
---|
| 135 | [KC_SEMICOLON] = ';',
|
---|
| 136 | [KC_QUOTE] = '\'',
|
---|
| 137 | [KC_BACKSLASH] = '\\',
|
---|
[f89979b] | 138 |
|
---|
| 139 | [KC_COMMA] = ',',
|
---|
| 140 | [KC_PERIOD] = '.',
|
---|
| 141 | [KC_SLASH] = '/',
|
---|
[d1eece6] | 142 | };
|
---|
| 143 |
|
---|
[28a5ebd] | 144 | static char32_t map_shifted[] = {
|
---|
[d1eece6] | 145 | [KC_BACKTICK] = '~',
|
---|
| 146 |
|
---|
| 147 | [KC_1] = '!',
|
---|
| 148 | [KC_2] = '@',
|
---|
| 149 | [KC_3] = '#',
|
---|
| 150 | [KC_4] = '$',
|
---|
| 151 | [KC_5] = '%',
|
---|
| 152 | [KC_6] = '^',
|
---|
| 153 | [KC_7] = '&',
|
---|
| 154 | [KC_8] = '*',
|
---|
| 155 | [KC_9] = '(',
|
---|
| 156 | [KC_0] = ')',
|
---|
| 157 |
|
---|
| 158 | [KC_MINUS] = '_',
|
---|
| 159 | [KC_EQUALS] = '+',
|
---|
| 160 |
|
---|
| 161 | [KC_LBRACKET] = '{',
|
---|
| 162 | [KC_RBRACKET] = '}',
|
---|
| 163 |
|
---|
| 164 | [KC_SEMICOLON] = ':',
|
---|
| 165 | [KC_QUOTE] = '"',
|
---|
| 166 | [KC_BACKSLASH] = '|',
|
---|
| 167 |
|
---|
| 168 | [KC_COMMA] = '<',
|
---|
| 169 | [KC_PERIOD] = '>',
|
---|
| 170 | [KC_SLASH] = '?',
|
---|
| 171 | };
|
---|
[f89979b] | 172 |
|
---|
[28a5ebd] | 173 | static char32_t map_neutral[] = {
|
---|
[d1eece6] | 174 | [KC_BACKSPACE] = '\b',
|
---|
| 175 | [KC_TAB] = '\t',
|
---|
| 176 | [KC_ENTER] = '\n',
|
---|
[90e3d6a] | 177 | [KC_SPACE] = ' ',
|
---|
| 178 |
|
---|
| 179 | [KC_NSLASH] = '/',
|
---|
| 180 | [KC_NTIMES] = '*',
|
---|
| 181 | [KC_NMINUS] = '-',
|
---|
| 182 | [KC_NPLUS] = '+',
|
---|
| 183 | [KC_NENTER] = '\n'
|
---|
| 184 | };
|
---|
| 185 |
|
---|
[28a5ebd] | 186 | static char32_t map_numeric[] = {
|
---|
[90e3d6a] | 187 | [KC_N7] = '7',
|
---|
| 188 | [KC_N8] = '8',
|
---|
| 189 | [KC_N9] = '9',
|
---|
| 190 | [KC_N4] = '4',
|
---|
| 191 | [KC_N5] = '5',
|
---|
| 192 | [KC_N6] = '6',
|
---|
| 193 | [KC_N1] = '1',
|
---|
| 194 | [KC_N2] = '2',
|
---|
| 195 | [KC_N3] = '3',
|
---|
| 196 |
|
---|
| 197 | [KC_N0] = '0',
|
---|
| 198 | [KC_NPERIOD] = '.'
|
---|
[f89979b] | 199 | };
|
---|
| 200 |
|
---|
[28a5ebd] | 201 | static char32_t translate(unsigned int key, char32_t *map, size_t map_length)
|
---|
[d1eece6] | 202 | {
|
---|
[9db4079] | 203 | if (key >= map_length)
|
---|
| 204 | return 0;
|
---|
| 205 | return map[key];
|
---|
[d1eece6] | 206 | }
|
---|
| 207 |
|
---|
[b7fd2a0] | 208 | static errno_t us_qwerty_create(layout_t *state)
|
---|
[d15815e2] | 209 | {
|
---|
[2f7a564] | 210 | return EOK;
|
---|
[d15815e2] | 211 | }
|
---|
| 212 |
|
---|
[2f7a564] | 213 | static void us_qwerty_destroy(layout_t *state)
|
---|
| 214 | {
|
---|
| 215 | }
|
---|
| 216 |
|
---|
[28a5ebd] | 217 | static char32_t us_qwerty_parse_ev(layout_t *state, kbd_event_t *ev)
|
---|
[f89979b] | 218 | {
|
---|
[28a5ebd] | 219 | char32_t c;
|
---|
[d1eece6] | 220 |
|
---|
[28a5ebd] | 221 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(char32_t));
|
---|
[9db4079] | 222 | if (c != 0)
|
---|
| 223 | return c;
|
---|
[d1eece6] | 224 |
|
---|
| 225 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
|
---|
[28a5ebd] | 226 | c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(char32_t));
|
---|
[d1eece6] | 227 | else
|
---|
[28a5ebd] | 228 | c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(char32_t));
|
---|
[d1eece6] | 229 |
|
---|
[9db4079] | 230 | if (c != 0)
|
---|
| 231 | return c;
|
---|
[d1eece6] | 232 |
|
---|
| 233 | if ((ev->mods & KM_SHIFT) != 0)
|
---|
[28a5ebd] | 234 | c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(char32_t));
|
---|
[d1eece6] | 235 | else
|
---|
[28a5ebd] | 236 | c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(char32_t));
|
---|
[d1eece6] | 237 |
|
---|
[9db4079] | 238 | if (c != 0)
|
---|
| 239 | return c;
|
---|
[90e3d6a] | 240 |
|
---|
| 241 | if ((ev->mods & KM_NUM_LOCK) != 0)
|
---|
[28a5ebd] | 242 | c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(char32_t));
|
---|
[90e3d6a] | 243 | else
|
---|
| 244 | c = 0;
|
---|
[d1eece6] | 245 |
|
---|
[90e3d6a] | 246 | return c;
|
---|
[f89979b] | 247 | }
|
---|
| 248 |
|
---|
| 249 | /**
|
---|
| 250 | * @}
|
---|
[1b20da0] | 251 | */
|
---|