Use common code for handling keysym translations.

This commit is contained in:
Themaister 2012-12-08 13:25:42 +01:00
parent 3a3953aef3
commit 5185524b46
6 changed files with 339 additions and 324 deletions

View File

@ -20,6 +20,7 @@
#include "../gfx_context.h"
#include "../gl_common.h"
#include "../gfx_common.h"
#include "../../input/input_common.h"
#include "x11_common.h"
#include <signal.h>
@ -222,25 +223,14 @@ static void gfx_ctx_check_window(bool *quit,
{
static XComposeStatus state;
char keybuf[32];
const unsigned x_keycode = XLookupKeysym(&event.xkey, 0);
bool down = event.type == KeyPress;
bool down = event.type == KeyPress;
uint32_t character = 0;
unsigned key = RETROK_UNKNOWN;
for (int i = 0; i < RETROK_LAST; i++)
{
if (keysym_lut[i] == x_keycode)
{
key = i;
break;
}
}
unsigned key = input_translate_keysym_to_rk(XLookupKeysym(&event.xkey, 0));
// FIXME: UTF-8.
if (down && XLookupString(&event.xkey, keybuf, sizeof(keybuf), 0, &state))
{
character = keybuf[0];
}
g_extern.system.key_event(down, key, character, 0);
}

View File

@ -37,7 +37,6 @@ struct dinput_input
LPDIRECTINPUTDEVICE8 mouse;
const rarch_joypad_driver_t *joypad;
uint8_t state[256];
int rk_to_di_lut[RETROK_LAST];
int mouse_rel_x;
int mouse_rel_y;
@ -52,105 +51,6 @@ struct dinput_joypad
DIJOYSTATE2 joy_state;
};
struct key_map
{
int di;
int rk;
};
static const struct key_map rk_to_di[] = {
{ DIK_LEFT, RETROK_LEFT },
{ DIK_RIGHT, RETROK_RIGHT },
{ DIK_UP, RETROK_UP },
{ DIK_DOWN, RETROK_DOWN },
{ DIK_RETURN, RETROK_RETURN },
{ DIK_TAB, RETROK_TAB },
{ DIK_INSERT, RETROK_INSERT },
{ DIK_DELETE, RETROK_DELETE },
{ DIK_RSHIFT, RETROK_RSHIFT },
{ DIK_LSHIFT, RETROK_LSHIFT },
{ DIK_LCONTROL, RETROK_LCTRL },
{ DIK_END, RETROK_END },
{ DIK_HOME, RETROK_HOME },
{ DIK_NEXT, RETROK_PAGEDOWN },
{ DIK_PRIOR, RETROK_PAGEUP },
{ DIK_LALT, RETROK_LALT },
{ DIK_SPACE, RETROK_SPACE },
{ DIK_ESCAPE, RETROK_ESCAPE },
{ DIK_BACKSPACE, RETROK_BACKSPACE },
{ DIK_NUMPADENTER, RETROK_KP_ENTER },
{ DIK_NUMPADPLUS, RETROK_KP_PLUS },
{ DIK_NUMPADMINUS, RETROK_KP_MINUS },
{ DIK_NUMPADSTAR, RETROK_KP_MULTIPLY },
{ DIK_NUMPADSLASH, RETROK_KP_DIVIDE },
{ DIK_GRAVE, RETROK_BACKQUOTE },
{ DIK_PAUSE, RETROK_PAUSE },
{ DIK_NUMPAD0, RETROK_KP0 },
{ DIK_NUMPAD1, RETROK_KP1 },
{ DIK_NUMPAD2, RETROK_KP2 },
{ DIK_NUMPAD3, RETROK_KP3 },
{ DIK_NUMPAD4, RETROK_KP4 },
{ DIK_NUMPAD5, RETROK_KP5 },
{ DIK_NUMPAD6, RETROK_KP6 },
{ DIK_NUMPAD7, RETROK_KP7 },
{ DIK_NUMPAD8, RETROK_KP8 },
{ DIK_NUMPAD9, RETROK_KP9 },
{ DIK_0, RETROK_0 },
{ DIK_1, RETROK_1 },
{ DIK_2, RETROK_2 },
{ DIK_3, RETROK_3 },
{ DIK_4, RETROK_4 },
{ DIK_5, RETROK_5 },
{ DIK_6, RETROK_6 },
{ DIK_7, RETROK_7 },
{ DIK_8, RETROK_8 },
{ DIK_9, RETROK_9 },
{ DIK_F1, RETROK_F1 },
{ DIK_F2, RETROK_F2 },
{ DIK_F3, RETROK_F3 },
{ DIK_F4, RETROK_F4 },
{ DIK_F5, RETROK_F5 },
{ DIK_F6, RETROK_F6 },
{ DIK_F7, RETROK_F7 },
{ DIK_F8, RETROK_F8 },
{ DIK_F9, RETROK_F9 },
{ DIK_F10, RETROK_F10 },
{ DIK_F11, RETROK_F11 },
{ DIK_F12, RETROK_F12 },
{ DIK_A, RETROK_a },
{ DIK_B, RETROK_b },
{ DIK_C, RETROK_c },
{ DIK_D, RETROK_d },
{ DIK_E, RETROK_e },
{ DIK_F, RETROK_f },
{ DIK_G, RETROK_g },
{ DIK_H, RETROK_h },
{ DIK_I, RETROK_i },
{ DIK_J, RETROK_j },
{ DIK_K, RETROK_k },
{ DIK_L, RETROK_l },
{ DIK_M, RETROK_m },
{ DIK_N, RETROK_n },
{ DIK_O, RETROK_o },
{ DIK_P, RETROK_p },
{ DIK_Q, RETROK_q },
{ DIK_R, RETROK_r },
{ DIK_S, RETROK_s },
{ DIK_T, RETROK_t },
{ DIK_U, RETROK_u },
{ DIK_V, RETROK_v },
{ DIK_W, RETROK_w },
{ DIK_X, RETROK_x },
{ DIK_Y, RETROK_y },
{ DIK_Z, RETROK_z },
};
static void init_lut(int *lut)
{
for (unsigned i = 0; i < sizeof(rk_to_di) / sizeof(rk_to_di[0]); i++)
lut[rk_to_di[i].rk] = rk_to_di[i].di;
}
static unsigned g_joypad_cnt;
static struct dinput_joypad g_pads[MAX_PLAYERS];
@ -225,7 +125,7 @@ static void *dinput_init(void)
DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
IDirectInputDevice8_Acquire(di->mouse);
init_lut(di->rk_to_di_lut);
input_init_keyboard_lut(rarch_key_map_dinput);
di->joypad = input_joypad_init_first();
return di;
@ -278,7 +178,8 @@ static bool dinput_keyboard_pressed(struct dinput_input *di, unsigned key)
if (key >= RETROK_LAST)
return false;
return di->state[di->rk_to_di_lut[key]] & 0x80;
unsigned sym = input_translate_rk_to_keysym(key);
return di->state[sym] & 0x80;
}
static bool dinput_is_pressed(struct dinput_input *di, const struct retro_keybind *binds,

View File

@ -22,6 +22,20 @@
#include "../config.h"
#endif
#ifdef HAVE_DINPUT
#undef DIRECTINPUT_VERSION
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
#endif
#ifdef HAVE_SDL
#include "SDL.h"
#endif
#ifdef HAVE_X11
#include <X11/keysym.h>
#endif
static const rarch_joypad_driver_t *joypad_drivers[] = {
#ifdef HAVE_DINPUT
&dinput_joypad,
@ -172,3 +186,298 @@ bool input_translate_coord_viewport(int mouse_x, int mouse_y,
return true;
}
#ifdef HAVE_X11
const struct rarch_key_map rarch_key_map_x11[] = {
{ XK_Left, RETROK_LEFT },
{ XK_Right, RETROK_RIGHT },
{ XK_Up, RETROK_UP },
{ XK_Down, RETROK_DOWN },
{ XK_Return, RETROK_RETURN },
{ XK_Tab, RETROK_TAB },
{ XK_Insert, RETROK_INSERT },
{ XK_Home, RETROK_HOME },
{ XK_End, RETROK_END },
{ XK_Page_Up, RETROK_PAGEUP },
{ XK_Page_Down, RETROK_PAGEDOWN },
{ XK_Delete, RETROK_DELETE },
{ XK_Shift_R, RETROK_RSHIFT },
{ XK_Shift_L, RETROK_LSHIFT },
{ XK_Control_L, RETROK_LCTRL },
{ XK_Alt_L, RETROK_LALT },
{ XK_space, RETROK_SPACE },
{ XK_Escape, RETROK_ESCAPE },
{ XK_BackSpace, RETROK_BACKSPACE },
{ XK_KP_Enter, RETROK_KP_ENTER },
{ XK_KP_Add, RETROK_KP_PLUS },
{ XK_KP_Subtract, RETROK_KP_MINUS },
{ XK_KP_Multiply, RETROK_KP_MULTIPLY },
{ XK_KP_Divide, RETROK_KP_DIVIDE },
{ XK_grave, RETROK_BACKQUOTE },
{ XK_Pause, RETROK_PAUSE },
{ XK_KP_0, RETROK_KP0 },
{ XK_KP_1, RETROK_KP1 },
{ XK_KP_2, RETROK_KP2 },
{ XK_KP_3, RETROK_KP3 },
{ XK_KP_4, RETROK_KP4 },
{ XK_KP_5, RETROK_KP5 },
{ XK_KP_6, RETROK_KP6 },
{ XK_KP_7, RETROK_KP7 },
{ XK_KP_8, RETROK_KP8 },
{ XK_KP_9, RETROK_KP9 },
{ XK_0, RETROK_0 },
{ XK_1, RETROK_1 },
{ XK_2, RETROK_2 },
{ XK_3, RETROK_3 },
{ XK_4, RETROK_4 },
{ XK_5, RETROK_5 },
{ XK_6, RETROK_6 },
{ XK_7, RETROK_7 },
{ XK_8, RETROK_8 },
{ XK_9, RETROK_9 },
{ XK_F1, RETROK_F1 },
{ XK_F2, RETROK_F2 },
{ XK_F3, RETROK_F3 },
{ XK_F4, RETROK_F4 },
{ XK_F5, RETROK_F5 },
{ XK_F6, RETROK_F6 },
{ XK_F7, RETROK_F7 },
{ XK_F8, RETROK_F8 },
{ XK_F9, RETROK_F9 },
{ XK_F10, RETROK_F10 },
{ XK_F11, RETROK_F11 },
{ XK_F12, RETROK_F12 },
{ XK_a, RETROK_a },
{ XK_b, RETROK_b },
{ XK_c, RETROK_c },
{ XK_d, RETROK_d },
{ XK_e, RETROK_e },
{ XK_f, RETROK_f },
{ XK_g, RETROK_g },
{ XK_h, RETROK_h },
{ XK_i, RETROK_i },
{ XK_j, RETROK_j },
{ XK_k, RETROK_k },
{ XK_l, RETROK_l },
{ XK_m, RETROK_m },
{ XK_n, RETROK_n },
{ XK_o, RETROK_o },
{ XK_p, RETROK_p },
{ XK_q, RETROK_q },
{ XK_r, RETROK_r },
{ XK_s, RETROK_s },
{ XK_t, RETROK_t },
{ XK_u, RETROK_u },
{ XK_v, RETROK_v },
{ XK_w, RETROK_w },
{ XK_x, RETROK_x },
{ XK_y, RETROK_y },
{ XK_z, RETROK_z },
{ 0, RETROK_UNKNOWN },
};
#endif
#ifdef HAVE_SDL
const struct rarch_key_map rarch_key_map_sdl[] = {
{ SDLK_LEFT, RETROK_LEFT },
{ SDLK_RIGHT, RETROK_RIGHT },
{ SDLK_UP, RETROK_UP },
{ SDLK_DOWN, RETROK_DOWN },
{ SDLK_RETURN, RETROK_RETURN },
{ SDLK_TAB, RETROK_TAB },
{ SDLK_INSERT, RETROK_INSERT },
{ SDLK_DELETE, RETROK_DELETE },
{ SDLK_RSHIFT, RETROK_RSHIFT },
{ SDLK_LSHIFT, RETROK_LSHIFT },
{ SDLK_LCTRL, RETROK_LCTRL },
{ SDLK_END, RETROK_END },
{ SDLK_HOME, RETROK_HOME },
{ SDLK_PAGEDOWN, RETROK_PAGEDOWN },
{ SDLK_PAGEUP, RETROK_PAGEUP },
{ SDLK_LALT, RETROK_LALT },
{ SDLK_SPACE, RETROK_SPACE },
{ SDLK_ESCAPE, RETROK_ESCAPE },
{ SDLK_BACKSPACE, RETROK_BACKSPACE },
{ SDLK_KP_ENTER, RETROK_KP_ENTER },
{ SDLK_KP_PLUS, RETROK_KP_PLUS },
{ SDLK_KP_MINUS, RETROK_KP_MINUS },
{ SDLK_KP_MULTIPLY, RETROK_KP_MULTIPLY },
{ SDLK_KP_DIVIDE, RETROK_KP_DIVIDE },
{ SDLK_BACKQUOTE, RETROK_BACKQUOTE },
{ SDLK_PAUSE, RETROK_PAUSE },
{ SDLK_KP0, RETROK_KP0 },
{ SDLK_KP1, RETROK_KP1 },
{ SDLK_KP2, RETROK_KP2 },
{ SDLK_KP3, RETROK_KP3 },
{ SDLK_KP4, RETROK_KP4 },
{ SDLK_KP5, RETROK_KP5 },
{ SDLK_KP6, RETROK_KP6 },
{ SDLK_KP7, RETROK_KP7 },
{ SDLK_KP8, RETROK_KP8 },
{ SDLK_KP9, RETROK_KP9 },
{ SDLK_0, RETROK_0 },
{ SDLK_1, RETROK_1 },
{ SDLK_2, RETROK_2 },
{ SDLK_3, RETROK_3 },
{ SDLK_4, RETROK_4 },
{ SDLK_5, RETROK_5 },
{ SDLK_6, RETROK_6 },
{ SDLK_7, RETROK_7 },
{ SDLK_8, RETROK_8 },
{ SDLK_9, RETROK_9 },
{ SDLK_F1, RETROK_F1 },
{ SDLK_F2, RETROK_F2 },
{ SDLK_F3, RETROK_F3 },
{ SDLK_F4, RETROK_F4 },
{ SDLK_F5, RETROK_F5 },
{ SDLK_F6, RETROK_F6 },
{ SDLK_F7, RETROK_F7 },
{ SDLK_F8, RETROK_F8 },
{ SDLK_F9, RETROK_F9 },
{ SDLK_F10, RETROK_F10 },
{ SDLK_F11, RETROK_F11 },
{ SDLK_F12, RETROK_F12 },
{ SDLK_a, RETROK_a },
{ SDLK_b, RETROK_b },
{ SDLK_c, RETROK_c },
{ SDLK_d, RETROK_d },
{ SDLK_e, RETROK_e },
{ SDLK_f, RETROK_f },
{ SDLK_g, RETROK_g },
{ SDLK_h, RETROK_h },
{ SDLK_i, RETROK_i },
{ SDLK_j, RETROK_j },
{ SDLK_k, RETROK_k },
{ SDLK_l, RETROK_l },
{ SDLK_m, RETROK_m },
{ SDLK_n, RETROK_n },
{ SDLK_o, RETROK_o },
{ SDLK_p, RETROK_p },
{ SDLK_q, RETROK_q },
{ SDLK_r, RETROK_r },
{ SDLK_s, RETROK_s },
{ SDLK_t, RETROK_t },
{ SDLK_u, RETROK_u },
{ SDLK_v, RETROK_v },
{ SDLK_w, RETROK_w },
{ SDLK_x, RETROK_x },
{ SDLK_y, RETROK_y },
{ SDLK_z, RETROK_z },
{ 0, RETROK_UNKNOWN },
};
#endif
#ifdef HAVE_DINPUT
const struct rarch_key_map rarch_key_map_dinput[] = {
{ DIK_LEFT, RETROK_LEFT },
{ DIK_RIGHT, RETROK_RIGHT },
{ DIK_UP, RETROK_UP },
{ DIK_DOWN, RETROK_DOWN },
{ DIK_RETURN, RETROK_RETURN },
{ DIK_TAB, RETROK_TAB },
{ DIK_INSERT, RETROK_INSERT },
{ DIK_DELETE, RETROK_DELETE },
{ DIK_RSHIFT, RETROK_RSHIFT },
{ DIK_LSHIFT, RETROK_LSHIFT },
{ DIK_LCONTROL, RETROK_LCTRL },
{ DIK_END, RETROK_END },
{ DIK_HOME, RETROK_HOME },
{ DIK_NEXT, RETROK_PAGEDOWN },
{ DIK_PRIOR, RETROK_PAGEUP },
{ DIK_LALT, RETROK_LALT },
{ DIK_SPACE, RETROK_SPACE },
{ DIK_ESCAPE, RETROK_ESCAPE },
{ DIK_BACKSPACE, RETROK_BACKSPACE },
{ DIK_NUMPADENTER, RETROK_KP_ENTER },
{ DIK_NUMPADPLUS, RETROK_KP_PLUS },
{ DIK_NUMPADMINUS, RETROK_KP_MINUS },
{ DIK_NUMPADSTAR, RETROK_KP_MULTIPLY },
{ DIK_NUMPADSLASH, RETROK_KP_DIVIDE },
{ DIK_GRAVE, RETROK_BACKQUOTE },
{ DIK_PAUSE, RETROK_PAUSE },
{ DIK_NUMPAD0, RETROK_KP0 },
{ DIK_NUMPAD1, RETROK_KP1 },
{ DIK_NUMPAD2, RETROK_KP2 },
{ DIK_NUMPAD3, RETROK_KP3 },
{ DIK_NUMPAD4, RETROK_KP4 },
{ DIK_NUMPAD5, RETROK_KP5 },
{ DIK_NUMPAD6, RETROK_KP6 },
{ DIK_NUMPAD7, RETROK_KP7 },
{ DIK_NUMPAD8, RETROK_KP8 },
{ DIK_NUMPAD9, RETROK_KP9 },
{ DIK_0, RETROK_0 },
{ DIK_1, RETROK_1 },
{ DIK_2, RETROK_2 },
{ DIK_3, RETROK_3 },
{ DIK_4, RETROK_4 },
{ DIK_5, RETROK_5 },
{ DIK_6, RETROK_6 },
{ DIK_7, RETROK_7 },
{ DIK_8, RETROK_8 },
{ DIK_9, RETROK_9 },
{ DIK_F1, RETROK_F1 },
{ DIK_F2, RETROK_F2 },
{ DIK_F3, RETROK_F3 },
{ DIK_F4, RETROK_F4 },
{ DIK_F5, RETROK_F5 },
{ DIK_F6, RETROK_F6 },
{ DIK_F7, RETROK_F7 },
{ DIK_F8, RETROK_F8 },
{ DIK_F9, RETROK_F9 },
{ DIK_F10, RETROK_F10 },
{ DIK_F11, RETROK_F11 },
{ DIK_F12, RETROK_F12 },
{ DIK_A, RETROK_a },
{ DIK_B, RETROK_b },
{ DIK_C, RETROK_c },
{ DIK_D, RETROK_d },
{ DIK_E, RETROK_e },
{ DIK_F, RETROK_f },
{ DIK_G, RETROK_g },
{ DIK_H, RETROK_h },
{ DIK_I, RETROK_i },
{ DIK_J, RETROK_j },
{ DIK_K, RETROK_k },
{ DIK_L, RETROK_l },
{ DIK_M, RETROK_m },
{ DIK_N, RETROK_n },
{ DIK_O, RETROK_o },
{ DIK_P, RETROK_p },
{ DIK_Q, RETROK_q },
{ DIK_R, RETROK_r },
{ DIK_S, RETROK_s },
{ DIK_T, RETROK_t },
{ DIK_U, RETROK_u },
{ DIK_V, RETROK_v },
{ DIK_W, RETROK_w },
{ DIK_X, RETROK_x },
{ DIK_Y, RETROK_y },
{ DIK_Z, RETROK_z },
{ 0, RETROK_UNKNOWN },
};
#endif
static enum retro_key rarch_keysym_lut[RETROK_LAST];
void input_init_keyboard_lut(const struct rarch_key_map *map)
{
memset(rarch_keysym_lut, 0, sizeof(rarch_keysym_lut));
for (; map->rk != RETROK_UNKNOWN; map++)
rarch_keysym_lut[map->rk] = (enum retro_key)map->sym;
}
enum retro_key input_translate_keysym_to_rk(unsigned sym)
{
for (unsigned i = 0; i < ARRAY_SIZE(rarch_keysym_lut); i++)
{
if (rarch_keysym_lut[i] == sym)
return (enum retro_key)i;
}
return RETROK_UNKNOWN;
}
unsigned input_translate_rk_to_keysym(enum retro_key key)
{
return rarch_keysym_lut[key];
}

View File

@ -82,5 +82,20 @@ extern const rarch_joypad_driver_t dinput_joypad;
extern const rarch_joypad_driver_t linuxraw_joypad;
extern const rarch_joypad_driver_t sdl_joypad;
struct rarch_key_map
{
unsigned sym;
enum retro_key rk;
};
extern const struct rarch_key_map rarch_key_map_x11[];
extern const struct rarch_key_map rarch_key_map_sdl[];
extern const struct rarch_key_map rarch_key_map_dinput[];
void input_init_keyboard_lut(const struct rarch_key_map *map);
enum retro_key input_translate_keysym_to_rk(unsigned sym);
unsigned input_translate_rk_to_keysym(enum retro_key key);
#endif

View File

@ -33,110 +33,9 @@ typedef struct sdl_input
int mouse_l, mouse_r, mouse_m;
} sdl_input_t;
struct key_bind
{
unsigned sdl;
enum retro_key sk;
};
static unsigned keysym_lut[RETROK_LAST];
static const struct key_bind lut_binds[] = {
{ SDLK_LEFT, RETROK_LEFT },
{ SDLK_RIGHT, RETROK_RIGHT },
{ SDLK_UP, RETROK_UP },
{ SDLK_DOWN, RETROK_DOWN },
{ SDLK_RETURN, RETROK_RETURN },
{ SDLK_TAB, RETROK_TAB },
{ SDLK_INSERT, RETROK_INSERT },
{ SDLK_DELETE, RETROK_DELETE },
{ SDLK_RSHIFT, RETROK_RSHIFT },
{ SDLK_LSHIFT, RETROK_LSHIFT },
{ SDLK_LCTRL, RETROK_LCTRL },
{ SDLK_END, RETROK_END },
{ SDLK_HOME, RETROK_HOME },
{ SDLK_PAGEDOWN, RETROK_PAGEDOWN },
{ SDLK_PAGEUP, RETROK_PAGEUP },
{ SDLK_LALT, RETROK_LALT },
{ SDLK_SPACE, RETROK_SPACE },
{ SDLK_ESCAPE, RETROK_ESCAPE },
{ SDLK_BACKSPACE, RETROK_BACKSPACE },
{ SDLK_KP_ENTER, RETROK_KP_ENTER },
{ SDLK_KP_PLUS, RETROK_KP_PLUS },
{ SDLK_KP_MINUS, RETROK_KP_MINUS },
{ SDLK_KP_MULTIPLY, RETROK_KP_MULTIPLY },
{ SDLK_KP_DIVIDE, RETROK_KP_DIVIDE },
{ SDLK_BACKQUOTE, RETROK_BACKQUOTE },
{ SDLK_PAUSE, RETROK_PAUSE },
{ SDLK_KP0, RETROK_KP0 },
{ SDLK_KP1, RETROK_KP1 },
{ SDLK_KP2, RETROK_KP2 },
{ SDLK_KP3, RETROK_KP3 },
{ SDLK_KP4, RETROK_KP4 },
{ SDLK_KP5, RETROK_KP5 },
{ SDLK_KP6, RETROK_KP6 },
{ SDLK_KP7, RETROK_KP7 },
{ SDLK_KP8, RETROK_KP8 },
{ SDLK_KP9, RETROK_KP9 },
{ SDLK_0, RETROK_0 },
{ SDLK_1, RETROK_1 },
{ SDLK_2, RETROK_2 },
{ SDLK_3, RETROK_3 },
{ SDLK_4, RETROK_4 },
{ SDLK_5, RETROK_5 },
{ SDLK_6, RETROK_6 },
{ SDLK_7, RETROK_7 },
{ SDLK_8, RETROK_8 },
{ SDLK_9, RETROK_9 },
{ SDLK_F1, RETROK_F1 },
{ SDLK_F2, RETROK_F2 },
{ SDLK_F3, RETROK_F3 },
{ SDLK_F4, RETROK_F4 },
{ SDLK_F5, RETROK_F5 },
{ SDLK_F6, RETROK_F6 },
{ SDLK_F7, RETROK_F7 },
{ SDLK_F8, RETROK_F8 },
{ SDLK_F9, RETROK_F9 },
{ SDLK_F10, RETROK_F10 },
{ SDLK_F11, RETROK_F11 },
{ SDLK_F12, RETROK_F12 },
{ SDLK_a, RETROK_a },
{ SDLK_b, RETROK_b },
{ SDLK_c, RETROK_c },
{ SDLK_d, RETROK_d },
{ SDLK_e, RETROK_e },
{ SDLK_f, RETROK_f },
{ SDLK_g, RETROK_g },
{ SDLK_h, RETROK_h },
{ SDLK_i, RETROK_i },
{ SDLK_j, RETROK_j },
{ SDLK_k, RETROK_k },
{ SDLK_l, RETROK_l },
{ SDLK_m, RETROK_m },
{ SDLK_n, RETROK_n },
{ SDLK_o, RETROK_o },
{ SDLK_p, RETROK_p },
{ SDLK_q, RETROK_q },
{ SDLK_r, RETROK_r },
{ SDLK_s, RETROK_s },
{ SDLK_t, RETROK_t },
{ SDLK_u, RETROK_u },
{ SDLK_v, RETROK_v },
{ SDLK_w, RETROK_w },
{ SDLK_x, RETROK_x },
{ SDLK_y, RETROK_y },
{ SDLK_z, RETROK_z },
};
static void init_lut(void)
{
memset(keysym_lut, 0, sizeof(keysym_lut));
for (unsigned i = 0; i < sizeof(lut_binds) / sizeof(lut_binds[0]); i++)
keysym_lut[lut_binds[i].sk] = lut_binds[i].sdl;
}
static void *sdl_input_init(void)
{
init_lut();
input_init_keyboard_lut(rarch_key_map_sdl);
sdl_input_t *sdl = (sdl_input_t*)calloc(1, sizeof(*sdl));
if (!sdl)
return NULL;
@ -150,12 +49,14 @@ static bool sdl_key_pressed(int key)
if (key >= RETROK_LAST)
return false;
int sym = input_translate_rk_to_keysym((enum retro_key)key);
int num_keys;
Uint8 *keymap = SDL_GetKeyState(&num_keys);
if (key >= num_keys)
if (sym < 0 || sym >= num_keys)
return false;
return keymap[key];
return keymap[sym];
}
static bool sdl_is_pressed(sdl_input_t *sdl, unsigned port_num, const struct retro_keybind *key)

View File

@ -39,107 +39,6 @@ typedef struct x11_input
int mouse_last_x, mouse_last_y;
} x11_input_t;
struct key_bind
{
unsigned x;
enum retro_key sk;
};
static unsigned keysym_lut[RETROK_LAST];
static const struct key_bind lut_binds[] = {
{ XK_Left, RETROK_LEFT },
{ XK_Right, RETROK_RIGHT },
{ XK_Up, RETROK_UP },
{ XK_Down, RETROK_DOWN },
{ XK_Return, RETROK_RETURN },
{ XK_Tab, RETROK_TAB },
{ XK_Insert, RETROK_INSERT },
{ XK_Home, RETROK_HOME },
{ XK_End, RETROK_END },
{ XK_Page_Up, RETROK_PAGEUP },
{ XK_Page_Down, RETROK_PAGEDOWN },
{ XK_Delete, RETROK_DELETE },
{ XK_Shift_R, RETROK_RSHIFT },
{ XK_Shift_L, RETROK_LSHIFT },
{ XK_Control_L, RETROK_LCTRL },
{ XK_Alt_L, RETROK_LALT },
{ XK_space, RETROK_SPACE },
{ XK_Escape, RETROK_ESCAPE },
{ XK_BackSpace, RETROK_BACKSPACE },
{ XK_KP_Enter, RETROK_KP_ENTER },
{ XK_KP_Add, RETROK_KP_PLUS },
{ XK_KP_Subtract, RETROK_KP_MINUS },
{ XK_KP_Multiply, RETROK_KP_MULTIPLY },
{ XK_KP_Divide, RETROK_KP_DIVIDE },
{ XK_grave, RETROK_BACKQUOTE },
{ XK_Pause, RETROK_PAUSE },
{ XK_KP_0, RETROK_KP0 },
{ XK_KP_1, RETROK_KP1 },
{ XK_KP_2, RETROK_KP2 },
{ XK_KP_3, RETROK_KP3 },
{ XK_KP_4, RETROK_KP4 },
{ XK_KP_5, RETROK_KP5 },
{ XK_KP_6, RETROK_KP6 },
{ XK_KP_7, RETROK_KP7 },
{ XK_KP_8, RETROK_KP8 },
{ XK_KP_9, RETROK_KP9 },
{ XK_0, RETROK_0 },
{ XK_1, RETROK_1 },
{ XK_2, RETROK_2 },
{ XK_3, RETROK_3 },
{ XK_4, RETROK_4 },
{ XK_5, RETROK_5 },
{ XK_6, RETROK_6 },
{ XK_7, RETROK_7 },
{ XK_8, RETROK_8 },
{ XK_9, RETROK_9 },
{ XK_F1, RETROK_F1 },
{ XK_F2, RETROK_F2 },
{ XK_F3, RETROK_F3 },
{ XK_F4, RETROK_F4 },
{ XK_F5, RETROK_F5 },
{ XK_F6, RETROK_F6 },
{ XK_F7, RETROK_F7 },
{ XK_F8, RETROK_F8 },
{ XK_F9, RETROK_F9 },
{ XK_F10, RETROK_F10 },
{ XK_F11, RETROK_F11 },
{ XK_F12, RETROK_F12 },
{ XK_a, RETROK_a },
{ XK_b, RETROK_b },
{ XK_c, RETROK_c },
{ XK_d, RETROK_d },
{ XK_e, RETROK_e },
{ XK_f, RETROK_f },
{ XK_g, RETROK_g },
{ XK_h, RETROK_h },
{ XK_i, RETROK_i },
{ XK_j, RETROK_j },
{ XK_k, RETROK_k },
{ XK_l, RETROK_l },
{ XK_m, RETROK_m },
{ XK_n, RETROK_n },
{ XK_o, RETROK_o },
{ XK_p, RETROK_p },
{ XK_q, RETROK_q },
{ XK_r, RETROK_r },
{ XK_s, RETROK_s },
{ XK_t, RETROK_t },
{ XK_u, RETROK_u },
{ XK_v, RETROK_v },
{ XK_w, RETROK_w },
{ XK_x, RETROK_x },
{ XK_y, RETROK_y },
{ XK_z, RETROK_z },
};
static void init_lut(void)
{
memset(keysym_lut, 0, sizeof(keysym_lut));
for (unsigned i = 0; i < sizeof(lut_binds) / sizeof(lut_binds[0]); i++)
keysym_lut[lut_binds[i].sk] = lut_binds[i].x;
}
static void *x_input_init(void)
{
if (driver.display_type != RARCH_DISPLAY_X11)
@ -157,7 +56,7 @@ static void *x_input_init(void)
x11->win = (Window)driver.video_window;
x11->joypad = input_joypad_init_first();
init_lut();
input_init_keyboard_lut(rarch_key_map_x11);
return x11;
}
@ -167,8 +66,8 @@ static bool x_key_pressed(x11_input_t *x11, int key)
if (key >= RETROK_LAST)
return false;
key = keysym_lut[key];
int keycode = XKeysymToKeycode(x11->display, key);
unsigned sym = input_translate_rk_to_keysym((enum retro_key)key);
int keycode = XKeysymToKeycode(x11->display, sym);
bool ret = x11->state[keycode >> 3] & (1 << (keycode & 7));
return ret;
}