src/video/x11/SDL_x11keyboard.c
author Bob Pendleton <bob@pendleton.com>
Sat, 12 Jan 2008 18:07:06 +0000
changeset 2299 a7cbc25071b6
parent 2298 41d2599b7117
child 2305 fbe8ff44c519
permissions -rw-r--r--
Enabled key board auto repeat in X11_InitKeyboard.c. Had to add a couple of new Xlib symbols.
slouken@1950
     1
/*
slouken@1950
     2
    SDL - Simple DirectMedia Layer
slouken@1950
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@1950
     4
slouken@1950
     5
    This library is free software; you can redistribute it and/or
slouken@1950
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1950
     7
    License as published by the Free Software Foundation; either
slouken@1950
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1950
     9
slouken@1950
    10
    This library is distributed in the hope that it will be useful,
slouken@1950
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1950
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1950
    13
    Lesser General Public License for more details.
slouken@1950
    14
slouken@1950
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1950
    16
    License along with this library; if not, write to the Free Software
slouken@1950
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1950
    18
slouken@1950
    19
    Sam Lantinga
slouken@1950
    20
    slouken@libsdl.org
slouken@1950
    21
*/
slouken@1950
    22
#include "SDL_config.h"
slouken@1950
    23
slouken@1950
    24
#include "SDL_x11video.h"
slouken@1950
    25
slouken@1950
    26
#include "../../events/SDL_keyboard_c.h"
slouken@1950
    27
bob@2295
    28
#include <X11/keysym.h>
bob@2295
    29
bob@2295
    30
#include "imKStoUCS.h"
bob@2295
    31
bob@2296
    32
/* 
bob@2296
    33
   KeyCode-to-SDLKey translation tables for various X servers. Which
bob@2296
    34
   one to use is decided in X11_InitKeyboard().
bob@2295
    35
*/
bob@2295
    36
bob@2295
    37
static SDLKey macKeyCodeToSDLK[];
bob@2295
    38
static SDLKey xorgLinuxKeyCodeToSDLK[];
bob@2295
    39
bob@2295
    40
static SDLKey *keyCodeToSDLKeyTables[] = {
bob@2295
    41
    xorgLinuxKeyCodeToSDLK,
bob@2295
    42
    macKeyCodeToSDLK,
bob@2295
    43
    NULL
bob@2295
    44
};
bob@2295
    45
bob@2295
    46
/* *INDENT-OFF* */
bob@2295
    47
bob@2295
    48
/* These are just Mac virtual key codes + 8 (see SDL/src/video/cocoa/
bob@2295
    49
   SDL_cocoakeys.h for more info). Observed to work with Apple X11 on
bob@2295
    50
   Mac OS X 10.4. May also work on older Linux distributions on Mac
bob@2295
    51
   hardware.
bob@2295
    52
*/
bob@2296
    53
bob@2297
    54
#define KeyCodeTableSize (256)
bob@2296
    55
static SDLKey macKeyCodeToSDLK[KeyCodeTableSize] = 
bob@2296
    56
{
bob@2295
    57
    /*   0 */   SDLK_UNKNOWN,
bob@2295
    58
    /*   1 */   SDLK_UNKNOWN,
bob@2295
    59
    /*   2 */   SDLK_UNKNOWN,
bob@2295
    60
    /*   3 */   SDLK_UNKNOWN,
bob@2295
    61
    /*   4 */   SDLK_UNKNOWN,
bob@2295
    62
    /*   5 */   SDLK_UNKNOWN,
bob@2295
    63
    /*   6 */   SDLK_UNKNOWN,
bob@2295
    64
    /*   7 */   SDLK_UNKNOWN,
bob@2295
    65
    /*   8 */   SDLK_A,
bob@2295
    66
    /*   9 */   SDLK_S,
bob@2295
    67
    /*  10 */   SDLK_D,
bob@2295
    68
    /*  11 */   SDLK_F,
bob@2295
    69
    /*  12 */   SDLK_H,
bob@2295
    70
    /*  13 */   SDLK_G,
bob@2295
    71
    /*  14 */   SDLK_Z,
bob@2295
    72
    /*  15 */   SDLK_X,
bob@2295
    73
    /*  16 */   SDLK_C,
bob@2295
    74
    /*  17 */   SDLK_V,
bob@2295
    75
    /*  18 */   SDLK_GRAVE,
bob@2295
    76
    /*  19 */   SDLK_B,
bob@2295
    77
    /*  20 */   SDLK_Q,
bob@2295
    78
    /*  21 */   SDLK_W,
bob@2295
    79
    /*  22 */   SDLK_E,
bob@2295
    80
    /*  23 */   SDLK_R,
bob@2295
    81
    /*  24 */   SDLK_Y,
bob@2295
    82
    /*  25 */   SDLK_T,
bob@2295
    83
    /*  26 */   SDLK_1,
bob@2295
    84
    /*  27 */   SDLK_2,
bob@2295
    85
    /*  28 */   SDLK_3,
bob@2295
    86
    /*  29 */   SDLK_4,
bob@2295
    87
    /*  30 */   SDLK_6,
bob@2295
    88
    /*  31 */   SDLK_5,
bob@2295
    89
    /*  32 */   SDLK_EQUALS,
bob@2295
    90
    /*  33 */   SDLK_9,
bob@2295
    91
    /*  34 */   SDLK_7,
bob@2295
    92
    /*  35 */   SDLK_HYPHENMINUS,
bob@2295
    93
    /*  36 */   SDLK_8,
bob@2295
    94
    /*  37 */   SDLK_0,
bob@2295
    95
    /*  38 */   SDLK_RIGHTBRACKET,
bob@2295
    96
    /*  39 */   SDLK_O,
bob@2295
    97
    /*  40 */   SDLK_U,
bob@2295
    98
    /*  41 */   SDLK_LEFTBRACKET,
bob@2295
    99
    /*  42 */   SDLK_I,
bob@2295
   100
    /*  43 */   SDLK_P,
bob@2295
   101
    /*  44 */   SDLK_RETURN,
bob@2295
   102
    /*  45 */   SDLK_L,
bob@2295
   103
    /*  46 */   SDLK_J,
bob@2295
   104
    /*  47 */   SDLK_APOSTROPHE,
bob@2295
   105
    /*  48 */   SDLK_K,
bob@2295
   106
    /*  49 */   SDLK_SEMICOLON,
bob@2295
   107
    /*  50 */   SDLK_BACKSLASH,
bob@2295
   108
    /*  51 */   SDLK_COMMA,
bob@2295
   109
    /*  52 */   SDLK_SLASH,
bob@2295
   110
    /*  53 */   SDLK_N,
bob@2295
   111
    /*  54 */   SDLK_M,
bob@2295
   112
    /*  55 */   SDLK_PERIOD,
bob@2295
   113
    /*  56 */   SDLK_TAB,
bob@2295
   114
    /*  57 */   SDLK_SPACE,
bob@2295
   115
    /*  58 */   SDLK_NONUSBACKSLASH,
bob@2295
   116
    /*  59 */   SDLK_BACKSPACE,
bob@2295
   117
    /*  60 */   SDLK_KP_ENTER,
bob@2295
   118
    /*  61 */   SDLK_ESCAPE,
bob@2295
   119
    /*  62 */   SDLK_RMETA,
bob@2295
   120
    /*  63 */   SDLK_LMETA,
bob@2295
   121
    /*  64 */   SDLK_LSHIFT,
bob@2295
   122
    /*  65 */   SDLK_CAPSLOCK,
bob@2295
   123
    /*  66 */   SDLK_LALT,
bob@2295
   124
    /*  67 */   SDLK_LCTRL,
bob@2295
   125
    /*  68 */   SDLK_RSHIFT,
bob@2295
   126
    /*  69 */   SDLK_RALT,
bob@2295
   127
    /*  70 */   SDLK_RCTRL,
bob@2295
   128
    /*  71 */   SDLK_NONE,
bob@2295
   129
    /*  72 */   SDLK_UNKNOWN,
bob@2295
   130
    /*  73 */   SDLK_KP_PERIOD,
bob@2295
   131
    /*  74 */   SDLK_UNKNOWN,
bob@2295
   132
    /*  75 */   SDLK_KP_MULTIPLY,
bob@2295
   133
    /*  76 */   SDLK_UNKNOWN,
bob@2295
   134
    /*  77 */   SDLK_KP_PLUS,
bob@2295
   135
    /*  78 */   SDLK_UNKNOWN,
bob@2295
   136
    /*  79 */   SDLK_KP_NUMLOCKCLEAR,
bob@2295
   137
    /*  80 */   SDLK_VOLUMEUP,
bob@2295
   138
    /*  81 */   SDLK_VOLUMEDOWN,
bob@2295
   139
    /*  82 */   SDLK_MUTE,
bob@2295
   140
    /*  83 */   SDLK_KP_DIVIDE,
bob@2295
   141
    /*  84 */   SDLK_KP_ENTER,
bob@2295
   142
    /*  85 */   SDLK_UNKNOWN,
bob@2295
   143
    /*  86 */   SDLK_KP_MINUS,
bob@2295
   144
    /*  87 */   SDLK_UNKNOWN,
bob@2295
   145
    /*  88 */   SDLK_UNKNOWN,
bob@2295
   146
    /*  89 */   SDLK_KP_EQUALS,
bob@2295
   147
    /*  90 */   SDLK_KP_0,
bob@2295
   148
    /*  91 */   SDLK_KP_1,
bob@2295
   149
    /*  92 */   SDLK_KP_2,
bob@2295
   150
    /*  93 */   SDLK_KP_3,
bob@2295
   151
    /*  94 */   SDLK_KP_4,
bob@2295
   152
    /*  95 */   SDLK_KP_5,
bob@2295
   153
    /*  96 */   SDLK_KP_6,
bob@2295
   154
    /*  97 */   SDLK_KP_7,
bob@2295
   155
    /*  98 */   SDLK_UNKNOWN,
bob@2295
   156
    /*  99 */   SDLK_KP_8,
bob@2295
   157
    /* 100 */   SDLK_KP_9,
bob@2295
   158
    /* 101 */   SDLK_INTERNATIONAL3,
bob@2295
   159
    /* 102 */   SDLK_INTERNATIONAL1,
bob@2295
   160
    /* 103 */   SDLK_KP_COMMA,
bob@2295
   161
    /* 104 */   SDLK_F5,
bob@2295
   162
    /* 105 */   SDLK_F6,
bob@2295
   163
    /* 106 */   SDLK_F7,
bob@2295
   164
    /* 107 */   SDLK_F3,
bob@2295
   165
    /* 108 */   SDLK_F8,
bob@2295
   166
    /* 109 */   SDLK_F9,
bob@2295
   167
    /* 110 */   SDLK_LANG2,
bob@2295
   168
    /* 111 */   SDLK_F11,
bob@2295
   169
    /* 112 */   SDLK_LANG1,
bob@2295
   170
    /* 113 */   SDLK_PRINTSCREEN,
bob@2295
   171
    /* 114 */   SDLK_F16,
bob@2295
   172
    /* 115 */   SDLK_SCROLLLOCK,
bob@2295
   173
    /* 116 */   SDLK_UNKNOWN,
bob@2295
   174
    /* 117 */   SDLK_F10,
bob@2295
   175
    /* 118 */   SDLK_APPLICATION,
bob@2295
   176
    /* 119 */   SDLK_F12,
bob@2295
   177
    /* 120 */   SDLK_UNKNOWN,
bob@2295
   178
    /* 121 */   SDLK_PAUSE,
bob@2295
   179
    /* 122 */   SDLK_INSERT,
bob@2295
   180
    /* 123 */   SDLK_HOME,
bob@2295
   181
    /* 124 */   SDLK_PAGEUP,
bob@2295
   182
    /* 125 */   SDLK_DELETE,
bob@2295
   183
    /* 126 */   SDLK_F4,
bob@2295
   184
    /* 127 */   SDLK_END,
bob@2295
   185
    /* 128 */   SDLK_F2,
bob@2295
   186
    /* 129 */   SDLK_PAGEDOWN,
bob@2295
   187
    /* 130 */   SDLK_F1,
bob@2295
   188
    /* 131 */   SDLK_LEFT,
bob@2295
   189
    /* 132 */   SDLK_RIGHT,
bob@2295
   190
    /* 133 */   SDLK_DOWN,
bob@2295
   191
    /* 134 */   SDLK_UP,
bob@2295
   192
    /* 135 */   SDLK_POWER,
bob@2295
   193
    /* 136 */   SDLK_UNKNOWN, /* codes higher than 135 shouldn't occur as Mac virtual keycodes only go to 127 */
bob@2295
   194
    /* 137 */   SDLK_UNKNOWN,
bob@2295
   195
    /* 138 */   SDLK_UNKNOWN,
bob@2295
   196
    /* 139 */   SDLK_UNKNOWN,
bob@2295
   197
    /* 140 */   SDLK_UNKNOWN,
bob@2295
   198
    /* 141 */   SDLK_UNKNOWN,
bob@2295
   199
    /* 142 */   SDLK_UNKNOWN,
bob@2295
   200
    /* 143 */   SDLK_UNKNOWN,
bob@2295
   201
    /* 144 */   SDLK_UNKNOWN,
bob@2295
   202
    /* 145 */   SDLK_UNKNOWN,
bob@2295
   203
    /* 146 */   SDLK_UNKNOWN,
bob@2295
   204
    /* 147 */   SDLK_UNKNOWN,
bob@2295
   205
    /* 148 */   SDLK_UNKNOWN,
bob@2295
   206
    /* 149 */   SDLK_UNKNOWN,
bob@2295
   207
    /* 150 */   SDLK_UNKNOWN,
bob@2295
   208
    /* 151 */   SDLK_UNKNOWN,
bob@2295
   209
    /* 152 */   SDLK_UNKNOWN,
bob@2295
   210
    /* 153 */   SDLK_UNKNOWN,
bob@2295
   211
    /* 154 */   SDLK_UNKNOWN,
bob@2295
   212
    /* 155 */   SDLK_UNKNOWN,
bob@2295
   213
    /* 156 */   SDLK_UNKNOWN,
bob@2295
   214
    /* 157 */   SDLK_UNKNOWN,
bob@2295
   215
    /* 158 */   SDLK_UNKNOWN,
bob@2295
   216
    /* 159 */   SDLK_UNKNOWN,
bob@2295
   217
    /* 160 */   SDLK_UNKNOWN,
bob@2295
   218
    /* 161 */   SDLK_UNKNOWN,
bob@2295
   219
    /* 162 */   SDLK_UNKNOWN,
bob@2295
   220
    /* 163 */   SDLK_UNKNOWN,
bob@2295
   221
    /* 164 */   SDLK_UNKNOWN,
bob@2295
   222
    /* 165 */   SDLK_UNKNOWN,
bob@2295
   223
    /* 166 */   SDLK_UNKNOWN,
bob@2295
   224
    /* 167 */   SDLK_UNKNOWN,
bob@2295
   225
    /* 168 */   SDLK_UNKNOWN,
bob@2295
   226
    /* 169 */   SDLK_UNKNOWN,
bob@2295
   227
    /* 170 */   SDLK_UNKNOWN,
bob@2295
   228
    /* 171 */   SDLK_UNKNOWN,
bob@2295
   229
    /* 172 */   SDLK_UNKNOWN,
bob@2295
   230
    /* 173 */   SDLK_UNKNOWN,
bob@2295
   231
    /* 174 */   SDLK_UNKNOWN,
bob@2295
   232
    /* 175 */   SDLK_UNKNOWN,
bob@2295
   233
    /* 176 */   SDLK_UNKNOWN,
bob@2295
   234
    /* 177 */   SDLK_UNKNOWN,
bob@2295
   235
    /* 178 */   SDLK_UNKNOWN,
bob@2295
   236
    /* 179 */   SDLK_UNKNOWN,
bob@2295
   237
    /* 180 */   SDLK_UNKNOWN,
bob@2295
   238
    /* 181 */   SDLK_UNKNOWN,
bob@2295
   239
    /* 182 */   SDLK_UNKNOWN,
bob@2295
   240
    /* 183 */   SDLK_UNKNOWN,
bob@2295
   241
    /* 184 */   SDLK_UNKNOWN,
bob@2295
   242
    /* 185 */   SDLK_UNKNOWN,
bob@2295
   243
    /* 186 */   SDLK_UNKNOWN,
bob@2295
   244
    /* 187 */   SDLK_UNKNOWN,
bob@2295
   245
    /* 188 */   SDLK_UNKNOWN,
bob@2295
   246
    /* 189 */   SDLK_UNKNOWN,
bob@2295
   247
    /* 190 */   SDLK_UNKNOWN,
bob@2295
   248
    /* 191 */   SDLK_UNKNOWN,
bob@2295
   249
    /* 192 */   SDLK_UNKNOWN,
bob@2295
   250
    /* 193 */   SDLK_UNKNOWN,
bob@2295
   251
    /* 194 */   SDLK_UNKNOWN,
bob@2295
   252
    /* 195 */   SDLK_UNKNOWN,
bob@2295
   253
    /* 196 */   SDLK_UNKNOWN,
bob@2295
   254
    /* 197 */   SDLK_UNKNOWN,
bob@2295
   255
    /* 198 */   SDLK_UNKNOWN,
bob@2295
   256
    /* 199 */   SDLK_UNKNOWN,
bob@2295
   257
    /* 200 */   SDLK_UNKNOWN,
bob@2295
   258
    /* 201 */   SDLK_UNKNOWN,
bob@2295
   259
    /* 202 */   SDLK_UNKNOWN,
bob@2295
   260
    /* 203 */   SDLK_UNKNOWN,
bob@2295
   261
    /* 204 */   SDLK_UNKNOWN,
bob@2295
   262
    /* 205 */   SDLK_UNKNOWN,
bob@2295
   263
    /* 206 */   SDLK_UNKNOWN,
bob@2295
   264
    /* 207 */   SDLK_UNKNOWN,
bob@2295
   265
    /* 208 */   SDLK_UNKNOWN,
bob@2295
   266
    /* 209 */   SDLK_UNKNOWN,
bob@2295
   267
    /* 210 */   SDLK_UNKNOWN,
bob@2295
   268
    /* 211 */   SDLK_UNKNOWN,
bob@2295
   269
    /* 212 */   SDLK_UNKNOWN,
bob@2295
   270
    /* 213 */   SDLK_UNKNOWN,
bob@2295
   271
    /* 214 */   SDLK_UNKNOWN,
bob@2295
   272
    /* 215 */   SDLK_UNKNOWN,
bob@2295
   273
    /* 216 */   SDLK_UNKNOWN,
bob@2295
   274
    /* 217 */   SDLK_UNKNOWN,
bob@2295
   275
    /* 218 */   SDLK_UNKNOWN,
bob@2295
   276
    /* 219 */   SDLK_UNKNOWN,
bob@2295
   277
    /* 220 */   SDLK_UNKNOWN,
bob@2295
   278
    /* 221 */   SDLK_UNKNOWN,
bob@2295
   279
    /* 222 */   SDLK_UNKNOWN,
bob@2295
   280
    /* 223 */   SDLK_UNKNOWN,
bob@2295
   281
    /* 224 */   SDLK_UNKNOWN,
bob@2295
   282
    /* 225 */   SDLK_UNKNOWN,
bob@2295
   283
    /* 226 */   SDLK_UNKNOWN,
bob@2295
   284
    /* 227 */   SDLK_UNKNOWN,
bob@2295
   285
    /* 228 */   SDLK_UNKNOWN,
bob@2295
   286
    /* 229 */   SDLK_UNKNOWN,
bob@2295
   287
    /* 230 */   SDLK_UNKNOWN,
bob@2295
   288
    /* 231 */   SDLK_UNKNOWN,
bob@2295
   289
    /* 232 */   SDLK_UNKNOWN,
bob@2295
   290
    /* 233 */   SDLK_UNKNOWN,
bob@2295
   291
    /* 234 */   SDLK_UNKNOWN,
bob@2295
   292
    /* 235 */   SDLK_UNKNOWN,
bob@2295
   293
    /* 236 */   SDLK_UNKNOWN,
bob@2295
   294
    /* 237 */   SDLK_UNKNOWN,
bob@2295
   295
    /* 238 */   SDLK_UNKNOWN,
bob@2295
   296
    /* 239 */   SDLK_UNKNOWN,
bob@2295
   297
    /* 240 */   SDLK_UNKNOWN,
bob@2295
   298
    /* 241 */   SDLK_UNKNOWN,
bob@2295
   299
    /* 242 */   SDLK_UNKNOWN,
bob@2295
   300
    /* 243 */   SDLK_UNKNOWN,
bob@2295
   301
    /* 244 */   SDLK_UNKNOWN,
bob@2295
   302
    /* 245 */   SDLK_UNKNOWN,
bob@2295
   303
    /* 246 */   SDLK_UNKNOWN,
bob@2295
   304
    /* 247 */   SDLK_UNKNOWN,
bob@2295
   305
    /* 248 */   SDLK_UNKNOWN,
bob@2295
   306
    /* 249 */   SDLK_UNKNOWN,
bob@2295
   307
    /* 250 */   SDLK_UNKNOWN,
bob@2295
   308
    /* 251 */   SDLK_UNKNOWN,
bob@2295
   309
    /* 252 */   SDLK_UNKNOWN,
bob@2295
   310
    /* 253 */   SDLK_UNKNOWN,
bob@2295
   311
    /* 254 */   SDLK_UNKNOWN,
bob@2295
   312
    /* 255 */   SDLK_UNKNOWN
bob@2295
   313
};
bob@2295
   314
bob@2295
   315
/* Found mostly by experimentation with X.org on Linux (Fedora Core 4 and
bob@2295
   316
   Ubuntu Dapper) on PC and PPC Mac hardware, some parts (especially about
bob@2295
   317
   the "multimedia"/"internet" keys) from various sources on the web.
bob@2295
   318
*/
bob@2296
   319
static SDLKey xorgLinuxKeyCodeToSDLK[KeyCodeTableSize] = 
bob@2296
   320
{
bob@2295
   321
    /*   0 */   SDLK_UNKNOWN,
bob@2295
   322
    /*   1 */   SDLK_UNKNOWN,
bob@2295
   323
    /*   2 */   SDLK_UNKNOWN,
bob@2295
   324
    /*   3 */   SDLK_UNKNOWN,
bob@2295
   325
    /*   4 */   SDLK_UNKNOWN,
bob@2295
   326
    /*   5 */   SDLK_UNKNOWN,
bob@2295
   327
    /*   6 */   SDLK_UNKNOWN,
bob@2295
   328
    /*   7 */   SDLK_UNKNOWN,
bob@2295
   329
    /*   8 */   SDLK_UNKNOWN,
bob@2295
   330
    /*   9 */   SDLK_ESCAPE,
bob@2295
   331
    /*  10 */   SDLK_1,
bob@2295
   332
    /*  11 */   SDLK_2,
bob@2295
   333
    /*  12 */   SDLK_3,
bob@2295
   334
    /*  13 */   SDLK_4,
bob@2295
   335
    /*  14 */   SDLK_5,
bob@2295
   336
    /*  15 */   SDLK_6,
bob@2295
   337
    /*  16 */   SDLK_7,
bob@2295
   338
    /*  17 */   SDLK_8,
bob@2295
   339
    /*  18 */   SDLK_9,
bob@2295
   340
    /*  19 */   SDLK_0,
bob@2295
   341
    /*  20 */   SDLK_HYPHENMINUS,
bob@2295
   342
    /*  21 */   SDLK_EQUALS,
bob@2295
   343
    /*  22 */   SDLK_BACKSPACE,
bob@2295
   344
    /*  23 */   SDLK_TAB,
bob@2295
   345
    /*  24 */   SDLK_Q,
bob@2295
   346
    /*  25 */   SDLK_W,
bob@2295
   347
    /*  26 */   SDLK_E,
bob@2295
   348
    /*  27 */   SDLK_R,
bob@2295
   349
    /*  28 */   SDLK_T,
bob@2295
   350
    /*  29 */   SDLK_Y,
bob@2295
   351
    /*  30 */   SDLK_U,
bob@2295
   352
    /*  31 */   SDLK_I,
bob@2295
   353
    /*  32 */   SDLK_O,
bob@2295
   354
    /*  33 */   SDLK_P,
bob@2295
   355
    /*  34 */   SDLK_LEFTBRACKET,
bob@2295
   356
    /*  35 */   SDLK_RIGHTBRACKET,
bob@2295
   357
    /*  36 */   SDLK_RETURN,
bob@2295
   358
    /*  37 */   SDLK_LCTRL,
bob@2295
   359
    /*  38 */   SDLK_A,
bob@2295
   360
    /*  39 */   SDLK_S,
bob@2295
   361
    /*  40 */   SDLK_D,
bob@2295
   362
    /*  41 */   SDLK_F,
bob@2295
   363
    /*  42 */   SDLK_G,
bob@2295
   364
    /*  43 */   SDLK_H,
bob@2295
   365
    /*  44 */   SDLK_J,
bob@2295
   366
    /*  45 */   SDLK_K,
bob@2295
   367
    /*  46 */   SDLK_L,
bob@2295
   368
    /*  47 */   SDLK_SEMICOLON,
bob@2295
   369
    /*  48 */   SDLK_APOSTROPHE,
bob@2295
   370
    /*  49 */   SDLK_GRAVE,
bob@2295
   371
    /*  50 */   SDLK_LSHIFT,
bob@2295
   372
    /*  51 */   SDLK_BACKSLASH,
bob@2295
   373
    /*  52 */   SDLK_Z,
bob@2295
   374
    /*  53 */   SDLK_X,
bob@2295
   375
    /*  54 */   SDLK_C,
bob@2295
   376
    /*  55 */   SDLK_V,
bob@2295
   377
    /*  56 */   SDLK_B,
bob@2295
   378
    /*  57 */   SDLK_N,
bob@2295
   379
    /*  58 */   SDLK_M,
bob@2295
   380
    /*  59 */   SDLK_COMMA,
bob@2295
   381
    /*  60 */   SDLK_PERIOD,
bob@2295
   382
    /*  61 */   SDLK_SLASH,
bob@2295
   383
    /*  62 */   SDLK_RSHIFT,
bob@2295
   384
    /*  63 */   SDLK_KP_MULTIPLY,
bob@2295
   385
    /*  64 */   SDLK_LALT,
bob@2295
   386
    /*  65 */   SDLK_SPACE,
bob@2295
   387
    /*  66 */   SDLK_CAPSLOCK,
bob@2295
   388
    /*  67 */   SDLK_F1,
bob@2295
   389
    /*  68 */   SDLK_F2,
bob@2295
   390
    /*  69 */   SDLK_F3,
bob@2295
   391
    /*  70 */   SDLK_F4,
bob@2295
   392
    /*  71 */   SDLK_F5,
bob@2295
   393
    /*  72 */   SDLK_F6,
bob@2295
   394
    /*  73 */   SDLK_F7,
bob@2295
   395
    /*  74 */   SDLK_F8,
bob@2295
   396
    /*  75 */   SDLK_F9,
bob@2295
   397
    /*  76 */   SDLK_F10,
bob@2295
   398
    /*  77 */   SDLK_KP_NUMLOCKCLEAR,
bob@2295
   399
    /*  78 */   SDLK_SCROLLLOCK,
bob@2295
   400
    /*  79 */   SDLK_KP_7,
bob@2295
   401
    /*  80 */   SDLK_KP_8,
bob@2295
   402
    /*  81 */   SDLK_KP_9,
bob@2295
   403
    /*  82 */   SDLK_KP_MINUS,
bob@2295
   404
    /*  83 */   SDLK_KP_4,
bob@2295
   405
    /*  84 */   SDLK_KP_5,
bob@2295
   406
    /*  85 */   SDLK_KP_6,
bob@2295
   407
    /*  86 */   SDLK_KP_PLUS,
bob@2295
   408
    /*  87 */   SDLK_KP_1,
bob@2295
   409
    /*  88 */   SDLK_KP_2,
bob@2295
   410
    /*  89 */   SDLK_KP_3,
bob@2295
   411
    /*  90 */   SDLK_KP_0,
bob@2295
   412
    /*  91 */   SDLK_KP_PERIOD,
bob@2295
   413
    /*  92 */   SDLK_SYSREQ,
bob@2295
   414
    /*  93 */   SDLK_MODE, /* is translated to XK_Mode_switch by my X server, but I have no keyboard that generates this code, so I'm not sure if this is correct */
bob@2295
   415
    /*  94 */   SDLK_NONUSBACKSLASH,
bob@2295
   416
    /*  95 */   SDLK_F11,
bob@2295
   417
    /*  96 */   SDLK_F12,
bob@2295
   418
    /*  97 */   SDLK_HOME,
bob@2295
   419
    /*  98 */   SDLK_UP,
bob@2295
   420
    /*  99 */   SDLK_PAGEUP,
bob@2295
   421
    /* 100 */   SDLK_LEFT,
bob@2295
   422
    /* 101 */   SDLK_BRIGHTNESSDOWN, /* on PowerBook G4 */
bob@2295
   423
    /* 102 */   SDLK_RIGHT,
bob@2295
   424
    /* 103 */   SDLK_END,
bob@2295
   425
    /* 104 */   SDLK_DOWN,
bob@2295
   426
    /* 105 */   SDLK_PAGEDOWN,
bob@2295
   427
    /* 106 */   SDLK_INSERT,
bob@2295
   428
    /* 107 */   SDLK_DELETE,
bob@2295
   429
    /* 108 */   SDLK_KP_ENTER,
bob@2295
   430
    /* 109 */   SDLK_RCTRL,
bob@2295
   431
    /* 110 */   SDLK_PAUSE,
bob@2295
   432
    /* 111 */   SDLK_PRINTSCREEN,
bob@2295
   433
    /* 112 */   SDLK_KP_DIVIDE,
bob@2295
   434
    /* 113 */   SDLK_RALT,
bob@2295
   435
    /* 114 */   SDLK_UNKNOWN,
bob@2295
   436
    /* 115 */   SDLK_LMETA,
bob@2295
   437
    /* 116 */   SDLK_RMETA,
bob@2295
   438
    /* 117 */   SDLK_APPLICATION,
bob@2295
   439
    /* 118 */   SDLK_F13,
bob@2295
   440
    /* 119 */   SDLK_F14,
bob@2295
   441
    /* 120 */   SDLK_F15,
bob@2295
   442
    /* 121 */   SDLK_F16,
bob@2295
   443
    /* 122 */   SDLK_F17,
bob@2295
   444
    /* 123 */   SDLK_UNKNOWN,
bob@2295
   445
    /* 124 */   SDLK_UNKNOWN, /* is translated to XK_ISO_Level3_Shift by my X server, but I have no keyboard that generates this code, so I don't know what the correct SDLK_* for it is */
bob@2295
   446
    /* 125 */   SDLK_UNKNOWN,
bob@2295
   447
    /* 126 */   SDLK_KP_EQUALS,
bob@2295
   448
    /* 127 */   SDLK_UNKNOWN,
bob@2295
   449
    /* 128 */   SDLK_UNKNOWN,
bob@2295
   450
    /* 129 */   SDLK_UNKNOWN,
bob@2295
   451
    /* 130 */   SDLK_UNKNOWN,
bob@2295
   452
    /* 131 */   SDLK_UNKNOWN,
bob@2295
   453
    /* 132 */   SDLK_UNKNOWN,
bob@2295
   454
    /* 133 */   SDLK_INTERNATIONAL3, /* Yen */
bob@2295
   455
    /* 134 */   SDLK_UNKNOWN,
bob@2295
   456
    /* 135 */   SDLK_AGAIN,
bob@2295
   457
    /* 136 */   SDLK_UNDO,
bob@2295
   458
    /* 137 */   SDLK_UNKNOWN,
bob@2295
   459
    /* 138 */   SDLK_UNKNOWN,
bob@2295
   460
    /* 139 */   SDLK_UNKNOWN,
bob@2295
   461
    /* 140 */   SDLK_UNKNOWN,
bob@2295
   462
    /* 141 */   SDLK_UNKNOWN,
bob@2295
   463
    /* 142 */   SDLK_UNKNOWN,
bob@2295
   464
    /* 143 */   SDLK_UNKNOWN,
bob@2295
   465
    /* 144 */   SDLK_AUDIOPREV,
bob@2295
   466
    /* 145 */   SDLK_UNKNOWN,
bob@2295
   467
    /* 146 */   SDLK_UNKNOWN,
bob@2295
   468
    /* 147 */   SDLK_UNKNOWN,
bob@2295
   469
    /* 148 */   SDLK_UNKNOWN,
bob@2295
   470
    /* 149 */   SDLK_UNKNOWN,
bob@2295
   471
    /* 150 */   SDLK_UNKNOWN,
bob@2295
   472
    /* 151 */   SDLK_UNKNOWN,
bob@2295
   473
    /* 152 */   SDLK_UNKNOWN,
bob@2295
   474
    /* 153 */   SDLK_AUDIONEXT,
bob@2295
   475
    /* 154 */   SDLK_UNKNOWN,
bob@2295
   476
    /* 155 */   SDLK_UNKNOWN,
bob@2295
   477
    /* 156 */   SDLK_UNKNOWN,
bob@2295
   478
    /* 157 */   SDLK_KP_EQUALS, /* on PowerBook G4 */
bob@2295
   479
    /* 158 */   SDLK_UNKNOWN,
bob@2295
   480
    /* 159 */   SDLK_UNKNOWN,
bob@2295
   481
    /* 160 */   SDLK_MUTE,
bob@2295
   482
    /* 161 */   SDLK_CALC,
bob@2295
   483
    /* 162 */   SDLK_AUDIOPLAY,
bob@2295
   484
    /* 163 */   SDLK_UNKNOWN,
bob@2295
   485
    /* 164 */   SDLK_AUDIOSTOP,
bob@2295
   486
    /* 165 */   SDLK_UNKNOWN,
bob@2295
   487
    /* 166 */   SDLK_UNKNOWN,
bob@2295
   488
    /* 167 */   SDLK_UNKNOWN,
bob@2295
   489
    /* 168 */   SDLK_UNKNOWN,
bob@2295
   490
    /* 169 */   SDLK_UNKNOWN,
bob@2295
   491
    /* 170 */   SDLK_UNKNOWN,
bob@2295
   492
    /* 171 */   SDLK_UNKNOWN,
bob@2295
   493
    /* 172 */   SDLK_UNKNOWN,
bob@2295
   494
    /* 173 */   SDLK_UNKNOWN,
bob@2295
   495
    /* 174 */   SDLK_VOLUMEDOWN,
bob@2295
   496
    /* 175 */   SDLK_UNKNOWN,
bob@2295
   497
    /* 176 */   SDLK_VOLUMEUP,
bob@2295
   498
    /* 177 */   SDLK_UNKNOWN,
bob@2295
   499
    /* 178 */   SDLK_WWW,
bob@2295
   500
    /* 179 */   SDLK_UNKNOWN,
bob@2295
   501
    /* 180 */   SDLK_UNKNOWN,
bob@2295
   502
    /* 181 */   SDLK_UNKNOWN,
bob@2295
   503
    /* 182 */   SDLK_UNKNOWN,
bob@2295
   504
    /* 183 */   SDLK_UNKNOWN,
bob@2295
   505
    /* 184 */   SDLK_UNKNOWN,
bob@2295
   506
    /* 185 */   SDLK_UNKNOWN,
bob@2295
   507
    /* 186 */   SDLK_UNKNOWN,
bob@2295
   508
    /* 187 */   SDLK_HELP,
bob@2295
   509
    /* 188 */   SDLK_UNKNOWN,
bob@2295
   510
    /* 189 */   SDLK_UNKNOWN,
bob@2295
   511
    /* 190 */   SDLK_UNKNOWN,
bob@2295
   512
    /* 191 */   SDLK_UNKNOWN,
bob@2295
   513
    /* 192 */   SDLK_UNKNOWN,
bob@2295
   514
    /* 193 */   SDLK_UNKNOWN,
bob@2295
   515
    /* 194 */   SDLK_UNKNOWN,
bob@2295
   516
    /* 195 */   SDLK_UNKNOWN,
bob@2295
   517
    /* 196 */   SDLK_UNKNOWN,
bob@2295
   518
    /* 197 */   SDLK_UNKNOWN,
bob@2295
   519
    /* 198 */   SDLK_UNKNOWN,
bob@2295
   520
    /* 199 */   SDLK_UNKNOWN,
bob@2295
   521
    /* 200 */   SDLK_UNKNOWN,
bob@2295
   522
    /* 201 */   SDLK_UNKNOWN,
bob@2295
   523
    /* 202 */   SDLK_UNKNOWN,
bob@2295
   524
    /* 203 */   SDLK_UNKNOWN,
bob@2295
   525
    /* 204 */   SDLK_EJECT, /* on PowerBook G4 */
bob@2295
   526
    /* 205 */   SDLK_UNKNOWN,
bob@2295
   527
    /* 206 */   SDLK_UNKNOWN,
bob@2295
   528
    /* 207 */   SDLK_UNKNOWN,
bob@2295
   529
    /* 208 */   SDLK_UNKNOWN,
bob@2295
   530
    /* 209 */   SDLK_UNKNOWN,
bob@2295
   531
    /* 210 */   SDLK_UNKNOWN,
bob@2295
   532
    /* 211 */   SDLK_UNKNOWN,
bob@2295
   533
    /* 212 */   SDLK_BRIGHTNESSUP, /* on PowerBook G4 */
bob@2295
   534
    /* 213 */   SDLK_UNKNOWN,
bob@2295
   535
    /* 214 */   SDLK_DISPLAYSWITCH, /* on PowerBook G4 */
bob@2295
   536
    /* 215 */   SDLK_KBDILLUMTOGGLE,
bob@2295
   537
    /* 216 */   SDLK_KBDILLUMDOWN,
bob@2295
   538
    /* 217 */   SDLK_KBDILLUMUP,
bob@2295
   539
    /* 218 */   SDLK_UNKNOWN,
bob@2295
   540
    /* 219 */   SDLK_UNKNOWN,
bob@2295
   541
    /* 220 */   SDLK_UNKNOWN,
bob@2295
   542
    /* 221 */   SDLK_UNKNOWN,
bob@2295
   543
    /* 222 */   SDLK_POWER,
bob@2295
   544
    /* 223 */   SDLK_SLEEP,
bob@2295
   545
    /* 224 */   SDLK_UNKNOWN,
bob@2295
   546
    /* 225 */   SDLK_UNKNOWN,
bob@2295
   547
    /* 226 */   SDLK_UNKNOWN,
bob@2295
   548
    /* 227 */   SDLK_UNKNOWN,
bob@2295
   549
    /* 228 */   SDLK_UNKNOWN,
bob@2295
   550
    /* 229 */   SDLK_SEARCH,
bob@2295
   551
    /* 230 */   SDLK_BOOKMARKS,
bob@2295
   552
    /* 231 */   SDLK_BROWSERRELOAD,
bob@2295
   553
    /* 232 */   SDLK_BROWSERSTOP,
bob@2295
   554
    /* 233 */   SDLK_BROWSERFORWARD,
bob@2295
   555
    /* 234 */   SDLK_BROWSERBACK,
bob@2295
   556
    /* 235 */   SDLK_COMPUTER,
bob@2295
   557
    /* 236 */   SDLK_EMAIL,
bob@2295
   558
    /* 237 */   SDLK_MEDIA,
bob@2295
   559
    /* 238 */   SDLK_UNKNOWN,
bob@2295
   560
    /* 239 */   SDLK_UNKNOWN,
bob@2295
   561
    /* 240 */   SDLK_UNKNOWN,
bob@2295
   562
    /* 241 */   SDLK_UNKNOWN,
bob@2295
   563
    /* 242 */   SDLK_UNKNOWN,
bob@2295
   564
    /* 243 */   SDLK_UNKNOWN,
bob@2295
   565
    /* 244 */   SDLK_UNKNOWN,
bob@2295
   566
    /* 245 */   SDLK_UNKNOWN,
bob@2295
   567
    /* 246 */   SDLK_UNKNOWN,
bob@2295
   568
    /* 247 */   SDLK_UNKNOWN,
bob@2295
   569
    /* 248 */   SDLK_UNKNOWN,
bob@2295
   570
    /* 249 */   SDLK_UNKNOWN,
bob@2295
   571
    /* 250 */   SDLK_UNKNOWN,
bob@2295
   572
    /* 251 */   SDLK_UNKNOWN,
bob@2295
   573
    /* 252 */   SDLK_UNKNOWN,
bob@2295
   574
    /* 253 */   SDLK_UNKNOWN,
bob@2295
   575
    /* 254 */   SDLK_UNKNOWN,
bob@2295
   576
    /* 255 */   SDLK_UNKNOWN
bob@2295
   577
};
bob@2295
   578
bob@2295
   579
/*---------------------------------------------------------------------------*/
bob@2295
   580
bob@2295
   581
/* Used by X11_KeySymToSDLKey(). This is a hybrid of a KeySym-to-layout-key
bob@2295
   582
    mapping (needed in X11_GetLayoutKey()) and a fallback KeySym-to-physical-key
bob@2295
   583
    mapping under the assumption of a US keyboard layout (needed in
bob@2295
   584
    X11_InitKeyboard()). If for a given KeySym...
bob@2295
   585
    - the layout and physical codes are the same (must be an SDLK_ constant):
bob@2295
   586
      there is one entry,
bob@2295
   587
    - the layout and physical codes differ: there are two entries, with the
bob@2295
   588
      layout one first,
bob@2295
   589
    - there is only a physical code in the table (must be an SDLK_ constant):
bob@2295
   590
      it's marked by X11_KEY_PHYSICAL_ONLY_BIT (this is the case when the layout
bob@2295
   591
      key code is handled by KeySymToUcs4()),
bob@2295
   592
    - there is only a layout code in the table (can't be an SDLK_ constant):
bob@2295
   593
      recognizable by the absence of SDL_KEY_CAN_BE_PHYSICAL_BIT.
bob@2295
   594
    This list is sorted by KeySym to allow a binary search.
bob@2295
   595
*/
bob@2295
   596
#define X11_KEY_PHYSICAL_ONLY_BIT SDL_KEY_LAYOUT_SPECIAL_BIT
bob@2295
   597
/* SDL_KEY_LAYOUT_SPECIAL_BIT cannot possibly occur in an SDLK_ constant, so we may repurpose that bit for our own use. */
bob@2295
   598
static struct
bob@2295
   599
{
bob@2295
   600
    KeySym sym;
bob@2295
   601
    SDLKey key;
bob@2296
   602
} keySymToSDLKey[KeyCodeTableSize] = 
bob@2296
   603
{
bob@2295
   604
    /* 0x00xx */
bob@2296
   605
    {XK_space, SDLK_SPACE},
bob@2296
   606
    {XK_apostrophe, SDLK_APOSTROPHE | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   607
    {XK_comma, SDLK_COMMA | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   608
    {XK_minus, SDLK_HYPHENMINUS | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   609
    {XK_period, SDLK_PERIOD | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   610
    {XK_slash, SDLK_SLASH | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   611
    {XK_0, SDLK_0 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   612
    {XK_1, SDLK_1 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   613
    {XK_2, SDLK_2 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   614
    {XK_3, SDLK_3 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   615
    {XK_4, SDLK_4 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   616
    {XK_5, SDLK_5 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   617
    {XK_6, SDLK_6 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   618
    {XK_7, SDLK_7 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   619
    {XK_8, SDLK_8 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   620
    {XK_9, SDLK_9 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   621
    {XK_semicolon, SDLK_SEMICOLON | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   622
    {XK_less, SDLK_NONUSBACKSLASH | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   623
    {XK_equal, SDLK_EQUALS | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   624
    {XK_bracketleft, SDLK_LEFTBRACKET | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   625
    {XK_backslash, SDLK_BACKSLASH | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   626
    {XK_bracketright, SDLK_RIGHTBRACKET | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   627
    {XK_grave, SDLK_GRAVE | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   628
    {XK_a, SDLK_A | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   629
    {XK_b, SDLK_B | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   630
    {XK_c, SDLK_C | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   631
    {XK_d, SDLK_D | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   632
    {XK_e, SDLK_E | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   633
    {XK_f, SDLK_F | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   634
    {XK_g, SDLK_G | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   635
    {XK_h, SDLK_H | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   636
    {XK_i, SDLK_I | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   637
    {XK_j, SDLK_J | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   638
    {XK_k, SDLK_K | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   639
    {XK_l, SDLK_L | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   640
    {XK_m, SDLK_M | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   641
    {XK_n, SDLK_N | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   642
    {XK_o, SDLK_O | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   643
    {XK_p, SDLK_P | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   644
    {XK_q, SDLK_Q | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   645
    {XK_r, SDLK_R | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   646
    {XK_s, SDLK_S | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   647
    {XK_t, SDLK_T | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   648
    {XK_u, SDLK_U | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   649
    {XK_v, SDLK_V | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   650
    {XK_w, SDLK_W | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   651
    {XK_x, SDLK_X | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   652
    {XK_y, SDLK_Y | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   653
    {XK_z, SDLK_Z | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   654
    {XK_section, SDLK_NONUSBACKSLASH | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2295
   655
        /* 0xFExx */
bob@2296
   656
    {XK_ISO_Level3_Shift, SDLK_RALT},
bob@2296
   657
    {XK_dead_grave, '`'},
bob@2296
   658
    {XK_dead_acute, 0xB4},
bob@2296
   659
    {XK_dead_circumflex, '^'},
bob@2296
   660
    {XK_dead_tilde, '~'},
bob@2296
   661
    {XK_dead_macron, 0xAF},
bob@2296
   662
    {XK_dead_breve, 0x2D8},
bob@2296
   663
    {XK_dead_abovedot, 0x2D9},
bob@2296
   664
    {XK_dead_diaeresis, 0xA8},
bob@2296
   665
    {XK_dead_abovering, 0x2DA},
bob@2296
   666
    {XK_dead_doubleacute, 0x2DD},
bob@2296
   667
    {XK_dead_caron, 0x2C7},
bob@2296
   668
    {XK_dead_cedilla, 0xB8},
bob@2296
   669
    {XK_dead_ogonek, 0x2DB},
bob@2296
   670
    {XK_dead_iota, 0x3B9},
bob@2296
   671
    {XK_dead_voiced_sound, 0x309B},
bob@2296
   672
    {XK_dead_semivoiced_sound, 0x309C},
bob@2296
   673
    {XK_dead_belowdot, 0xB7},        /* that's actually MIDDLE DOT,
bob@2296
   674
                                        but I haven't found a
bob@2296
   675
                                        non-combining DOT BELOW
bob@2296
   676
                                        XK_dead_hook, XK_dead_horn: I
bob@2296
   677
                                        haven't found non-combining
bob@2296
   678
                                        HOOK and HORN characters */
bob@2296
   679
    /* 0xFFxx */
bob@2296
   680
    {XK_BackSpace, SDLK_BACKSPACE},
bob@2296
   681
    {XK_Tab, SDLK_TAB},
bob@2296
   682
    {XK_Return, SDLK_RETURN},
bob@2296
   683
    {XK_Pause, SDLK_PAUSE},
bob@2296
   684
    {XK_Scroll_Lock, SDLK_SCROLLLOCK},
bob@2296
   685
    {XK_Escape, SDLK_ESCAPE},
bob@2296
   686
    {XK_Home, SDLK_HOME},
bob@2296
   687
    {XK_Left, SDLK_LEFT},
bob@2296
   688
    {XK_Up, SDLK_UP},
bob@2296
   689
    {XK_Right, SDLK_RIGHT},
bob@2296
   690
    {XK_Down, SDLK_DOWN},
bob@2296
   691
    {XK_Page_Up, SDLK_PAGEUP},
bob@2296
   692
    {XK_Page_Down, SDLK_PAGEDOWN},
bob@2296
   693
    {XK_End, SDLK_END},
bob@2296
   694
    {XK_Print, SDLK_PRINTSCREEN},
bob@2296
   695
    {XK_Insert, SDLK_INSERT},
bob@2296
   696
    {XK_Menu, SDLK_APPLICATION},
bob@2296
   697
    {XK_Break, SDLK_PAUSE},
bob@2296
   698
    {XK_Mode_switch, SDLK_MODE},
bob@2296
   699
    {XK_Num_Lock, SDLK_KP_NUMLOCKCLEAR},
bob@2296
   700
    {XK_KP_Enter, SDLK_KP_ENTER},
bob@2296
   701
    {XK_KP_Home, SDLK_KP_7 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   702
    {XK_KP_Left, SDLK_KP_4 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   703
    {XK_KP_Up, SDLK_KP_8 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   704
    {XK_KP_Right, SDLK_KP_6 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   705
    {XK_KP_Down, SDLK_KP_2 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   706
    {XK_KP_Page_Up, SDLK_KP_9 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   707
    {XK_KP_Page_Down, SDLK_KP_3 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   708
    {XK_KP_End, SDLK_KP_1 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   709
    {XK_KP_Begin, SDLK_KP_5 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   710
    {XK_KP_Insert, SDLK_KP_0 | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   711
    {XK_KP_Delete, SDLK_KP_PERIOD | X11_KEY_PHYSICAL_ONLY_BIT},
bob@2296
   712
    {XK_KP_Multiply, '*'},
bob@2296
   713
    {XK_KP_Multiply, SDLK_KP_MULTIPLY},
bob@2296
   714
    {XK_KP_Add, '+'},
bob@2296
   715
    {XK_KP_Add, SDLK_KP_PLUS},
bob@2296
   716
    {XK_KP_Separator, '.'},
bob@2296
   717
    {XK_KP_Separator, SDLK_KP_PERIOD},
bob@2296
   718
    {XK_KP_Subtract, '-'},
bob@2296
   719
    {XK_KP_Subtract, SDLK_KP_MINUS},
bob@2296
   720
    {XK_KP_Decimal, '.'},
bob@2296
   721
    {XK_KP_Decimal, SDLK_KP_PERIOD},
bob@2296
   722
    {XK_KP_Divide, '/'},
bob@2296
   723
    {XK_KP_Divide, SDLK_KP_DIVIDE},
bob@2296
   724
    {XK_KP_0, '0'},
bob@2296
   725
    {XK_KP_0, SDLK_KP_0},
bob@2296
   726
    {XK_KP_1, '1'},
bob@2296
   727
    {XK_KP_1, SDLK_KP_1},
bob@2296
   728
    {XK_KP_2, '2'},
bob@2296
   729
    {XK_KP_2, SDLK_KP_2},
bob@2296
   730
    {XK_KP_3, '3'},
bob@2296
   731
    {XK_KP_3, SDLK_KP_3},
bob@2296
   732
    {XK_KP_4, '4'},
bob@2296
   733
    {XK_KP_4, SDLK_KP_4},
bob@2296
   734
    {XK_KP_5, '5'},
bob@2296
   735
    {XK_KP_5, SDLK_KP_5},
bob@2296
   736
    {XK_KP_6, '6'},
bob@2296
   737
    {XK_KP_6, SDLK_KP_6},
bob@2296
   738
    {XK_KP_7, '7'},
bob@2296
   739
    {XK_KP_7, SDLK_KP_7},
bob@2296
   740
    {XK_KP_8, '8'},
bob@2296
   741
    {XK_KP_8, SDLK_KP_8},
bob@2296
   742
    {XK_KP_9, '9'},
bob@2296
   743
    {XK_KP_9, SDLK_KP_9},
bob@2296
   744
    {XK_KP_Equal, '='},
bob@2296
   745
    {XK_KP_Equal, SDLK_KP_EQUALS},
bob@2296
   746
    {XK_F1, SDLK_F1},
bob@2296
   747
    {XK_F2, SDLK_F2},
bob@2296
   748
    {XK_F3, SDLK_F3},
bob@2296
   749
    {XK_F4, SDLK_F4},
bob@2296
   750
    {XK_F5, SDLK_F5},
bob@2296
   751
    {XK_F6, SDLK_F6},
bob@2296
   752
    {XK_F7, SDLK_F7},
bob@2296
   753
    {XK_F8, SDLK_F8},
bob@2296
   754
    {XK_F9, SDLK_F9},
bob@2296
   755
    {XK_F10, SDLK_F10},
bob@2296
   756
    {XK_F11, SDLK_F11},
bob@2296
   757
    {XK_F12, SDLK_F12},
bob@2296
   758
    {XK_F13, SDLK_F13},
bob@2296
   759
    {XK_F14, SDLK_F14},
bob@2296
   760
    {XK_F15, SDLK_F15},
bob@2296
   761
    {XK_F16, SDLK_F16},
bob@2296
   762
    {XK_F17, SDLK_F17},
bob@2296
   763
    {XK_F18, SDLK_F18},
bob@2296
   764
    {XK_F19, SDLK_F19},
bob@2296
   765
    {XK_F20, SDLK_F20},
bob@2296
   766
    {XK_F21, SDLK_F21},
bob@2296
   767
    {XK_F22, SDLK_F22},
bob@2296
   768
    {XK_F23, SDLK_F23},
bob@2296
   769
    {XK_F24, SDLK_F24},
bob@2296
   770
    {XK_Shift_L, SDLK_LSHIFT},
bob@2296
   771
    {XK_Shift_R, SDLK_RSHIFT},
bob@2296
   772
    {XK_Control_L, SDLK_LCTRL},
bob@2296
   773
    {XK_Control_R, SDLK_RCTRL},
bob@2296
   774
    {XK_Caps_Lock, SDLK_CAPSLOCK},
bob@2296
   775
    {XK_Shift_Lock, SDLK_CAPSLOCK},
bob@2296
   776
    {XK_Meta_L, SDLK_LMETA},
bob@2296
   777
    {XK_Meta_R, SDLK_RMETA},
bob@2296
   778
    {XK_Alt_L, SDLK_LALT},
bob@2296
   779
    {XK_Alt_R, SDLK_RALT},
bob@2296
   780
    {XK_Super_L, SDLK_LMETA},
bob@2296
   781
    {XK_Super_R, SDLK_RMETA},
bob@2296
   782
    {XK_Hyper_L, SDLK_LMETA},
bob@2296
   783
    {XK_Hyper_R, SDLK_RMETA},
bob@2296
   784
    {XK_Delete, SDLK_DELETE},
bob@2296
   785
    {0x1000003, SDLK_KP_ENTER}   /* keyboard enter on Mac OS X */
bob@2295
   786
};
bob@2295
   787
bob@2296
   788
/* *INDENT-ON* */
bob@2296
   789
bob@2296
   790
/* 
bob@2296
   791
   Used for two purposes: - by X11_GetLayoutKey(), with physical =
bob@2296
   792
   false, to convert a KeySym to the corresponding layout key code
bob@2296
   793
   (SDLK_ ones and some character ones - most character KeySyms are
bob@2296
   794
   handled by X11_KeySymToUcs4() after this function returns
bob@2296
   795
   SDLK_UNKNOWN for them).  - by X11_InitKeyboard(), with physical =
bob@2296
   796
   true, to build a makeshift translation table based on the KeySyms
bob@2296
   797
   when none of the predefined KeyCode- to-SDLKey tables fits. This
bob@2296
   798
   is *not* correct anywhere but on a US layout, since the
bob@2296
   799
   translation table deals with physical key codes, while the X11
bob@2296
   800
   KeySym corresponds to our concept of a layout key code, but it's
bob@2296
   801
   better than nothing.
bob@2296
   802
*/
bob@2296
   803
bob@2295
   804
static SDLKey
bob@2295
   805
X11_KeySymToSDLKey(KeySym sym, SDL_bool physical)
bob@2295
   806
{
bob@2295
   807
    /* Do a binary search for sym in the keySymToSDLKey table */
bob@2295
   808
    SDLKey key = SDLK_UNKNOWN;
bob@2295
   809
    int start = -1;
bob@2295
   810
    int end = SDL_arraysize(keySymToSDLKey);
bob@2295
   811
    int i;
bob@2295
   812
    /* Invariant: keySymToSDLKey[start].sym < sym <
bob@2295
   813
       keySymToSDLKey[end].sym (imagine ...[-1] = -inf and
bob@2295
   814
       ...[arraysize] = inf, these entries needn't be there in reality
bob@2295
   815
       because they're never accessed) */
bob@2295
   816
    while (end > start + 1) {
bob@2295
   817
        i = (start + end) / 2;
bob@2295
   818
        if (keySymToSDLKey[i].sym == sym) {
bob@2295
   819
            /* found an entry, if it's the second of two back up to the first */
bob@2295
   820
            if (keySymToSDLKey[i - 1].sym == sym)
bob@2295
   821
                i--;
bob@2295
   822
            /* if there are two, the physical one is the second */
bob@2295
   823
            if (physical && keySymToSDLKey[i + 1].sym == sym)
bob@2295
   824
                i++;
bob@2295
   825
            key = keySymToSDLKey[i].key;
bob@2295
   826
            break;
bob@2295
   827
        } else if (keySymToSDLKey[i].sym < sym)
bob@2295
   828
            start = i;
bob@2295
   829
        else
bob@2295
   830
            end = i;
bob@2295
   831
    }
bob@2295
   832
bob@2295
   833
    /* if we're being asked for a layout key code, but the table only
bob@2295
   834
       has a physical one, or vice versa, return SDLK_UNKNOWN) */
bob@2295
   835
bob@2295
   836
    if (!physical && ((key & X11_KEY_PHYSICAL_ONLY_BIT) != 0)
bob@2295
   837
        || physical && ((key & SDL_KEY_CAN_BE_PHYSICAL_BIT) == 0))
bob@2295
   838
        key = SDLK_UNKNOWN;
bob@2295
   839
    key &= ~X11_KEY_PHYSICAL_ONLY_BIT;
bob@2295
   840
    return key;
bob@2295
   841
}
bob@2295
   842
bob@2295
   843
int
slouken@1950
   844
X11_InitKeyboard(_THIS)
slouken@1950
   845
{
slouken@1950
   846
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@1950
   847
    SDL_Keyboard keyboard;
bob@2295
   848
    SDLKey **table;
bob@2295
   849
    SDLKey *foundTable;
bob@2295
   850
    int i;
bob@2295
   851
    int code;
bob@2295
   852
    SDLKey sdlkey;
bob@2295
   853
bob@2299
   854
    XAutoRepeatOn(data->display);
bob@2299
   855
bob@2295
   856
    /* A random collection of KeySym/SDLKey pairs that should be valid
bob@2295
   857
       in any keyboard layout (if this isn't the case on yours,
bob@2295
   858
       please adjust). Using XKeysymToKeycode on these KeySyms
bob@2295
   859
       creates a "fingerprint" of the X server's key-to-KeyCode
bob@2295
   860
       mapping which is then matched against all our predefined
bob@2295
   861
       KeyCodeToSDLK tables to find the right one (if any).
bob@2295
   862
     */
bob@2296
   863
bob@2298
   864
/* *INDENT-OFF* */
bob@2295
   865
    struct
bob@2295
   866
    {
bob@2295
   867
        KeySym sym;
bob@2295
   868
        SDLKey key;
bob@2298
   869
    } fingerprint[] = 
bob@2298
   870
      {
bob@2298
   871
        {XK_Tab, SDLK_TAB}, 
bob@2298
   872
        {XK_Return, SDLK_RETURN}, 
bob@2298
   873
        {XK_Escape, SDLK_ESCAPE}, 
bob@2298
   874
        {XK_space, SDLK_SPACE}
bob@2295
   875
    };
bob@2298
   876
/* *INDENT-ON* */
slouken@1950
   877
slouken@1950
   878
    SDL_zero(keyboard);
slouken@1950
   879
    data->keyboard = SDL_AddKeyboard(&keyboard, -1);
bob@2295
   880
bob@2295
   881
    /* Determine which X11 KeyCode to SDL physical key code table to use */
bob@2295
   882
bob@2295
   883
    foundTable = NULL;
bob@2295
   884
    table = keyCodeToSDLKeyTables;
bob@2295
   885
    while ((NULL == foundTable) && (NULL != (*table))) {
bob@2295
   886
        foundTable = *table;
bob@2295
   887
        for (i = 0; i < SDL_arraysize(fingerprint); i++) {
bob@2295
   888
            code = XKeysymToKeycode(data->display, fingerprint[i].sym);
bob@2295
   889
            if ((code != 0) && ((*table)[code] != fingerprint[i].key)) {
bob@2295
   890
                foundTable = NULL;
bob@2295
   891
                break;
bob@2295
   892
            }
bob@2295
   893
        }
bob@2295
   894
        table++;
bob@2295
   895
    }
bob@2295
   896
bob@2295
   897
    if (NULL != foundTable) {
bob@2295
   898
        /* Found a suitable one among the predefined tables */
bob@2295
   899
        data->keyCodeToSDLKTable = foundTable;
bob@2295
   900
    } else {
bob@2295
   901
        /* No suitable table found - build a makeshift table based on
bob@2295
   902
           the KeySyms, assuming a US keyboard layout */
bob@2295
   903
bob@2295
   904
#if 1
bob@2295
   905
        fprintf(stderr,
bob@2295
   906
                "The key codes of your X server are unknown to SDL. Keys may not be recognized properly. To help get this fixed, report this to the SDL mailing list <sdl@libsdl.org> or to Christian Walther <cwalther@gmx.ch>.\n");
bob@2295
   907
#endif
bob@2295
   908
        data->keyCodeToSDLKTable =
bob@2299
   909
            SDL_malloc(KeyCodeTableSize * sizeof(SDLKey));
bob@2295
   910
        if (data->keyCodeToSDLKTable == NULL) {
bob@2295
   911
            SDL_OutOfMemory();
bob@2295
   912
            return -1;
bob@2295
   913
        }
bob@2297
   914
        for (code = KeyCodeTableSize; code >= 0; code--) {
bob@2295
   915
            data->keyCodeToSDLKTable[code] =
bob@2295
   916
                X11_KeySymToSDLKey(XKeycodeToKeysym(data->display, code, 0),
bob@2295
   917
                                   SDL_TRUE);
bob@2295
   918
        }
bob@2295
   919
    }
bob@2295
   920
bob@2295
   921
    /* Set some non-default key names */
bob@2295
   922
bob@2297
   923
    for (code = 0; code < KeyCodeTableSize; code++) {
bob@2295
   924
        sdlkey = data->keyCodeToSDLKTable[code];
bob@2295
   925
        switch (sdlkey) {
bob@2295
   926
            /* The SDLK_*META keys are used as XK_Meta_* by some X
bob@2295
   927
               servers, as XK_Super_* by others */
bob@2295
   928
        case SDLK_LMETA:
bob@2295
   929
        case SDLK_RMETA:
bob@2295
   930
            switch (XKeycodeToKeysym(data->display, code, 0)) {
bob@2295
   931
                /* nothing to do for XK_Meta_* because that's already the default name */
bob@2295
   932
            case XK_Super_L:
bob@2295
   933
                SDL_SetKeyName(sdlkey, "left super");
bob@2295
   934
                break;
bob@2295
   935
            case XK_Super_R:
bob@2295
   936
                SDL_SetKeyName(sdlkey, "right super");
bob@2295
   937
                break;
bob@2295
   938
            }
bob@2295
   939
            break;
bob@2295
   940
        }
bob@2295
   941
    }
bob@2295
   942
    SDL_SetKeyName(SDLK_APPLICATION, "menu");
bob@2295
   943
bob@2295
   944
    return 0;
bob@2295
   945
}
bob@2295
   946
bob@2295
   947
SDLKey
bob@2295
   948
X11_GetLayoutKey(_THIS, SDLKey physicalKey)
bob@2295
   949
{
bob@2295
   950
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
bob@2295
   951
    int code = 0;
bob@2295
   952
    KeySym sym;
bob@2295
   953
    SDLKey layoutKey;
bob@2295
   954
bob@2295
   955
    switch (physicalKey) {
bob@2295
   956
    case SDLK_UNKNOWN:
bob@2295
   957
        return physicalKey;
bob@2295
   958
bob@2295
   959
        /* Shortcut handling of keypad numbers because on my PC their
bob@2295
   960
           primary KeySyms are not the numbers that I want but
bob@2295
   961
           XK_KP_Home, XK_KP_Up etc. The downside is that this gets us
bob@2295
   962
           latin numerals even on e.g. an Arabic layout. */
bob@2295
   963
    case SDLK_KP_1:
bob@2295
   964
        return '1';
bob@2295
   965
    case SDLK_KP_2:
bob@2295
   966
        return '2';
bob@2295
   967
    case SDLK_KP_3:
bob@2295
   968
        return '3';
bob@2295
   969
    case SDLK_KP_4:
bob@2295
   970
        return '4';
bob@2295
   971
    case SDLK_KP_5:
bob@2295
   972
        return '5';
bob@2295
   973
    case SDLK_KP_6:
bob@2295
   974
        return '6';
bob@2295
   975
    case SDLK_KP_7:
bob@2295
   976
        return '7';
bob@2295
   977
    case SDLK_KP_8:
bob@2295
   978
        return '8';
bob@2295
   979
    case SDLK_KP_9:
bob@2295
   980
        return '9';
bob@2295
   981
    case SDLK_KP_0:
bob@2295
   982
        return '0';
bob@2295
   983
    case SDLK_KP_PERIOD:
bob@2295
   984
        return '.';
bob@2295
   985
    default:
bob@2295
   986
        break;                  /* just to avoid a compiler warning */
bob@2295
   987
    }
bob@2295
   988
bob@2295
   989
    /* Look up physicalKey to get an X11 KeyCode - linear search isn't
bob@2295
   990
       terribly efficient, this might have to be optimized. */
bob@2297
   991
    while ((code < KeyCodeTableSize) &&
bob@2296
   992
           (physicalKey != data->keyCodeToSDLKTable[code])) {
bob@2295
   993
        code++;
bob@2295
   994
    }
bob@2295
   995
bob@2297
   996
    if (code == KeyCodeTableSize) {
bob@2295
   997
        return physicalKey;
bob@2295
   998
    }
bob@2295
   999
    /* Get the corresponding KeySym - this is where the keyboard
bob@2295
  1000
       layout comes into play */
bob@2295
  1001
    sym = XKeycodeToKeysym(data->display, code, 0);
bob@2295
  1002
bob@2295
  1003
    /* Try our own KeySym-to-layout-key-code table: it handles all
bob@2295
  1004
       keys whose layout code is an SDLK_ one, including a few where
bob@2295
  1005
       X11_KeySymToUcs4() would yield a character, but not a suitable
bob@2295
  1006
       one as a key name (e.g. space), and some that are character
bob@2295
  1007
       keys for our purposes, but aren't handled by X11_KeySymToUcs4()
bob@2295
  1008
       (dead keys, keypad operations). */
bob@2295
  1009
bob@2295
  1010
    layoutKey = X11_KeySymToSDLKey(sym, SDL_FALSE);
bob@2295
  1011
bob@2295
  1012
    /* If it wasn't handled by X11_KeySymToSDLKey(), it's most
bob@2295
  1013
       probably a plain character KeySym that X11_KeySymToUcs4()
bob@2295
  1014
       (ripped from X.org) knows. */
bob@2295
  1015
bob@2295
  1016
    if (layoutKey == SDLK_UNKNOWN) {
bob@2295
  1017
        unsigned int ucs = X11_KeySymToUcs4(sym);
bob@2295
  1018
        if (ucs != 0)
bob@2295
  1019
            layoutKey = (SDLKey) ucs;
bob@2295
  1020
    }
bob@2295
  1021
bob@2295
  1022
    /* Still no success? Give up. */
bob@2295
  1023
    if (layoutKey == SDLK_UNKNOWN) {
bob@2295
  1024
        return physicalKey;
bob@2295
  1025
    }
bob@2295
  1026
bob@2295
  1027
    return layoutKey;
slouken@1950
  1028
}
slouken@1950
  1029
slouken@1950
  1030
void
slouken@1950
  1031
X11_QuitKeyboard(_THIS)
slouken@1950
  1032
{
slouken@1950
  1033
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@1950
  1034
bob@2295
  1035
    if (data->keyCodeToSDLKTable != NULL) {
bob@2295
  1036
        /* If it's not one of the predefined tables, it was malloced
bob@2295
  1037
           and must be freed */
bob@2295
  1038
        SDLKey **table = keyCodeToSDLKeyTables;
bob@2295
  1039
        while (*table != NULL && *table != data->keyCodeToSDLKTable) {
bob@2295
  1040
            table++;
bob@2295
  1041
        }
bob@2295
  1042
        if (*table == NULL)
bob@2295
  1043
            SDL_free(data->keyCodeToSDLKTable);
bob@2295
  1044
        data->keyCodeToSDLKTable = NULL;
bob@2295
  1045
    }
bob@2295
  1046
slouken@1950
  1047
    SDL_DelKeyboard(data->keyboard);
slouken@1950
  1048
}
slouken@1950
  1049
slouken@1950
  1050
/* vi: set ts=4 sw=4 expandtab: */