[453c5ce] | 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 |
|
---|
| 43 | static errno_t fr_azerty_create (layout_t *);
|
---|
| 44 | static void fr_azerty_destroy (layout_t *);
|
---|
[28a5ebd] | 45 | static char32_t fr_azerty_parse_ev (layout_t *, kbd_event_t *);
|
---|
[453c5ce] | 46 |
|
---|
| 47 | layout_ops_t fr_azerty_ops = {
|
---|
| 48 | .create = fr_azerty_create,
|
---|
| 49 | .destroy = fr_azerty_destroy,
|
---|
| 50 | .parse_ev = fr_azerty_parse_ev
|
---|
| 51 | };
|
---|
| 52 |
|
---|
[28a5ebd] | 53 | static char32_t map_lcase[] = {
|
---|
[453c5ce] | 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 |
|
---|
[28a5ebd] | 84 | static char32_t map_ucase[] = {
|
---|
[453c5ce] | 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 |
|
---|
[28a5ebd] | 119 | static char32_t map_not_shifted[] = {
|
---|
[453c5ce] | 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 |
|
---|
[28a5ebd] | 148 | static char32_t map_shifted[] = {
|
---|
[453c5ce] | 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 |
|
---|
[28a5ebd] | 178 | static char32_t map_neutral[] = {
|
---|
[453c5ce] | 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 |
|
---|
[28a5ebd] | 191 | static char32_t map_numeric[] = {
|
---|
[453c5ce] | 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 |
|
---|
[28a5ebd] | 206 | static char32_t translate (unsigned int key, char32_t *map, size_t map_len)
|
---|
[453c5ce] | 207 | {
|
---|
| 208 | if (key >= map_len)
|
---|
| 209 | return 0;
|
---|
| 210 | return map[key];
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | static errno_t fr_azerty_create (layout_t *s)
|
---|
| 214 | {
|
---|
| 215 | return EOK;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | static void fr_azerty_destroy (layout_t *s)
|
---|
| 219 | {
|
---|
| 220 |
|
---|
| 221 | }
|
---|
| 222 |
|
---|
[28a5ebd] | 223 | static char32_t fr_azerty_parse_ev (layout_t *s, kbd_event_t *e)
|
---|
[453c5ce] | 224 | {
|
---|
[28a5ebd] | 225 | char32_t c = translate (e->key, map_neutral, sizeof (map_neutral) / sizeof (char32_t));
|
---|
[453c5ce] | 226 | if (c)
|
---|
| 227 | return c;
|
---|
| 228 |
|
---|
| 229 | if ((e->mods & KM_SHIFT))
|
---|
[28a5ebd] | 230 | c = translate (e->key, map_shifted, sizeof (map_shifted) / sizeof (char32_t));
|
---|
[453c5ce] | 231 | else
|
---|
[28a5ebd] | 232 | c = translate (e->key, map_not_shifted, sizeof (map_not_shifted) / sizeof (char32_t));
|
---|
[453c5ce] | 233 |
|
---|
| 234 | if (c)
|
---|
| 235 | return c;
|
---|
| 236 |
|
---|
| 237 | if (((e->mods & KM_SHIFT)) ^ ((e->mods & KM_CAPS_LOCK)))
|
---|
[28a5ebd] | 238 | c = translate (e->key, map_ucase, sizeof (map_ucase) / sizeof (char32_t));
|
---|
[453c5ce] | 239 | else
|
---|
[28a5ebd] | 240 | c = translate (e->key, map_lcase, sizeof (map_lcase) / sizeof (char32_t));
|
---|
[453c5ce] | 241 |
|
---|
| 242 | if (c)
|
---|
| 243 | return c;
|
---|
| 244 |
|
---|
| 245 | if ((e->mods & KM_NUM_LOCK))
|
---|
[28a5ebd] | 246 | c = translate (e->key, map_numeric, sizeof (map_numeric) / sizeof (char32_t));
|
---|
[453c5ce] | 247 | else
|
---|
| 248 | c = 0;
|
---|
| 249 |
|
---|
| 250 | return c;
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | /**
|
---|
| 254 | * @}
|
---|
| 255 | */
|
---|