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 },
133 { XK_Super_R, SDL_SCANCODE_RGUI },
150 X11_KeyCodeToSDLScancode(Display *display, KeyCode keycode)
155 #if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM 156 keysym = X11_XkbKeycodeToKeysym(display, keycode, 0, 0);
158 keysym = X11_XKeycodeToKeysym(display, keycode, 0);
160 if (keysym == NoSymbol) {
164 if (keysym >= XK_A && keysym <= XK_Z) {
168 if (keysym >= XK_0 && keysym <= XK_9) {
173 if (keysym == KeySymToSDLScancode[i].keysym) {
174 return KeySymToSDLScancode[
i].scancode;
181 X11_KeyCodeToUcs4(Display *display, KeyCode keycode,
unsigned char group)
185 #if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM 186 keysym = X11_XkbKeycodeToKeysym(display, keycode, group, 0);
188 keysym = X11_XKeycodeToKeysym(display, keycode, 0);
190 if (keysym == NoSymbol) {
203 int min_keycode, max_keycode;
220 X11_XAutoRepeatOn(
data->display);
225 X11_XDisplayKeycodes(
data->display, &min_keycode, &max_keycode);
227 fingerprint[
i].value =
228 X11_XKeysymToKeycode(
data->display, fingerprint[i].keysym) -
233 if ((max_keycode - min_keycode + 1) <= scancode_set[
i].table_size) {
238 if (fingerprint[
j].
value < 0
239 || fingerprint[
j].
value >= scancode_set[i].table_size) {
241 }
else if (scancode_set[i].
table[fingerprint[
j].
value] != fingerprint[
j].scancode) {
245 if (distance < best_distance) {
250 if (best_index >= 0 && best_distance <= 2) {
251 #ifdef DEBUG_KEYBOARD 252 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);
254 SDL_memcpy(&
data->key_layout[min_keycode], scancode_set[best_index].table,
255 sizeof(
SDL_Scancode) * scancode_set[best_index].table_size);
260 (
"Keyboard layout unknown, please send the following to the SDL mailing list (sdl@libsdl.org):\n");
264 for (i = min_keycode; i <= max_keycode; ++
i) {
266 #if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM 267 sym = X11_XkbKeycodeToKeysym(
data->display, i, 0, 0);
269 sym = X11_XKeycodeToKeysym(
data->display, i, 0);
271 if (sym != NoSymbol) {
273 printf(
"code = %d, sym = 0x%X (%s) ", i - min_keycode,
274 (
unsigned int) sym, X11_XKeysymToString(sym));
275 scancode = X11_KeyCodeToSDLScancode(
data->display, i);
276 data->key_layout[
i] = scancode;
278 printf(
"scancode not found\n");
304 unsigned char group = 0;
308 #if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM 311 if (X11_XkbGetState(data->
display, XkbUseCoreKbd, &state) == Success) {
328 key = X11_KeyCodeToUcs4(data->
display, (KeyCode)i, group);
330 keymap[scancode] = key;
334 switch (keyScancode) {
390 SDL_IBus_UpdateTextRect(rect);
void SDL_GetDefaultKeymap(SDL_Keycode *keymap)
GLenum GLsizei GLenum GLenum const void * table
uint32_t Uint32
An unsigned 32-bit integer type.
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 X11_StartTextInput(_THIS)
static const SDL_Scancode xfree86_scancode_table2[]
#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[]
GLsizei const GLfloat * value
unsigned int X11_KeySymToUcs4(KeySym keysym)
#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)
#define SDL_arraysize(array)
SDL_Scancode
The SDL keyboard scancode representation.
A rectangle, with the origin at the upper left.
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)