00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00034 #include <kbd.h>
00035 #include <io/console.h>
00036 #include <io/keycode.h>
00037 #include <layout.h>
00038
00039 static void layout_reset(void);
00040 static wchar_t layout_parse_ev(console_event_t *ev);
00041
00042 layout_op_t us_qwerty_op = {
00043 layout_reset,
00044 layout_parse_ev
00045 };
00046
00047 static wchar_t map_lcase[] = {
00048 [KC_Q] = 'q',
00049 [KC_W] = 'w',
00050 [KC_E] = 'e',
00051 [KC_R] = 'r',
00052 [KC_T] = 't',
00053 [KC_Y] = 'y',
00054 [KC_U] = 'u',
00055 [KC_I] = 'i',
00056 [KC_O] = 'o',
00057 [KC_P] = 'p',
00058
00059 [KC_A] = 'a',
00060 [KC_S] = 's',
00061 [KC_D] = 'd',
00062 [KC_F] = 'f',
00063 [KC_G] = 'g',
00064 [KC_H] = 'h',
00065 [KC_J] = 'j',
00066 [KC_K] = 'k',
00067 [KC_L] = 'l',
00068
00069 [KC_Z] = 'z',
00070 [KC_X] = 'x',
00071 [KC_C] = 'c',
00072 [KC_V] = 'v',
00073 [KC_B] = 'b',
00074 [KC_N] = 'n',
00075 [KC_M] = 'm',
00076 };
00077
00078 static wchar_t map_ucase[] = {
00079 [KC_Q] = 'Q',
00080 [KC_W] = 'W',
00081 [KC_E] = 'E',
00082 [KC_R] = 'R',
00083 [KC_T] = 'T',
00084 [KC_Y] = 'Y',
00085 [KC_U] = 'U',
00086 [KC_I] = 'I',
00087 [KC_O] = 'O',
00088 [KC_P] = 'P',
00089
00090 [KC_A] = 'A',
00091 [KC_S] = 'S',
00092 [KC_D] = 'D',
00093 [KC_F] = 'F',
00094 [KC_G] = 'G',
00095 [KC_H] = 'H',
00096 [KC_J] = 'J',
00097 [KC_K] = 'K',
00098 [KC_L] = 'L',
00099
00100 [KC_Z] = 'Z',
00101 [KC_X] = 'X',
00102 [KC_C] = 'C',
00103 [KC_V] = 'V',
00104 [KC_B] = 'B',
00105 [KC_N] = 'N',
00106 [KC_M] = 'M',
00107 };
00108
00109 static wchar_t map_not_shifted[] = {
00110 [KC_BACKTICK] = '`',
00111
00112 [KC_1] = '1',
00113 [KC_2] = '2',
00114 [KC_3] = '3',
00115 [KC_4] = '4',
00116 [KC_5] = '5',
00117 [KC_6] = '6',
00118 [KC_7] = '7',
00119 [KC_8] = '8',
00120 [KC_9] = '9',
00121 [KC_0] = '0',
00122
00123 [KC_MINUS] = '-',
00124 [KC_EQUALS] = '=',
00125
00126 [KC_LBRACKET] = '[',
00127 [KC_RBRACKET] = ']',
00128
00129 [KC_SEMICOLON] = ';',
00130 [KC_QUOTE] = '\'',
00131 [KC_BACKSLASH] = '\\',
00132
00133 [KC_COMMA] = ',',
00134 [KC_PERIOD] = '.',
00135 [KC_SLASH] = '/',
00136 };
00137
00138 static wchar_t map_shifted[] = {
00139 [KC_BACKTICK] = '~',
00140
00141 [KC_1] = '!',
00142 [KC_2] = '@',
00143 [KC_3] = '#',
00144 [KC_4] = '$',
00145 [KC_5] = '%',
00146 [KC_6] = '^',
00147 [KC_7] = '&',
00148 [KC_8] = '*',
00149 [KC_9] = '(',
00150 [KC_0] = ')',
00151
00152 [KC_MINUS] = '_',
00153 [KC_EQUALS] = '+',
00154
00155 [KC_LBRACKET] = '{',
00156 [KC_RBRACKET] = '}',
00157
00158 [KC_SEMICOLON] = ':',
00159 [KC_QUOTE] = '"',
00160 [KC_BACKSLASH] = '|',
00161
00162 [KC_COMMA] = '<',
00163 [KC_PERIOD] = '>',
00164 [KC_SLASH] = '?',
00165 };
00166
00167 static wchar_t map_neutral[] = {
00168 [KC_BACKSPACE] = '\b',
00169 [KC_TAB] = '\t',
00170 [KC_ENTER] = '\n',
00171 [KC_SPACE] = ' ',
00172
00173 [KC_NSLASH] = '/',
00174 [KC_NTIMES] = '*',
00175 [KC_NMINUS] = '-',
00176 [KC_NPLUS] = '+',
00177 [KC_NENTER] = '\n'
00178 };
00179
00180 static wchar_t map_numeric[] = {
00181 [KC_N7] = '7',
00182 [KC_N8] = '8',
00183 [KC_N9] = '9',
00184 [KC_N4] = '4',
00185 [KC_N5] = '5',
00186 [KC_N6] = '6',
00187 [KC_N1] = '1',
00188 [KC_N2] = '2',
00189 [KC_N3] = '3',
00190
00191 [KC_N0] = '0',
00192 [KC_NPERIOD] = '.'
00193 };
00194
00195 static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
00196 {
00197 if (key >= map_length)
00198 return 0;
00199 return map[key];
00200 }
00201
00202 static void layout_reset(void)
00203 {
00204 }
00205
00206 static wchar_t layout_parse_ev(console_event_t *ev)
00207 {
00208 wchar_t c;
00209
00210
00211 if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
00212 return 0;
00213
00214 c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t));
00215 if (c != 0)
00216 return c;
00217
00218 if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
00219 c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t));
00220 else
00221 c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t));
00222
00223 if (c != 0)
00224 return c;
00225
00226 if ((ev->mods & KM_SHIFT) != 0)
00227 c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t));
00228 else
00229 c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t));
00230
00231 if (c != 0)
00232 return c;
00233
00234 if ((ev->mods & KM_NUM_LOCK) != 0)
00235 c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t));
00236 else
00237 c = 0;
00238
00239 return c;
00240 }
00241