21 #include "../../SDL_internal.h" 23 #if SDL_VIDEO_DRIVER_X11 27 #include "../../events/SDL_keyboard_c.h" 28 #include "../../events/scancodes_darwin.h" 29 #include "../../events/scancodes_xfree86.h" 31 #include <X11/keysym.h> 32 #include <X11/XKBlib.h> 40 } KeySymToSDLScancode[] = {
88 { XK_KP_Decimal, SDL_SCANCODE_KP_PERIOD },
89 { XK_KP_1, SDL_SCANCODE_KP_1 },
90 { XK_KP_2, SDL_SCANCODE_KP_2 },
91 { XK_KP_3, SDL_SCANCODE_KP_3 },
92 { XK_KP_4, SDL_SCANCODE_KP_4 },
93 { XK_KP_5, SDL_SCANCODE_KP_5 },
94 { XK_KP_6, SDL_SCANCODE_KP_6 },
95 { XK_KP_7, SDL_SCANCODE_KP_7 },
96 { XK_KP_8, SDL_SCANCODE_KP_8 },
97 { XK_KP_9, SDL_SCANCODE_KP_9 },
98 { XK_KP_0, SDL_SCANCODE_KP_0 },
99 { XK_KP_Decimal, SDL_SCANCODE_KP_PERIOD },
128 { XK_Super_L, SDL_SCANCODE_LGUI },
132 { XK_ISO_Level3_Shift, SDL_SCANCODE_RALT },
134 { XK_Super_R, SDL_SCANCODE_RGUI },
163 X11_KeyCodeToSDLScancode(
_THIS, KeyCode keycode)
169 if (keysym == NoSymbol) {
173 if (keysym >= XK_a && keysym <= XK_z) {
176 if (keysym >= XK_A && keysym <= XK_Z) {
180 if (keysym == XK_0) {
183 if (keysym >= XK_1 && keysym <= XK_9) {
188 if (keysym == KeySymToSDLScancode[i].keysym) {
189 return KeySymToSDLScancode[
i].scancode;
196 X11_KeyCodeToUcs4(
_THIS, KeyCode keycode,
unsigned char group)
200 if (keysym == NoSymbol) {
215 int num_groups = XkbKeyNumGroups(data->xkb, keycode);
216 unsigned char info = XkbKeyGroupInfo(data->xkb, keycode);
218 if (num_groups && group >= num_groups) {
220 int action = XkbOutOfRangeGroupAction(info);
222 if (action == XkbRedirectIntoRange) {
223 if ((group = XkbOutOfRangeGroupNumber(info)) >= num_groups) {
226 }
else if (action == XkbClampIntoRange) {
227 group = num_groups - 1;
232 keysym = X11_XkbKeycodeToKeysym(data->
display, keycode, group, 0);
234 keysym = X11_XKeycodeToKeysym(data->
display, keycode, 0);
237 keysym = X11_XKeycodeToKeysym(data->
display, keycode, 0);
249 int min_keycode, max_keycode;
266 X11_XAutoRepeatOn(data->
display);
268 #if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM 270 int xkb_major = XkbMajorVersion;
271 int xkb_minor = XkbMinorVersion;
273 data->xkb = X11_XkbGetMap(data->
display, XkbAllClientInfoMask, XkbUseCoreKbd);
281 X11_XDisplayKeycodes(data->
display, &min_keycode, &max_keycode);
283 fingerprint[
i].value =
284 X11_XKeysymToKeycode(data->
display, fingerprint[i].keysym) -
289 if ((max_keycode - min_keycode + 1) <= scancode_set[
i].table_size) {
294 if (fingerprint[
j].
value < 0
295 || fingerprint[
j].
value >= scancode_set[i].table_size) {
297 }
else if (scancode_set[i].
table[fingerprint[
j].
value] != fingerprint[
j].scancode) {
301 if (distance < best_distance) {
306 if (best_index >= 0 && best_distance <= 2) {
307 #ifdef DEBUG_KEYBOARD 308 printf(
"Using scancode set %d, min_keycode = %d, max_keycode = %d, table_size = %d\n", best_index, min_keycode, max_keycode, scancode_set[best_index].table_size);
311 sizeof(
SDL_Scancode) * scancode_set[best_index].table_size);
316 (
"Keyboard layout unknown, please send the following to the SDL mailing list (sdl@libsdl.org):\n");
320 for (i = min_keycode; i <= max_keycode; ++
i) {
323 if (sym != NoSymbol) {
325 printf(
"code = %d, sym = 0x%X (%s) ", i - min_keycode,
326 (
unsigned int) sym, X11_XKeysymToString(sym));
327 scancode = X11_KeyCodeToSDLScancode(
_this, i);
330 printf(
"scancode not found\n");
356 unsigned char group = 0;
360 #if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM 363 X11_XkbGetUpdatedMap(data->
display, XkbAllClientInfoMask, data->xkb);
365 if (X11_XkbGetState(data->
display, XkbUseCoreKbd, &state) == Success) {
382 key = X11_KeyCodeToUcs4(
_this, (KeyCode)i, group);
384 keymap[scancode] = key;
388 switch (keyScancode) {
420 X11_XkbFreeClientMap(data->xkb, 0, True);
433 #ifdef X_HAVE_UTF8_STRING 440 if (data && data->
ic) {
442 char *contents = X11_Xutf8ResetIC(data->
ic);
void SDL_GetDefaultKeymap(SDL_Keycode *keymap)
GLenum GLsizei GLenum GLenum const void * table
void X11_QuitKeyboard(_THIS)
void X11_SetTextInputRect(_THIS, SDL_Rect *rect)
static const SDL_Scancode xfree86_scancode_table[]
struct wl_display * display
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
void SDL_IME_UpdateTextRect(SDL_Rect *rect)
SDL_WindowData ** windowlist
void X11_StartTextInput(_THIS)
static const SDL_Scancode xfree86_scancode_table2[]
uint32_t Uint32
An unsigned 32-bit integer type.
#define SDL_InvalidParamError(param)
Sint32 SDL_Keycode
The SDL virtual key representation.
GLsizei GLsizei GLfloat distance
static SDL_VideoDevice * _this
void SDL_SetKeymap(int start, SDL_Keycode *keys, int length)
static const SDL_Scancode darwin_scancode_table[]
KeySym X11_KeyCodeToSym(_THIS, KeyCode, unsigned char group)
GLsizei const GLfloat * value
unsigned int X11_KeySymToUcs4(KeySym keysym)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
#define SDL_SCANCODE_TO_KEYCODE(X)
void X11_UpdateKeymap(_THIS)
void SDL_SetScancodeName(SDL_Scancode scancode, const char *name)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
void X11_StopTextInput(_THIS)
#define SDL_GetScancodeName
int X11_InitKeyboard(_THIS)
SDL_bool SDL_IME_Init(void)
#define SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
#define SDL_arraysize(array)
SDL_Scancode
The SDL keyboard scancode representation.
A rectangle, with the origin at the upper left.
static const SDL_Scancode xvnc_scancode_table[]