src/video/x11/SDL_x11keyboard.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 17 Oct 2013 17:37:23 -0700
changeset 7824 286ab38ef766
parent 7672 424794018389
child 7827 a03ec8de0426
permissions -rw-r--r--
Fixed using the wrong variable when reporting a missing SDL scancode mapping.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
     2
  Simple DirectMedia Layer
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6318
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
     7
  arising from the use of this software.
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    11
  freely, subject to the following restrictions:
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
5481
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    23
#if SDL_VIDEO_DRIVER_X11
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    24
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#include "SDL_x11video.h"
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#include "../../events/SDL_keyboard_c.h"
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
    28
#include "../../events/scancodes_darwin.h"
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
    29
#include "../../events/scancodes_xfree86.h"
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
2295
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
    31
#include <X11/keysym.h>
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
    32
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
    33
#include "imKStoUCS.h"
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
    34
3001
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    35
/* *INDENT-OFF* */
3162
dc1eb82ffdaa Von: Thomas Zimmermann
Sam Lantinga <slouken@libsdl.org>
parents: 3001
diff changeset
    36
static const struct {
3001
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
    37
    KeySym keysym;
7580
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    38
    SDL_Scancode scancode;
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    39
} KeySymToSDLScancode[] = {
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    40
    { XK_Return, SDL_SCANCODE_RETURN },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    41
    { XK_Escape, SDL_SCANCODE_ESCAPE },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    42
    { XK_BackSpace, SDL_SCANCODE_BACKSPACE },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    43
    { XK_Tab, SDL_SCANCODE_TAB },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    44
    { XK_Caps_Lock, SDL_SCANCODE_CAPSLOCK },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    45
    { XK_F1, SDL_SCANCODE_F1 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    46
    { XK_F2, SDL_SCANCODE_F2 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    47
    { XK_F3, SDL_SCANCODE_F3 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    48
    { XK_F4, SDL_SCANCODE_F4 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    49
    { XK_F5, SDL_SCANCODE_F5 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    50
    { XK_F6, SDL_SCANCODE_F6 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    51
    { XK_F7, SDL_SCANCODE_F7 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    52
    { XK_F8, SDL_SCANCODE_F8 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    53
    { XK_F9, SDL_SCANCODE_F9 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    54
    { XK_F10, SDL_SCANCODE_F10 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    55
    { XK_F11, SDL_SCANCODE_F11 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    56
    { XK_F12, SDL_SCANCODE_F12 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    57
    { XK_Print, SDL_SCANCODE_PRINTSCREEN },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    58
    { XK_Scroll_Lock, SDL_SCANCODE_SCROLLLOCK },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    59
    { XK_Pause, SDL_SCANCODE_PAUSE },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    60
    { XK_Insert, SDL_SCANCODE_INSERT },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    61
    { XK_Home, SDL_SCANCODE_HOME },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    62
    { XK_Prior, SDL_SCANCODE_PAGEUP },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    63
    { XK_Delete, SDL_SCANCODE_DELETE },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    64
    { XK_End, SDL_SCANCODE_END },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    65
    { XK_Next, SDL_SCANCODE_PAGEDOWN },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    66
    { XK_Right, SDL_SCANCODE_RIGHT },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    67
    { XK_Left, SDL_SCANCODE_LEFT },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    68
    { XK_Down, SDL_SCANCODE_DOWN },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    69
    { XK_Up, SDL_SCANCODE_UP },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    70
    { XK_Num_Lock, SDL_SCANCODE_NUMLOCKCLEAR },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    71
    { XK_KP_Divide, SDL_SCANCODE_KP_DIVIDE },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    72
    { XK_KP_Multiply, SDL_SCANCODE_KP_MULTIPLY },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    73
    { XK_KP_Subtract, SDL_SCANCODE_KP_MINUS },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    74
    { XK_KP_Add, SDL_SCANCODE_KP_PLUS },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    75
    { XK_KP_Enter, SDL_SCANCODE_KP_ENTER },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    76
    { XK_KP_Delete, SDL_SCANCODE_KP_PERIOD },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    77
    { XK_KP_End, SDL_SCANCODE_KP_1 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    78
    { XK_KP_Down, SDL_SCANCODE_KP_2 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    79
    { XK_KP_Next, SDL_SCANCODE_KP_3 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    80
    { XK_KP_Left, SDL_SCANCODE_KP_4 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    81
    { XK_KP_Begin, SDL_SCANCODE_KP_5 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    82
    { XK_KP_Right, SDL_SCANCODE_KP_6 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    83
    { XK_KP_Home, SDL_SCANCODE_KP_7 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    84
    { XK_KP_Up, SDL_SCANCODE_KP_8 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    85
    { XK_KP_Prior, SDL_SCANCODE_KP_9 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    86
    { XK_KP_Insert, SDL_SCANCODE_KP_0 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    87
    { XK_KP_Decimal, SDL_SCANCODE_KP_PERIOD },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    88
    { XK_KP_1, SDL_SCANCODE_KP_1 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    89
    { XK_KP_2, SDL_SCANCODE_KP_2 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    90
    { XK_KP_3, SDL_SCANCODE_KP_3 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    91
    { XK_KP_4, SDL_SCANCODE_KP_4 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    92
    { XK_KP_5, SDL_SCANCODE_KP_5 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    93
    { XK_KP_6, SDL_SCANCODE_KP_6 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    94
    { XK_KP_7, SDL_SCANCODE_KP_7 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    95
    { XK_KP_8, SDL_SCANCODE_KP_8 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    96
    { XK_KP_9, SDL_SCANCODE_KP_9 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    97
    { XK_KP_0, SDL_SCANCODE_KP_0 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    98
    { XK_KP_Decimal, SDL_SCANCODE_KP_PERIOD },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
    99
    { XK_Hyper_R, SDL_SCANCODE_APPLICATION },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   100
    { XK_KP_Equal, SDL_SCANCODE_KP_EQUALS },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   101
    { XK_F13, SDL_SCANCODE_F13 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   102
    { XK_F14, SDL_SCANCODE_F14 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   103
    { XK_F15, SDL_SCANCODE_F15 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   104
    { XK_F16, SDL_SCANCODE_F16 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   105
    { XK_F17, SDL_SCANCODE_F17 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   106
    { XK_F18, SDL_SCANCODE_F18 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   107
    { XK_F19, SDL_SCANCODE_F19 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   108
    { XK_F20, SDL_SCANCODE_F20 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   109
    { XK_F21, SDL_SCANCODE_F21 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   110
    { XK_F22, SDL_SCANCODE_F22 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   111
    { XK_F23, SDL_SCANCODE_F23 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   112
    { XK_F24, SDL_SCANCODE_F24 },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   113
    { XK_Execute, SDL_SCANCODE_EXECUTE },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   114
    { XK_Help, SDL_SCANCODE_HELP },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   115
    { XK_Menu, SDL_SCANCODE_MENU },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   116
    { XK_Select, SDL_SCANCODE_SELECT },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   117
    { XK_Cancel, SDL_SCANCODE_STOP },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   118
    { XK_Redo, SDL_SCANCODE_AGAIN },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   119
    { XK_Undo, SDL_SCANCODE_UNDO },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   120
    { XK_Find, SDL_SCANCODE_FIND },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   121
    { XK_KP_Separator, SDL_SCANCODE_KP_COMMA },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   122
    { XK_Sys_Req, SDL_SCANCODE_SYSREQ },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   123
    { XK_Control_L, SDL_SCANCODE_LCTRL },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   124
    { XK_Shift_L, SDL_SCANCODE_LSHIFT },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   125
    { XK_Alt_L, SDL_SCANCODE_LALT },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   126
    { XK_Meta_L, SDL_SCANCODE_LGUI },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   127
    { XK_Super_L, SDL_SCANCODE_LGUI },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   128
    { XK_Control_R, SDL_SCANCODE_RCTRL },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   129
    { XK_Shift_R, SDL_SCANCODE_RSHIFT },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   130
    { XK_Alt_R, SDL_SCANCODE_RALT },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   131
    { XK_Meta_R, SDL_SCANCODE_RGUI },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   132
    { XK_Super_R, SDL_SCANCODE_RGUI },
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   133
    { XK_Mode_switch, SDL_SCANCODE_MODE },
2295
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   134
};
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   135
3162
dc1eb82ffdaa Von: Thomas Zimmermann
Sam Lantinga <slouken@libsdl.org>
parents: 3001
diff changeset
   136
static const struct
2295
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   137
{
5218
572a73d71b5f Sheena pointed out that "scancode" and "keysym" are single words and shouldn't be camel-cased.
Sam Lantinga <slouken@libsdl.org>
parents: 5081
diff changeset
   138
    const SDL_Scancode const *table;
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   139
    int table_size;
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   140
} scancode_set[] = {
2308
514f7c1651fc Untested Win32 keyboard scancode code.
Sam Lantinga <slouken@libsdl.org>
parents: 2306
diff changeset
   141
    { darwin_scancode_table, SDL_arraysize(darwin_scancode_table) },
514f7c1651fc Untested Win32 keyboard scancode code.
Sam Lantinga <slouken@libsdl.org>
parents: 2306
diff changeset
   142
    { xfree86_scancode_table, SDL_arraysize(xfree86_scancode_table) },
2825
620a91b6d263 Date: Tue, 02 Dec 2008 23:38:26 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 2323
diff changeset
   143
    { xfree86_scancode_table2, SDL_arraysize(xfree86_scancode_table2) },
2308
514f7c1651fc Untested Win32 keyboard scancode code.
Sam Lantinga <slouken@libsdl.org>
parents: 2306
diff changeset
   144
};
514f7c1651fc Untested Win32 keyboard scancode code.
Sam Lantinga <slouken@libsdl.org>
parents: 2306
diff changeset
   145
/* *INDENT-OFF* */
2295
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   146
7580
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   147
/* This function only works for keyboards in US QWERTY layout */
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   148
static SDL_Scancode
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   149
X11_KeyCodeToSDLScancode(Display *display, KeyCode keycode)
3001
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   150
{
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   151
    KeySym keysym;
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   152
    int i;
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   153
6318
49b2cb56db6e 1.Fixed a memory leak inside XInput2 code
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6138
diff changeset
   154
#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
49b2cb56db6e 1.Fixed a memory leak inside XInput2 code
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6138
diff changeset
   155
    keysym = XkbKeycodeToKeysym(display, keycode, 0, 0);
49b2cb56db6e 1.Fixed a memory leak inside XInput2 code
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6138
diff changeset
   156
#else
3001
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   157
    keysym = XKeycodeToKeysym(display, keycode, 0);
6318
49b2cb56db6e 1.Fixed a memory leak inside XInput2 code
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6138
diff changeset
   158
#endif
3001
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   159
    if (keysym == NoSymbol) {
7580
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   160
        return SDL_SCANCODE_UNKNOWN;
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   161
    }
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   162
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   163
    if (keysym >= XK_A && keysym <= XK_Z) {
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   164
        return SDL_SCANCODE_A + (keysym - XK_A);
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   165
    }
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   166
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   167
    if (keysym >= XK_0 && keysym <= XK_9) {
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   168
        return SDL_SCANCODE_0 + (keysym - XK_0);
3001
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   169
    }
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   170
7580
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   171
    for (i = 0; i < SDL_arraysize(KeySymToSDLScancode); ++i) {
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   172
        if (keysym == KeySymToSDLScancode[i].keysym) {
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   173
            return KeySymToSDLScancode[i].scancode;
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   174
        }
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   175
    }
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   176
    return SDL_SCANCODE_UNKNOWN;
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   177
}
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   178
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   179
static Uint32
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   180
X11_KeyCodeToUcs4(Display *display, KeyCode keycode)
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   181
{
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   182
    KeySym keysym;
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   183
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   184
#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   185
    keysym = XkbKeycodeToKeysym(display, keycode, 0, 0);
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   186
#else
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   187
    keysym = XKeycodeToKeysym(display, keycode, 0);
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   188
#endif
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   189
    if (keysym == NoSymbol) {
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   190
        return 0;
3001
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   191
    }
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   192
7580
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   193
    return X11_KeySymToUcs4(keysym);
3001
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   194
}
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   195
2295
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   196
int
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   197
X11_InitKeyboard(_THIS)
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   198
{
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   199
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
7672
424794018389 Fixed compiler warning.
Ryan C. Gordon <icculus@icculus.org>
parents: 7580
diff changeset
   200
    int i = 0;
424794018389 Fixed compiler warning.
Ryan C. Gordon <icculus@icculus.org>
parents: 7580
diff changeset
   201
    int j = 0;
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   202
    int min_keycode, max_keycode;
3001
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   203
    struct {
5218
572a73d71b5f Sheena pointed out that "scancode" and "keysym" are single words and shouldn't be camel-cased.
Sam Lantinga <slouken@libsdl.org>
parents: 5081
diff changeset
   204
        SDL_Scancode scancode;
3001
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   205
        KeySym keysym;
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   206
        int value;
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   207
    } fingerprint[] = {
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   208
        { SDL_SCANCODE_HOME, XK_Home, 0 },
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   209
        { SDL_SCANCODE_PAGEUP, XK_Prior, 0 },
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   210
        { SDL_SCANCODE_PAGEDOWN, XK_Next, 0 },
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   211
    };
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   212
    SDL_bool fingerprint_detected;
2295
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   213
2299
a7cbc25071b6 Enabled key board auto repeat in X11_InitKeyboard.c. Had to add a couple of new Xlib symbols.
Bob Pendleton <bob@pendleton.com>
parents: 2298
diff changeset
   214
    XAutoRepeatOn(data->display);
a7cbc25071b6 Enabled key board auto repeat in X11_InitKeyboard.c. Had to add a couple of new Xlib symbols.
Bob Pendleton <bob@pendleton.com>
parents: 2298
diff changeset
   215
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   216
    /* Try to determine which scancodes are being used based on fingerprint */
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   217
    fingerprint_detected = SDL_FALSE;
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   218
    XDisplayKeycodes(data->display, &min_keycode, &max_keycode);
3001
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   219
    for (i = 0; i < SDL_arraysize(fingerprint); ++i) {
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   220
        fingerprint[i].value =
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   221
            XKeysymToKeycode(data->display, fingerprint[i].keysym) -
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   222
            min_keycode;
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   223
    }
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   224
    for (i = 0; i < SDL_arraysize(scancode_set); ++i) {
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   225
        /* Make sure the scancode set isn't too big */
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   226
        if ((max_keycode - min_keycode + 1) <= scancode_set[i].table_size) {
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   227
            continue;
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   228
        }
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   229
        for (j = 0; j < SDL_arraysize(fingerprint); ++j) {
3001
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   230
            if (fingerprint[j].value < 0
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   231
                || fingerprint[j].value >= scancode_set[i].table_size) {
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   232
                break;
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   233
            }
3001
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   234
            if (scancode_set[i].table[fingerprint[j].value] !=
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   235
                fingerprint[j].scancode) {
2295
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   236
                break;
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   237
            }
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   238
        }
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   239
        if (j == SDL_arraysize(fingerprint)) {
4535
ce811c9247da Added back in a little more debugging for the X11 keyboard code
Sam Lantinga <slouken@libsdl.org>
parents: 4465
diff changeset
   240
#ifdef DEBUG_KEYBOARD
ce811c9247da Added back in a little more debugging for the X11 keyboard code
Sam Lantinga <slouken@libsdl.org>
parents: 4465
diff changeset
   241
            printf("Using scancode set %d, min_keycode = %d, max_keycode = %d, table_size = %d\n", i, min_keycode, max_keycode, scancode_set[i].table_size);
ce811c9247da Added back in a little more debugging for the X11 keyboard code
Sam Lantinga <slouken@libsdl.org>
parents: 4465
diff changeset
   242
#endif
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   243
            SDL_memcpy(&data->key_layout[min_keycode], scancode_set[i].table,
5218
572a73d71b5f Sheena pointed out that "scancode" and "keysym" are single words and shouldn't be camel-cased.
Sam Lantinga <slouken@libsdl.org>
parents: 5081
diff changeset
   244
                       sizeof(SDL_Scancode) * scancode_set[i].table_size);
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   245
            fingerprint_detected = SDL_TRUE;
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   246
            break;
2295
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   247
        }
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   248
    }
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   249
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   250
    if (!fingerprint_detected) {
5220
1fbe1c202501 Renamed SDL_Key to SDL_Keycode to clarify terminology.
Sam Lantinga <slouken@libsdl.org>
parents: 5219
diff changeset
   251
        SDL_Keycode keymap[SDL_NUM_SCANCODES];
3001
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   252
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   253
        printf
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   254
            ("Keyboard layout unknown, please send the following to the SDL mailing list (sdl@libsdl.org):\n");
2295
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   255
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   256
        /* Determine key_layout - only works on US QWERTY layout */
3001
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   257
        SDL_GetDefaultKeymap(keymap);
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   258
        for (i = min_keycode; i <= max_keycode; ++i) {
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   259
            KeySym sym;
6318
49b2cb56db6e 1.Fixed a memory leak inside XInput2 code
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6138
diff changeset
   260
#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
49b2cb56db6e 1.Fixed a memory leak inside XInput2 code
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6138
diff changeset
   261
            sym = XkbKeycodeToKeysym(data->display, i, 0, 0);
49b2cb56db6e 1.Fixed a memory leak inside XInput2 code
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6138
diff changeset
   262
#else
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   263
            sym = XKeycodeToKeysym(data->display, i, 0);
6318
49b2cb56db6e 1.Fixed a memory leak inside XInput2 code
Dimitris Zenios <dimitris.zenios@gmail.com>
parents: 6138
diff changeset
   264
#endif
3001
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   265
            if (sym != NoSymbol) {
7580
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   266
                SDL_Scancode scancode;
3667
cc7eca3a4e13 Fixed compiler warning.
Ryan C. Gordon <icculus@icculus.org>
parents: 3162
diff changeset
   267
                printf("code = %d, sym = 0x%X (%s) ", i - min_keycode,
cc7eca3a4e13 Fixed compiler warning.
Ryan C. Gordon <icculus@icculus.org>
parents: 3162
diff changeset
   268
                       (unsigned int) sym, XKeysymToString(sym));
7580
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   269
                scancode = X11_KeyCodeToSDLScancode(data->display, i);
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   270
                data->key_layout[i] = scancode;
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   271
                if (scancode == SDL_SCANCODE_UNKNOWN) {
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   272
                    printf("scancode not found\n");
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   273
                } else {
7824
286ab38ef766 Fixed using the wrong variable when reporting a missing SDL scancode mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 7672
diff changeset
   274
                    printf("scancode = %d (%s)\n", scancode, SDL_GetScancodeName(scancode));
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   275
                }
2295
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   276
            }
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   277
        }
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   278
    }
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   279
2306
1a8bab15a45d Fixed compile errors
Sam Lantinga <slouken@libsdl.org>
parents: 2305
diff changeset
   280
    X11_UpdateKeymap(_this);
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   281
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   282
    SDL_SetScancodeName(SDL_SCANCODE_APPLICATION, "Menu");
2295
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   283
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   284
    return 0;
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   285
}
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   286
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   287
void
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   288
X11_UpdateKeymap(_THIS)
2295
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   289
{
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   290
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   291
    int i;
5218
572a73d71b5f Sheena pointed out that "scancode" and "keysym" are single words and shouldn't be camel-cased.
Sam Lantinga <slouken@libsdl.org>
parents: 5081
diff changeset
   292
    SDL_Scancode scancode;
5220
1fbe1c202501 Renamed SDL_Key to SDL_Keycode to clarify terminology.
Sam Lantinga <slouken@libsdl.org>
parents: 5219
diff changeset
   293
    SDL_Keycode keymap[SDL_NUM_SCANCODES];
2295
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   294
7580
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   295
    SDL_GetDefaultKeymap(keymap);
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   296
    for (i = 0; i < SDL_arraysize(data->key_layout); i++) {
7580
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   297
        Uint32 key;
2295
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   298
3001
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   299
        /* Make sure this is a valid scancode */
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   300
        scancode = data->key_layout[i];
3001
7b031c55aebc Fixed bug #669
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   301
        if (scancode == SDL_SCANCODE_UNKNOWN) {
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   302
            continue;
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2299
diff changeset
   303
        }
2295
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   304
7580
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   305
        /* See if there is a UCS keycode for this scancode */
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   306
        key = X11_KeyCodeToUcs4(data->display, (KeyCode)i);
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   307
        if (key) {
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   308
            keymap[scancode] = key;
5a924aac594c Fixed a number of missing keys in the X11 keyboard mapping.
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   309
        }
2295
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 1950
diff changeset
   310
    }
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   311
    SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   312
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   313
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   314
void
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   315
X11_QuitKeyboard(_THIS)
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   316
{
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   317
}
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   318
5481
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   319
#endif /* SDL_VIDEO_DRIVER_X11 */
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   320
1950
a344e42bce3b Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   321
/* vi: set ts=4 sw=4 expandtab: */