src/video/x11/SDL_x11keyboard.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 07 Feb 2008 15:31:09 +0000
changeset 2305 fbe8ff44c519
parent 2299 a7cbc25071b6
child 2306 1a8bab15a45d
permissions -rw-r--r--
First pass of new SDL scancode concept for X11.
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@2305
    27
#include "../../events/scancodes_darwin.h"
slouken@2305
    28
#include "../../events/scancodes_xfree86.h"
slouken@1950
    29
bob@2295
    30
#include <X11/keysym.h>
bob@2295
    31
bob@2295
    32
#include "imKStoUCS.h"
bob@2295
    33
slouken@2305
    34
static KeySym XKeySymTable[SDL_NUM_SCANCODES] = {
slouken@2305
    35
    0, 0, 0, 0,
slouken@2305
    36
    XK_a,
slouken@2305
    37
    XK_b,
slouken@2305
    38
    XK_c,
slouken@2305
    39
    XK_d,
slouken@2305
    40
    XK_e,
slouken@2305
    41
    XK_f,
slouken@2305
    42
    XK_g,
slouken@2305
    43
    XK_h,
slouken@2305
    44
    XK_i,
slouken@2305
    45
    XK_j,
slouken@2305
    46
    XK_k,
slouken@2305
    47
    XK_l,
slouken@2305
    48
    XK_m,
slouken@2305
    49
    XK_n,
slouken@2305
    50
    XK_o,
slouken@2305
    51
    XK_p,
slouken@2305
    52
    XK_q,
slouken@2305
    53
    XK_r,
slouken@2305
    54
    XK_s,
slouken@2305
    55
    XK_t,
slouken@2305
    56
    XK_u,
slouken@2305
    57
    XK_v,
slouken@2305
    58
    XK_w,
slouken@2305
    59
    XK_x,
slouken@2305
    60
    XK_y,
slouken@2305
    61
    XK_z,
slouken@2305
    62
    XK_1,
slouken@2305
    63
    XK_2,
slouken@2305
    64
    XK_3,
slouken@2305
    65
    XK_4,
slouken@2305
    66
    XK_5,
slouken@2305
    67
    XK_6,
slouken@2305
    68
    XK_7,
slouken@2305
    69
    XK_8,
slouken@2305
    70
    XK_9,
slouken@2305
    71
    XK_0,
slouken@2305
    72
    XK_Return,
slouken@2305
    73
    XK_Escape,
slouken@2305
    74
    XK_BackSpace,
slouken@2305
    75
    XK_Tab,
slouken@2305
    76
    XK_space,
slouken@2305
    77
    XK_minus,
slouken@2305
    78
    XK_equal,
slouken@2305
    79
    XK_bracketleft,
slouken@2305
    80
    XK_bracketright,
slouken@2305
    81
    XK_backslash,
slouken@2305
    82
    0,                          /* SDL_SCANCODE_NONUSHASH ? */
slouken@2305
    83
    XK_semicolon,
slouken@2305
    84
    XK_apostrophe,
slouken@2305
    85
    XK_grave,
slouken@2305
    86
    XK_comma,
slouken@2305
    87
    XK_period,
slouken@2305
    88
    XK_slash,
slouken@2305
    89
    XK_Caps_Lock,
slouken@2305
    90
    XK_F1,
slouken@2305
    91
    XK_F2,
slouken@2305
    92
    XK_F3,
slouken@2305
    93
    XK_F4,
slouken@2305
    94
    XK_F5,
slouken@2305
    95
    XK_F6,
slouken@2305
    96
    XK_F7,
slouken@2305
    97
    XK_F8,
slouken@2305
    98
    XK_F9,
slouken@2305
    99
    XK_F10,
slouken@2305
   100
    XK_F11,
slouken@2305
   101
    XK_F12,
slouken@2305
   102
    XK_Print,
slouken@2305
   103
    XK_Scroll_Lock,
slouken@2305
   104
    XK_Pause,
slouken@2305
   105
    XK_Insert,
slouken@2305
   106
    XK_Home,
slouken@2305
   107
    XK_Prior,
slouken@2305
   108
    XK_Delete,
slouken@2305
   109
    XK_End,
slouken@2305
   110
    XK_Next,
slouken@2305
   111
    XK_Right,
slouken@2305
   112
    XK_Left,
slouken@2305
   113
    XK_Down,
slouken@2305
   114
    XK_Up,
slouken@2305
   115
    XK_Num_Lock,
slouken@2305
   116
    XK_KP_Divide,
slouken@2305
   117
    XK_KP_Multiply,
slouken@2305
   118
    XK_KP_Subtract,
slouken@2305
   119
    XK_KP_Add,
slouken@2305
   120
    XK_KP_Enter,
slouken@2305
   121
    XK_KP_1,
slouken@2305
   122
    XK_KP_2,
slouken@2305
   123
    XK_KP_3,
slouken@2305
   124
    XK_KP_4,
slouken@2305
   125
    XK_KP_5,
slouken@2305
   126
    XK_KP_6,
slouken@2305
   127
    XK_KP_7,
slouken@2305
   128
    XK_KP_8,
slouken@2305
   129
    XK_KP_9,
slouken@2305
   130
    XK_KP_0,
slouken@2305
   131
    XK_KP_Decimal,
slouken@2305
   132
    0,                          /* SDL_SCANCODE_NONUSBACKSLASH ? */
slouken@2305
   133
    XK_Hyper_R,
slouken@2305
   134
    0,                          /* SDL_SCANCODE_POWER ? */
slouken@2305
   135
    XK_KP_Equal,
slouken@2305
   136
    XK_F13,
slouken@2305
   137
    XK_F14,
slouken@2305
   138
    XK_F15,
slouken@2305
   139
    XK_F16,
slouken@2305
   140
    XK_F17,
slouken@2305
   141
    XK_F18,
slouken@2305
   142
    XK_F19,
slouken@2305
   143
    XK_F20,
slouken@2305
   144
    XK_F21,
slouken@2305
   145
    XK_F22,
slouken@2305
   146
    XK_F23,
slouken@2305
   147
    XK_F24,
slouken@2305
   148
    XK_Execute,
slouken@2305
   149
    XK_Help,
slouken@2305
   150
    XK_Menu,
slouken@2305
   151
    XK_Select,
slouken@2305
   152
    XK_Cancel,
slouken@2305
   153
    XK_Redo,
slouken@2305
   154
    XK_Undo,
slouken@2305
   155
    0,                          /* SDL_SCANCODE_CUT ? */
slouken@2305
   156
    0,                          /* SDL_SCANCODE_COPY ? */
slouken@2305
   157
    0,                          /* SDL_SCANCODE_PASTE ? */
slouken@2305
   158
    XK_Find,
slouken@2305
   159
    0,                          /* SDL_SCANCODE_MUTE ? */
slouken@2305
   160
    0,                          /* SDL_SCANCODE_VOLUMEUP ? */
slouken@2305
   161
    0,                          /* SDL_SCANCODE_VOLUMEDOWN ? */
slouken@2305
   162
    0, 0, 0,
slouken@2305
   163
    XK_KP_Separator,
slouken@2305
   164
    0,                          /* SDL_SCANCODE_KP_EQUALSAS400 ? */
slouken@2305
   165
    0,                          /* SDL_SCANCODE_INTERNATIONAL1 ? */
slouken@2305
   166
    0,                          /* SDL_SCANCODE_INTERNATIONAL2 ? */
slouken@2305
   167
    0,                          /* SDL_SCANCODE_INTERNATIONAL3 ? */
slouken@2305
   168
    0,                          /* SDL_SCANCODE_INTERNATIONAL4 ? */
slouken@2305
   169
    0,                          /* SDL_SCANCODE_INTERNATIONAL5 ? */
slouken@2305
   170
    0,                          /* SDL_SCANCODE_INTERNATIONAL6 ? */
slouken@2305
   171
    0,                          /* SDL_SCANCODE_INTERNATIONAL7 ? */
slouken@2305
   172
    0,                          /* SDL_SCANCODE_INTERNATIONAL8 ? */
slouken@2305
   173
    0,                          /* SDL_SCANCODE_INTERNATIONAL9 ? */
slouken@2305
   174
    0,                          /* SDL_SCANCODE_LANG1 ? */
slouken@2305
   175
    0,                          /* SDL_SCANCODE_LANG2 ? */
slouken@2305
   176
    0,                          /* SDL_SCANCODE_LANG3 ? */
slouken@2305
   177
    0,                          /* SDL_SCANCODE_LANG4 ? */
slouken@2305
   178
    0,                          /* SDL_SCANCODE_LANG5 ? */
slouken@2305
   179
    0,                          /* SDL_SCANCODE_LANG6 ? */
slouken@2305
   180
    0,                          /* SDL_SCANCODE_LANG7 ? */
slouken@2305
   181
    0,                          /* SDL_SCANCODE_LANG8 ? */
slouken@2305
   182
    0,                          /* SDL_SCANCODE_LANG9 ? */
slouken@2305
   183
    0,                          /* SDL_SCANCODE_ALTERASE ? */
slouken@2305
   184
    XK_Sys_Req,
slouken@2305
   185
    0,                          /* SDL_SCANCODE_CANCEL ? - XK_Cancel was used above... */
slouken@2305
   186
    0,                          /* SDL_SCANCODE_CLEAR ? */
slouken@2305
   187
    0,                          /* SDL_SCANCODE_PRIOR ? - XK_Prior was used above... */
slouken@2305
   188
    0,                          /* SDL_SCANCODE_RETURN2 ? */
slouken@2305
   189
    0,                          /* SDL_SCANCODE_SEPARATOR ? */
slouken@2305
   190
    0,                          /* SDL_SCANCODE_OUT ? */
slouken@2305
   191
    0,                          /* SDL_SCANCODE_OPER ? */
slouken@2305
   192
    0,                          /* SDL_SCANCODE_CLEARAGAIN ? */
slouken@2305
   193
    0,                          /* SDL_SCANCODE_CRSEL ? */
slouken@2305
   194
    0,                          /* SDL_SCANCODE_EXSEL ? */
slouken@2305
   195
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
slouken@2305
   196
    0,                          /* SDL_SCANCODE_KP_00 ? */
slouken@2305
   197
    0,                          /* SDL_SCANCODE_KP_000 ? */
slouken@2305
   198
    0,                          /* SDL_SCANCODE_THOUSANDSSEPARATOR ? */
slouken@2305
   199
    0,                          /* SDL_SCANCODE_DECIMALSEPARATOR ? */
slouken@2305
   200
    0,                          /* SDL_SCANCODE_CURRENCYUNIT ? */
slouken@2305
   201
    0,                          /* SDL_SCANCODE_CURRENCYSUBUNIT ? */
slouken@2305
   202
    0,                          /* SDL_SCANCODE_KP_LEFTPAREN ? */
slouken@2305
   203
    0,                          /* SDL_SCANCODE_KP_RIGHTPAREN ? */
slouken@2305
   204
    0,                          /* SDL_SCANCODE_KP_LEFTBRACE ? */
slouken@2305
   205
    0,                          /* SDL_SCANCODE_KP_RIGHTBRACE ? */
slouken@2305
   206
    0,                          /* SDL_SCANCODE_KP_TAB ? */
slouken@2305
   207
    0,                          /* SDL_SCANCODE_KP_BACKSPACE ? */
slouken@2305
   208
    0,                          /* SDL_SCANCODE_KP_A ? */
slouken@2305
   209
    0,                          /* SDL_SCANCODE_KP_B ? */
slouken@2305
   210
    0,                          /* SDL_SCANCODE_KP_C ? */
slouken@2305
   211
    0,                          /* SDL_SCANCODE_KP_D ? */
slouken@2305
   212
    0,                          /* SDL_SCANCODE_KP_E ? */
slouken@2305
   213
    0,                          /* SDL_SCANCODE_KP_F ? */
slouken@2305
   214
    0,                          /* SDL_SCANCODE_KP_XOR ? */
slouken@2305
   215
    0,                          /* SDL_SCANCODE_KP_POWER ? */
slouken@2305
   216
    0,                          /* SDL_SCANCODE_KP_PERCENT ? */
slouken@2305
   217
    0,                          /* SDL_SCANCODE_KP_LESS ? */
slouken@2305
   218
    0,                          /* SDL_SCANCODE_KP_GREATER ? */
slouken@2305
   219
    0,                          /* SDL_SCANCODE_KP_AMPERSAND ? */
slouken@2305
   220
    0,                          /* SDL_SCANCODE_KP_DBLAMPERSAND ? */
slouken@2305
   221
    0,                          /* SDL_SCANCODE_KP_VERTICALBAR ? */
slouken@2305
   222
    0,                          /* SDL_SCANCODE_KP_DBLVERTICALBAR ? */
slouken@2305
   223
    0,                          /* SDL_SCANCODE_KP_COLON ? */
slouken@2305
   224
    0,                          /* SDL_SCANCODE_KP_HASH ? */
slouken@2305
   225
    0,                          /* SDL_SCANCODE_KP_SPACE ? */
slouken@2305
   226
    0,                          /* SDL_SCANCODE_KP_AT ? */
slouken@2305
   227
    0,                          /* SDL_SCANCODE_KP_EXCLAM ? */
slouken@2305
   228
    0,                          /* SDL_SCANCODE_KP_MEMSTORE ? */
slouken@2305
   229
    0,                          /* SDL_SCANCODE_KP_MEMRECALL ? */
slouken@2305
   230
    0,                          /* SDL_SCANCODE_KP_MEMCLEAR ? */
slouken@2305
   231
    0,                          /* SDL_SCANCODE_KP_MEMADD ? */
slouken@2305
   232
    0,                          /* SDL_SCANCODE_KP_MEMSUBTRACT ? */
slouken@2305
   233
    0,                          /* SDL_SCANCODE_KP_MEMMULTIPLY ? */
slouken@2305
   234
    0,                          /* SDL_SCANCODE_KP_MEMDIVIDE ? */
slouken@2305
   235
    0,                          /* SDL_SCANCODE_KP_PLUSMINUS ? */
slouken@2305
   236
    0,                          /* SDL_SCANCODE_KP_CLEAR ? */
slouken@2305
   237
    0,                          /* SDL_SCANCODE_KP_CLEARENTRY ? */
slouken@2305
   238
    0,                          /* SDL_SCANCODE_KP_BINARY ? */
slouken@2305
   239
    0,                          /* SDL_SCANCODE_KP_OCTAL ? */
slouken@2305
   240
    0,                          /* SDL_SCANCODE_KP_DECIMAL ? */
slouken@2305
   241
    0,                          /* SDL_SCANCODE_KP_HEXADECIMAL ? */
slouken@2305
   242
    0, 0,
slouken@2305
   243
    XK_Control_L,
slouken@2305
   244
    XK_Shift_L,
slouken@2305
   245
    XK_Alt_L,
slouken@2305
   246
    XK_Meta_L,
slouken@2305
   247
    XK_Control_R,
slouken@2305
   248
    XK_Shift_R,
slouken@2305
   249
    XK_Alt_R,
slouken@2305
   250
    XK_Meta_R,
slouken@2305
   251
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
slouken@2305
   252
    XK_Mode_switch /*XK_ISO_Level3_Shift */ ,
slouken@2305
   253
    0,                          /* SDL_SCANCODE_AUDIONEXT ? */
slouken@2305
   254
    0,                          /* SDL_SCANCODE_AUDIOPREV ? */
slouken@2305
   255
    0,                          /* SDL_SCANCODE_AUDIOSTOP ? */
slouken@2305
   256
    0,                          /* SDL_SCANCODE_AUDIOPLAY ? */
slouken@2305
   257
    0,                          /* SDL_SCANCODE_AUDIOMUTE ? */
slouken@2305
   258
    0,                          /* SDL_SCANCODE_MEDIASELECT ? */
slouken@2305
   259
    0,                          /* SDL_SCANCODE_WWW ? */
slouken@2305
   260
    0,                          /* SDL_SCANCODE_MAIL ? */
slouken@2305
   261
    0,                          /* SDL_SCANCODE_CALCULATOR ? */
slouken@2305
   262
    0,                          /* SDL_SCANCODE_COMPUTER ? */
slouken@2305
   263
    0,                          /* SDL_SCANCODE_AC_SEARCH ? */
slouken@2305
   264
    0,                          /* SDL_SCANCODE_AC_HOME ? */
slouken@2305
   265
    0,                          /* SDL_SCANCODE_AC_BACK ? */
slouken@2305
   266
    0,                          /* SDL_SCANCODE_AC_FORWARD ? */
slouken@2305
   267
    0,                          /* SDL_SCANCODE_AC_STOP ? */
slouken@2305
   268
    0,                          /* SDL_SCANCODE_AC_REFRESH ? */
slouken@2305
   269
    0,                          /* SDL_SCANCODE_AC_BOOKMARKS ? */
slouken@2305
   270
    0,                          /* SDL_SCANCODE_BRIGHTNESSDOWN ? */
slouken@2305
   271
    0,                          /* SDL_SCANCODE_BRIGHTNESSUP ? */
slouken@2305
   272
    0,                          /* SDL_SCANCODE_DISPLAYSWITCH ? */
slouken@2305
   273
    0,                          /* SDL_SCANCODE_KBDILLUMTOGGLE ? */
slouken@2305
   274
    0,                          /* SDL_SCANCODE_KBDILLUMDOWN ? */
slouken@2305
   275
    0,                          /* SDL_SCANCODE_KBDILLUMUP ? */
slouken@2305
   276
    0,                          /* SDL_SCANCODE_EJECT ? */
slouken@2305
   277
    0,                          /* SDL_SCANCODE_SLEEP ? */
bob@2295
   278
};
bob@2295
   279
bob@2295
   280
static struct
bob@2295
   281
{
slouken@2305
   282
    SDL_scancode *table;
slouken@2305
   283
    int table_size;
slouken@2305
   284
} scancode_set[] = {
slouken@2305
   285
    {
slouken@2305
   286
    darwin_scancode_table, SDL_arraysize(darwin_scancode_table)}, {
slouken@2305
   287
xfree86_scancode_table, SDL_arraysize(xfree86_scancode_table)},};
bob@2295
   288
bob@2295
   289
int
slouken@1950
   290
X11_InitKeyboard(_THIS)
slouken@1950
   291
{
slouken@1950
   292
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@1950
   293
    SDL_Keyboard keyboard;
slouken@2305
   294
    int i, j;
slouken@2305
   295
    int min_keycode, max_keycode;
slouken@2305
   296
    SDL_scancode fingerprint_scancodes[] = {
slouken@2305
   297
        SDL_SCANCODE_HOME,
slouken@2305
   298
        SDL_SCANCODE_PAGEUP,
slouken@2305
   299
        SDL_SCANCODE_PAGEDOWN
slouken@2305
   300
    };
slouken@2305
   301
    int fingerprint[3];
slouken@2305
   302
    SDL_bool fingerprint_detected;
bob@2295
   303
bob@2299
   304
    XAutoRepeatOn(data->display);
bob@2299
   305
slouken@2305
   306
    /* Try to determine which scancodes are being used based on fingerprint */
slouken@2305
   307
    fingerprint_detected = SDL_FALSE;
slouken@2305
   308
    XDisplayKeycodes(data->display, &min_keycode, &max_keycode);
slouken@2305
   309
    for (i = 0; i < SDL_arraysize(fingerprint_scancodes); ++i) {
slouken@2305
   310
        fingerprint[i] =
slouken@2305
   311
            XKeysymToKeycode(data->display,
slouken@2305
   312
                             XKeySymTable[fingerprint_scancodes[i]]) -
slouken@2305
   313
            min_keycode;
slouken@2305
   314
    }
slouken@2305
   315
    for (i = 0; i < SDL_arraysize(scancode_set); ++i) {
slouken@2305
   316
        /* Make sure the scancode set isn't too big */
slouken@2305
   317
        if ((max_keycode - min_keycode + 1) <= scancode_set[i].table_size) {
slouken@2305
   318
            continue;
slouken@2305
   319
        }
slouken@2305
   320
        for (j = 0; j < SDL_arraysize(fingerprint); ++j) {
slouken@2305
   321
            if (fingerprint[j] < 0
slouken@2305
   322
                || fingerprint[j] >= scancode_set[i].table_size) {
slouken@2305
   323
                break;
slouken@2305
   324
            }
slouken@2305
   325
            if (scancode_set[i].table[fingerprint[j]] !=
slouken@2305
   326
                fingerprint_scancodes[j]) {
slouken@2305
   327
                break;
slouken@2305
   328
            }
slouken@2305
   329
        }
slouken@2305
   330
        if (j == SDL_arraysize(fingerprint)) {
slouken@2305
   331
            printf("Using scancode set %d\n", i);
slouken@2305
   332
            SDL_memcpy(&data->key_layout[min_keycode], scancode_set[i].table,
slouken@2305
   333
                       sizeof(SDL_scancode) * scancode_set[i].table_size);
slouken@2305
   334
            fingerprint_detected = SDL_TRUE;
slouken@2305
   335
            break;
slouken@2305
   336
        }
slouken@2305
   337
    }
bob@2296
   338
slouken@2305
   339
    if (!fingerprint_detected) {
slouken@2305
   340
        printf
slouken@2305
   341
            ("Keyboard layout unknown, please send the following to the SDL mailing list (sdl@libsdl.org):\n");
slouken@2305
   342
slouken@2305
   343
        /* Determine key_layout - only works on US QWERTY layout */
slouken@2305
   344
        for (i = min_keycode; i <= max_keycode; ++i) {
slouken@2305
   345
            KeySym sym;
slouken@2305
   346
            sym = XKeycodeToKeysym(data->display, i, 0);
slouken@2305
   347
            if (sym) {
slouken@2305
   348
                printf("code = %d, sym = 0x%X (%s) ", i - min_keycode, sym,
slouken@2305
   349
                       XKeysymToString(sym));
slouken@2305
   350
                for (j = 0; j < SDL_arraysize(XKeySymTable); ++j) {
slouken@2305
   351
                    if (XKeySymTable[j] == sym) {
slouken@2305
   352
                        data->key_layout[i] = (SDL_scancode) j;
slouken@2305
   353
                        break;
slouken@2305
   354
                    }
slouken@2305
   355
                }
slouken@2305
   356
                if (j == SDL_arraysize(XKeySymTable)) {
slouken@2305
   357
                    printf("scancode not found\n");
slouken@2305
   358
                } else {
slouken@2305
   359
                    printf("scancode = %d (%s)\n", j, SDL_GetScancodeName(j));
slouken@2305
   360
                }
slouken@2305
   361
            }
slouken@2305
   362
        }
slouken@2305
   363
    }
slouken@1950
   364
slouken@1950
   365
    SDL_zero(keyboard);
slouken@1950
   366
    data->keyboard = SDL_AddKeyboard(&keyboard, -1);
slouken@2305
   367
    X11_UpdateKeymap(this);
bob@2295
   368
slouken@2305
   369
    SDL_SetScancodeName(SDL_SCANCODE_APPLICATION, "Menu");
bob@2295
   370
bob@2295
   371
    return 0;
bob@2295
   372
}
bob@2295
   373
slouken@2305
   374
void
slouken@2305
   375
X11_UpdateKeymap(_THIS)
bob@2295
   376
{
bob@2295
   377
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@2305
   378
    int i;
slouken@2305
   379
    SDL_scancode scancode;
slouken@2305
   380
    SDLKey keymap[SDL_NUM_SCANCODES];
bob@2295
   381
slouken@2305
   382
    SDL_GetDefaultKeymap(keymap);
bob@2295
   383
slouken@2305
   384
    for (i = 0; i < SDL_arraysize(data->key_layout); i++) {
slouken@2305
   385
slouken@2305
   386
        /* Make sure this scancode is a valid character scancode */
slouken@2305
   387
        scancode = data->key_layout[i];
slouken@2305
   388
        if (scancode == SDL_SCANCODE_UNKNOWN ||
slouken@2305
   389
            (keymap[scancode] & SDLK_SCANCODE_MASK)) {
slouken@2305
   390
            continue;
slouken@2305
   391
        }
slouken@2305
   392
slouken@2305
   393
        keymap[scancode] =
slouken@2305
   394
            (SDLKey) X11_KeySymToUcs4(XKeycodeToKeysym(data->display, i, 0));
bob@2295
   395
    }
slouken@2305
   396
    SDL_SetKeymap(data->keyboard, 0, keymap, SDL_NUM_SCANCODES);
slouken@1950
   397
}
slouken@1950
   398
slouken@1950
   399
void
slouken@1950
   400
X11_QuitKeyboard(_THIS)
slouken@1950
   401
{
slouken@1950
   402
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@1950
   403
slouken@1950
   404
    SDL_DelKeyboard(data->keyboard);
slouken@1950
   405
}
slouken@1950
   406
slouken@1950
   407
/* vi: set ts=4 sw=4 expandtab: */