(input_keymaps.c) Namespace changes and documentation

This commit is contained in:
twinaphex 2015-01-12 02:52:52 +01:00
parent 41fbfe3e55
commit b61ae369f7
18 changed files with 258 additions and 127 deletions

View File

@ -72,7 +72,7 @@ static void* const associated_name_tag = (void*)&associated_name_tag;
int32_t idx = self.setting->index ? self.setting->index - 1 : 0;
if ((value = apple_input_find_any_key()))
BINDFOR(*[self setting]).key = input_translate_keysym_to_rk(value);
BINDFOR(*[self setting]).key = input_keymaps_translate_keysym_to_rk(value);
else if ((value = apple_input_find_any_button(idx)) >= 0)
BINDFOR(*[self setting]).joykey = value;
else if ((value = apple_input_find_any_axis(idx)))

View File

@ -558,7 +558,7 @@ static void RunActionSheet(const char* title, const struct string_list* items, U
idx = self.setting->index - 1;
if ((value = apple_input_find_any_key()))
BINDFOR(*self.setting).key = input_translate_keysym_to_rk(value);
BINDFOR(*self.setting).key = input_keymaps_translate_keysym_to_rk(value);
else if ((value = apple_input_find_any_button(idx)) >= 0)
BINDFOR(*self.setting).joykey = value;
else if ((value = apple_input_find_any_axis(idx)))

View File

@ -217,7 +217,7 @@ static int16_t apple_input_is_pressed(apple_input_data_t *apple, unsigned port_n
if (id < RARCH_BIND_LIST_END)
{
const struct retro_keybind *bind = &binds[id];
unsigned bit = input_translate_rk_to_keysym(bind->key);
unsigned bit = input_keymaps_translate_rk_to_keysym(bind->key);
return bind->valid && apple->key_state[bit];
}
return 0;
@ -231,7 +231,7 @@ static void *apple_input_init(void)
if (!apple)
return NULL;
input_init_keyboard_lut(rarch_key_map_apple_hid);
input_keymaps_init_keyboard_lut(rarch_key_map_apple_hid);
apple->joypad = input_joypad_init_driver(g_settings.input.joypad_driver);
@ -329,7 +329,7 @@ static int16_t apple_input_state(void *data,
idx, id, binds[port]);
case RETRO_DEVICE_KEYBOARD:
{
unsigned bit = input_translate_rk_to_keysym((enum retro_key)id);
unsigned bit = input_keymaps_translate_rk_to_keysym((enum retro_key)id);
return (id < RETROK_LAST) && apple->key_state[bit];
}
case RETRO_DEVICE_MOUSE:

View File

@ -159,7 +159,7 @@ static void *dinput_init(void)
IDirectInputDevice8_Acquire(di->mouse);
}
input_init_keyboard_lut(rarch_key_map_dinput);
input_keymaps_init_keyboard_lut(rarch_key_map_dinput);
di->joypad = input_joypad_init_driver(g_settings.input.joypad_driver);
return di;
@ -220,10 +220,11 @@ static void dinput_poll(void *data)
static bool dinput_keyboard_pressed(struct dinput_input *di, unsigned key)
{
unsigned sym;
if (key >= RETROK_LAST)
return false;
sym = input_translate_rk_to_keysym((enum retro_key)key);
sym = input_keymaps_translate_rk_to_keysym((enum retro_key)key);
return di->state[sym] & 0x80;
}
@ -258,7 +259,7 @@ static int16_t dinput_pressed_analog(struct dinput_input *di,
if (dinput_keyboard_pressed(di, bind_minus->key))
pressed_minus = -0x7fff;
if (dinput_keyboard_pressed(di, bind_plus->key))
pressed_plus = 0x7fff;
pressed_plus = 0x7fff;
return pressed_plus + pressed_minus;
}
@ -370,8 +371,8 @@ static int16_t dinput_input_state(void *data,
const struct retro_keybind **binds, unsigned port,
unsigned device, unsigned idx, unsigned id)
{
struct dinput_input *di = (struct dinput_input*)data;
int16_t ret;
struct dinput_input *di = (struct dinput_input*)data;
switch (device)
{
@ -474,6 +475,7 @@ struct pointer_status *dinput_find_pointer(struct dinput_input *di,
break;
check_pos = check_pos->next;
}
return check_pos;
}
@ -646,6 +648,7 @@ bool g_xinput_block_pads;
static void dinput_joypad_destroy(void)
{
unsigned i;
for (i = 0; i < MAX_USERS; i++)
{
if (g_pads[i].joypad)

View File

@ -378,7 +378,7 @@ void input_get_bind_string(char *buf, const struct retro_keybind *bind,
input_get_bind_string_joyaxis(buf, "Auto: ", auto_bind, size);
#ifndef RARCH_CONSOLE
input_translate_rk_to_str(bind->key, key, sizeof(key));
input_keymaps_translate_rk_to_str(bind->key, key, sizeof(key));
if (!strcmp(key, "nul"))
*key = '\0';

View File

@ -54,7 +54,6 @@ bool input_translate_coord_viewport(int mouse_x, int mouse_y,
void input_get_bind_string(char *buf, const struct retro_keybind *bind,
const struct retro_keybind *auto_bind, size_t size);
void input_translate_rk_to_str(enum retro_key key, char *buf, size_t size);
enum retro_key input_translate_str_to_rk(const char *str);

View File

@ -999,16 +999,33 @@ const struct rarch_key_map rarch_key_map_apple_hid[] = {
static enum retro_key rarch_keysym_lut[RETROK_LAST];
void input_init_keyboard_lut(const struct rarch_key_map *map)
/**
* input_keymaps_init_keyboard_lut:
* @map : Keyboard map.
*
* Initializes and sets the keyboard layout to a keyboard map (@map).
**/
void input_keymaps_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)
/**
* input_keymaps_translate_keysym_to_rk:
* @sym : Key symbol.
*
* Translates a key symbol from the keyboard layout table
* to an associated retro key identifier.
*
* Returns: Retro key identifier.
**/
enum retro_key input_keymaps_translate_keysym_to_rk(unsigned sym)
{
unsigned i;
for (i = 0; i < ARRAY_SIZE(rarch_keysym_lut); i++)
{
if (rarch_keysym_lut[i] == sym)
@ -1018,8 +1035,19 @@ enum retro_key input_translate_keysym_to_rk(unsigned sym)
return RETROK_UNKNOWN;
}
void input_translate_rk_to_str(enum retro_key key, char *buf, size_t size)
/**
* input_keymaps_translate_rk_to_str:
* @key : Retro key identifier.
* @buf : Buffer.
* @size : Size of @buf.
*
* Translates a retro key identifier to a human-readable
* identifier string.
**/
void input_keymaps_translate_rk_to_str(enum retro_key key, char *buf, size_t size)
{
unsigned i;
rarch_assert(size >= 2);
*buf = '\0';
@ -1027,22 +1055,29 @@ void input_translate_rk_to_str(enum retro_key key, char *buf, size_t size)
{
buf[0] = (key - RETROK_a) + 'a';
buf[1] = '\0';
return;
}
else
for (i = 0; input_config_key_map[i].str; i++)
{
unsigned i;
for (i = 0; input_config_key_map[i].str; i++)
{
if (input_config_key_map[i].key == key)
{
strlcpy(buf, input_config_key_map[i].str, size);
break;
}
}
if (input_config_key_map[i].key != key)
continue;
strlcpy(buf, input_config_key_map[i].str, size);
break;
}
}
unsigned input_translate_rk_to_keysym(enum retro_key key)
/**
* input_keymaps_translate_rk_to_keysym:
* @key : Retro key identifier
*
* Translates a retro key identifier to a key symbol
* from the keyboard layout table.
*
* Returns: key symbol from the keyboard layout table.
**/
unsigned input_keymaps_translate_rk_to_keysym(enum retro_key key)
{
return rarch_keysym_lut[key];
}

View File

@ -46,9 +46,46 @@ extern const struct rarch_key_map rarch_key_map_rwebinput[];
extern const struct rarch_key_map rarch_key_map_linux[];
extern const struct rarch_key_map rarch_key_map_apple_hid[];
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);
/**
* input_keymaps_init_keyboard_lut:
* @map : Keyboard map.
*
* Initializes and sets the keyboard layout to a keyboard map (@map).
**/
void input_keymaps_init_keyboard_lut(const struct rarch_key_map *map);
/**
* input_keymaps_translate_keysym_to_rk:
* @sym : Key symbol.
*
* Translates a key symbol from the keyboard layout table
* to an associated retro key identifier.
*
* Returns: Retro key identifier.
**/
enum retro_key input_keymaps_translate_keysym_to_rk(unsigned sym);
/**
* input_keymaps_translate_rk_to_keysym:
* @key : Retro key identifier
*
* Translates a retro key identifier to a key symbol
* from the keyboard layout table.
*
* Returns: key symbol from the keyboard layout table.
**/
unsigned input_keymaps_translate_rk_to_keysym(enum retro_key key);
/**
* input_keymaps_translate_rk_to_str:
* @key : Retro key identifier.
* @buf : Buffer.
* @size : Size of @buf.
*
* Translates a retro key identifier to a human-readable
* identifier string.
**/
void input_keymaps_translate_rk_to_str(enum retro_key key, char *buf, size_t size);
#ifdef __cplusplus
}

View File

@ -72,7 +72,8 @@ static bool handle_small_keyboard(unsigned* code, bool down)
if (!map_initialized)
{
for (int i = 0; mapping_def[i].orig; i ++)
int i;
for (i = 0; mapping_def[i].orig; i ++)
mapping[mapping_def[i].orig] = mapping_def[i].mod;
map_initialized = true;
}
@ -157,5 +158,5 @@ void apple_input_keyboard_event(bool down,
apple->key_state[code] = down;
input_keyboard_event(down,
input_translate_keysym_to_rk(code), character, (enum retro_mod)mod);
input_keymaps_translate_keysym_to_rk(code), character, (enum retro_mod)mod);
}

View File

@ -24,15 +24,21 @@ LRESULT win32_handle_keyboard_event(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam)
{
unsigned scancode = (lparam >> 16) & 0xff;
unsigned keycode = input_translate_keysym_to_rk(scancode);
unsigned keycode = input_keymaps_translate_keysym_to_rk(scancode);
uint16_t mod = 0;
mod |= (GetKeyState(VK_SHIFT) & 0x80) ? RETROKMOD_SHIFT : 0;
mod |= (GetKeyState(VK_CONTROL) & 0x80) ? RETROKMOD_CTRL : 0;
mod |= (GetKeyState(VK_MENU) & 0x80) ? RETROKMOD_ALT : 0;
mod |= (GetKeyState(VK_CAPITAL) & 0x81) ? RETROKMOD_CAPSLOCK : 0;
mod |= (GetKeyState(VK_SCROLL) & 0x81) ? RETROKMOD_SCROLLOCK : 0;
mod |= ((GetKeyState(VK_LWIN) | GetKeyState(VK_RWIN)) & 0x80) ?
RETROKMOD_META : 0;
if (GetKeyState(VK_SHIFT) & 0x80)
mod |= RETROKMOD_SHIFT;
if (GetKeyState(VK_CONTROL) & 0x80)
mod |= RETROKMOD_CTRL;
if (GetKeyState(VK_MENU) & 0x80)
mod |= RETROKMOD_ALT;
if (GetKeyState(VK_CAPITAL) & 0x81)
mod |= RETROKMOD_CAPSLOCK;
if (GetKeyState(VK_SCROLL) & 0x81)
mod |= RETROKMOD_SCROLLOCK;
if ((GetKeyState(VK_LWIN) | GetKeyState(VK_RWIN)) & 0x80)
mod |= RETROKMOD_META;
switch (message)
{

View File

@ -77,11 +77,13 @@ static size_t conv_utf8_utf32(uint32_t *out,
void x11_handle_key_event(XEvent *event, XIC ic, bool filter)
{
int i;
unsigned state;
uint16_t mod = 0;
char keybuf[32] = {0};
uint32_t chars[32] = {0};
bool down = event->type == KeyPress;
unsigned key = input_translate_keysym_to_rk(XLookupKeysym(&event->xkey, 0));
unsigned key = input_keymaps_translate_keysym_to_rk(XLookupKeysym(&event->xkey, 0));
int num = 0;
if (down && !filter)
@ -107,15 +109,21 @@ void x11_handle_key_event(XEvent *event, XIC ic, bool filter)
#endif
}
unsigned state = event->xkey.state;
uint16_t mod = 0;
mod |= (state & ShiftMask) ? RETROKMOD_SHIFT : 0;
mod |= (state & LockMask) ? RETROKMOD_CAPSLOCK : 0;
mod |= (state & ControlMask) ? RETROKMOD_CTRL : 0;
mod |= (state & Mod1Mask) ? RETROKMOD_ALT : 0;
mod |= (state & Mod4Mask) ? RETROKMOD_META : 0;
state = event->xkey.state;
if (state & ShiftMask)
mod |= RETROKMOD_SHIFT;
if (state & LockMask)
mod |= RETROKMOD_CAPSLOCK;
if (state & ControlMask)
mod |= RETROKMOD_CTRL;
if (state & Mod1Mask)
mod |= RETROKMOD_ALT;
if (state & Mod4Mask)
mod |= RETROKMOD_META;
input_keyboard_event(down, key, chars[0], mod);
for (i = 1; i < num; i++)
input_keyboard_event(down, RETROK_UNKNOWN, chars[i], mod);
}

View File

@ -60,8 +60,9 @@ void handle_xkb(
(enum xkb_state_component)((XKB_STATE_MODS_EFFECTIVE) > 0)) ? *map_bit : 0;
}
input_keyboard_event(value, input_translate_keysym_to_rk(code),
input_keyboard_event(value, input_keymaps_translate_keysym_to_rk(code),
num_syms ? xkb_keysym_to_utf32(syms[0]) : 0, mod);
for (i = 1; i < num_syms; i++)
input_keyboard_event(value, RETROK_UNKNOWN, xkb_keysym_to_utf32(syms[i]), mod);
}

View File

@ -115,7 +115,7 @@ static void *linuxraw_input_init(void)
atexit(linuxraw_resetKbmd);
linuxraw->joypad = input_joypad_init_driver(g_settings.input.joypad_driver);
input_init_keyboard_lut(rarch_key_map_linux);
input_keymaps_init_keyboard_lut(rarch_key_map_linux);
/* We need to disable use of stdin command interface if
* stdin is supposed to be used for input. */
@ -126,7 +126,7 @@ static void *linuxraw_input_init(void)
static bool linuxraw_key_pressed(linuxraw_input_t *linuxraw, int key)
{
unsigned sym = input_translate_rk_to_keysym((enum retro_key)key);
unsigned sym = input_keymaps_translate_rk_to_keysym((enum retro_key)key);
return linuxraw->state[sym];
}
@ -149,6 +149,7 @@ static int16_t linuxraw_analog_pressed(linuxraw_input_t *linuxraw,
int16_t pressed_minus = 0, pressed_plus = 0;
unsigned id_minus = 0;
unsigned id_plus = 0;
input_conv_analog_id_to_bind_id(idx, id, &id_minus, &id_plus);
if (linuxraw_is_pressed(linuxraw, binds, id_minus))
@ -162,8 +163,6 @@ static int16_t linuxraw_analog_pressed(linuxraw_input_t *linuxraw,
static bool linuxraw_bind_button_pressed(void *data, int key)
{
linuxraw_input_t *linuxraw = (linuxraw_input_t*)data;
if (!linuxraw)
return false;
return linuxraw_is_pressed(linuxraw, g_settings.input.binds[0], key) ||
input_joypad_pressed(linuxraw->joypad, 0, g_settings.input.binds[0], key);
}
@ -172,8 +171,8 @@ static int16_t linuxraw_input_state(void *data,
const struct retro_keybind **binds, unsigned port,
unsigned device, unsigned idx, unsigned id)
{
linuxraw_input_t *linuxraw = (linuxraw_input_t*)data;
int16_t ret;
linuxraw_input_t *linuxraw = (linuxraw_input_t*)data;
switch (device)
{

View File

@ -46,18 +46,22 @@ static void *rwebinput_input_init(void)
return NULL;
}
input_init_keyboard_lut(rarch_key_map_rwebinput);
input_keymaps_init_keyboard_lut(rarch_key_map_rwebinput);
return rwebinput;
}
static bool rwebinput_key_pressed(rwebinput_input_t *rwebinput, int key)
{
unsigned sym;
bool ret;
if (key >= RETROK_LAST)
return false;
unsigned sym = input_translate_rk_to_keysym((enum retro_key)key);
bool ret = rwebinput->state.keys[sym >> 3] & (1 << (sym & 7));
sym = input_keymaps_translate_rk_to_keysym((enum retro_key)key);
ret = rwebinput->state.keys[sym >> 3] & (1 << (sym & 7));
return ret;
}
@ -68,8 +72,8 @@ static bool rwebinput_is_pressed(rwebinput_input_t *rwebinput, const struct retr
const struct retro_keybind *bind = &binds[id];
return bind->valid && rwebinput_key_pressed(rwebinput, binds[id].key);
}
else
return false;
return false;
}
static bool rwebinput_bind_button_pressed(void *data, int key)
@ -90,20 +94,25 @@ static int16_t rwebinput_mouse_state(rwebinput_input_t *rwebinput, unsigned id)
return rwebinput->state.mouse_l;
case RETRO_DEVICE_ID_MOUSE_RIGHT:
return rwebinput->state.mouse_r;
default:
return 0;
}
return 0;
}
static int16_t rwebinput_analog_pressed(rwebinput_input_t *rwebinput,
const struct retro_keybind *binds, unsigned idx, unsigned id)
{
int16_t pressed_minus = 0, pressed_plus = 0;
unsigned id_minus = 0;
unsigned id_plus = 0;
input_conv_analog_id_to_bind_id(idx, id, &id_minus, &id_plus);
int16_t pressed_minus = rwebinput_is_pressed(rwebinput, binds, id_minus) ? -0x7fff : 0;
int16_t pressed_plus = rwebinput_is_pressed(rwebinput, binds, id_plus) ? 0x7fff : 0;
if (rwebinput_is_pressed(rwebinput, binds, id_minus))
pressed_minus = -0x7fff;
if (rwebinput_is_pressed(rwebinput, binds, id_plus))
pressed_plus = 0x7fff;
return pressed_plus + pressed_minus;
}
@ -125,10 +134,9 @@ static int16_t rwebinput_input_state(void *data, const struct retro_keybind **bi
case RETRO_DEVICE_MOUSE:
return rwebinput_mouse_state(rwebinput, id);
default:
return 0;
}
return 0;
}
static void rwebinput_input_free(void *data)
@ -146,23 +154,25 @@ static void rwebinput_input_free(void *data)
static void rwebinput_input_poll(void *data)
{
unsigned i;
rwebinput_input_t *rwebinput = (rwebinput_input_t*)data;
rwebinput_state_t *state = RWebInputPoll(rwebinput->context);
rwebinput_state_t *state = RWebInputPoll(rwebinput->context);
// get new keys
for (unsigned i = 0; i < 32; i++)
/* Get new keys. */
for (i = 0; i < 32; i++)
{
if (state->keys[i] != rwebinput->state.keys[i])
unsigned k;
uint8_t diff;
if (state->keys[i] == rwebinput->state.keys[i])
continue;
diff = state->keys[i] ^ rwebinput->state.keys[i];
for (k = 0; diff; diff >>= 1, k++)
{
uint8_t diff = state->keys[i] ^ rwebinput->state.keys[i];
for (unsigned k = 0; diff; diff >>= 1, k++)
{
if (diff & 1)
{
input_keyboard_event((state->keys[i] & (1 << k)) != 0, input_translate_keysym_to_rk(i * 8 + k), 0, 0);
}
}
if (diff & 1)
input_keyboard_event((state->keys[i] & (1 << k)) != 0, input_keymaps_translate_keysym_to_rk(i * 8 + k), 0, 0);
}
}

View File

@ -40,7 +40,7 @@ typedef struct sdl_input
static void *sdl_input_init(void)
{
input_init_keyboard_lut(rarch_key_map_sdl);
input_keymaps_init_keyboard_lut(rarch_key_map_sdl);
sdl_input_t *sdl = (sdl_input_t*)calloc(1, sizeof(*sdl));
if (!sdl)
return NULL;
@ -53,13 +53,15 @@ static void *sdl_input_init(void)
static bool sdl_key_pressed(int key)
{
int num_keys;
const uint8_t *keymap;
unsigned sym;
if (key >= RETROK_LAST)
return false;
unsigned sym = input_translate_rk_to_keysym((enum retro_key)key);
sym = input_keymaps_translate_rk_to_keysym((enum retro_key)key);
int num_keys;
const uint8_t *keymap;
#if HAVE_SDL2
sym = SDL_GetScancodeFromKey(sym);
keymap = SDL_GetKeyboardState(&num_keys);
@ -83,12 +85,17 @@ static bool sdl_is_pressed(sdl_input_t *sdl, unsigned port_num, const struct ret
static int16_t sdl_analog_pressed(sdl_input_t *sdl, const struct retro_keybind *binds,
unsigned idx, unsigned id)
{
int16_t pressed_minus = 0, pressed_plus = 0;
unsigned id_minus = 0;
unsigned id_plus = 0;
input_conv_analog_id_to_bind_id(idx, id, &id_minus, &id_plus);
int16_t pressed_minus = sdl_key_pressed(binds[id_minus].key) ? -0x7fff : 0;
int16_t pressed_plus = sdl_key_pressed(binds[id_plus].key) ? 0x7fff : 0;
if (sdl_key_pressed(binds[id_minus].key))
pressed_minus = -0x7fff;
if (sdl_key_pressed(binds[id_plus].key))
pressed_plus = 0x7fff;
return pressed_plus + pressed_minus;
}
@ -141,19 +148,21 @@ static int16_t sdl_mouse_device_state(sdl_input_t *sdl, unsigned id)
return sdl->mouse_y;
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
return sdl->mouse_m;
default:
return 0;
}
return 0;
}
static int16_t sdl_pointer_device_state(sdl_input_t *sdl,
unsigned idx, unsigned id, bool screen)
{
bool valid, inside;
int16_t res_x = 0, res_y = 0, res_screen_x = 0, res_screen_y = 0;
if (idx != 0)
return 0;
int16_t res_x = 0, res_y = 0, res_screen_x = 0, res_screen_y = 0;
bool valid = input_translate_coord_viewport(sdl->mouse_abs_x, sdl->mouse_abs_y,
valid = input_translate_coord_viewport(sdl->mouse_abs_x, sdl->mouse_abs_y,
&res_x, &res_y, &res_screen_x, &res_screen_y);
if (!valid)
@ -165,7 +174,7 @@ static int16_t sdl_pointer_device_state(sdl_input_t *sdl,
res_y = res_screen_y;
}
bool inside = (res_x >= -0x7fff) && (res_y >= -0x7fff);
inside = (res_x >= -0x7fff) && (res_y >= -0x7fff);
if (!inside)
return 0;
@ -178,9 +187,9 @@ static int16_t sdl_pointer_device_state(sdl_input_t *sdl,
return res_y;
case RETRO_DEVICE_ID_POINTER_PRESSED:
return sdl->mouse_l;
default:
return 0;
}
return 0;
}
static int16_t sdl_lightgun_device_state(sdl_input_t *sdl, unsigned id)
@ -201,15 +210,16 @@ static int16_t sdl_lightgun_device_state(sdl_input_t *sdl, unsigned id)
return sdl->mouse_m && sdl->mouse_r;
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
return sdl->mouse_m && sdl->mouse_l;
default:
return 0;
}
return 0;
}
static int16_t sdl_input_state(void *data_, const struct retro_keybind **binds,
unsigned port, unsigned device, unsigned idx, unsigned id)
{
sdl_input_t *data = (sdl_input_t*)data_;
switch (device)
{
case RETRO_DEVICE_JOYPAD:
@ -232,10 +242,12 @@ static int16_t sdl_input_state(void *data_, const struct retro_keybind **binds,
static void sdl_input_free(void *data)
{
sdl_input_t *sdl = (sdl_input_t*)data;
if (!data)
return;
// Flush out all pending events.
/* Flush out all pending events. */
#ifdef HAVE_SDL2
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
#else
@ -243,8 +255,6 @@ static void sdl_input_free(void *data)
while (SDL_PollEvent(&event));
#endif
sdl_input_t *sdl = (sdl_input_t*)data;
if (sdl->joypad)
sdl->joypad->destroy();
@ -254,17 +264,17 @@ static void sdl_input_free(void *data)
#ifdef HAVE_SDL2
static void sdl_grab_mouse(void *data, bool state)
{
struct temp{
SDL_Window *w;
};
sdl_input_t *sdl = (sdl_input_t*)data;
if (driver.video == &video_sdl2)
{
/* first member of sdl2_video_t is the window */
struct temp{
SDL_Window *w;
};
SDL_SetWindowGrab(((struct temp*)driver.video_data)->w,
state ? SDL_TRUE : SDL_FALSE);
}
if (driver.video != &video_sdl2)
return;
/* First member of sdl2_video_t is the window */
SDL_SetWindowGrab(((struct temp*)driver.video_data)->w,
state ? SDL_TRUE : SDL_FALSE);
}
#endif
@ -272,6 +282,8 @@ static bool sdl_set_rumble(void *data, unsigned port,
enum retro_rumble_effect effect, uint16_t strength)
{
sdl_input_t *sdl = (sdl_input_t*)data;
if (!sdl)
return false;
return input_joypad_set_rumble(sdl->joypad, port, effect, strength);
}
@ -284,7 +296,9 @@ static const rarch_joypad_driver_t *sdl_get_joypad_driver(void *data)
static void sdl_poll_mouse(sdl_input_t *sdl)
{
Uint8 btn = SDL_GetRelativeMouseState(&sdl->mouse_x, &sdl->mouse_y);
SDL_GetMouseState(&sdl->mouse_abs_x, &sdl->mouse_abs_y);
sdl->mouse_l = SDL_BUTTON(SDL_BUTTON_LEFT) & btn ? 1 : 0;
sdl->mouse_r = SDL_BUTTON(SDL_BUTTON_RIGHT) & btn ? 1 : 0;
sdl->mouse_m = SDL_BUTTON(SDL_BUTTON_MIDDLE) & btn ? 1 : 0;
@ -296,9 +310,10 @@ static void sdl_poll_mouse(sdl_input_t *sdl)
static void sdl_input_poll(void *data)
{
SDL_PumpEvents();
sdl_input_t *sdl = (sdl_input_t*)data;
SDL_PumpEvents();
if (sdl->joypad)
sdl->joypad->poll();
sdl_poll_mouse(sdl);
@ -313,7 +328,7 @@ static void sdl_input_poll(void *data)
if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP)
{
uint16_t mod = 0;
unsigned code = input_translate_keysym_to_rk(event.key.keysym.sym);
unsigned code = input_keymaps_translate_keysym_to_rk(event.key.keysym.sym);
if (event.key.keysym.mod & KMOD_SHIFT)
mod |= RETROKMOD_SHIFT;

View File

@ -486,7 +486,7 @@ static bool udev_input_is_pressed(udev_input_t *udev, const struct retro_keybind
if (id < RARCH_BIND_LIST_END)
{
const struct retro_keybind *bind = &binds[id];
unsigned bit = input_translate_rk_to_keysym(binds[id].key);
unsigned bit = input_keymaps_translate_rk_to_keysym(binds[id].key);
return bind->valid && BIT_GET(udev->key_state, bit);
}
return false;
@ -512,8 +512,8 @@ static int16_t udev_analog_pressed(udev_input_t *udev,
static int16_t udev_input_state(void *data, const struct retro_keybind **binds,
unsigned port, unsigned device, unsigned idx, unsigned id)
{
udev_input_t *udev = (udev_input_t*)data;
int16_t ret;
udev_input_t *udev = (udev_input_t*)data;
switch (device)
{
@ -529,7 +529,7 @@ static int16_t udev_input_state(void *data, const struct retro_keybind **binds,
case RETRO_DEVICE_KEYBOARD:
{
unsigned bit = input_translate_rk_to_keysym((enum retro_key)id);
unsigned bit = input_keymaps_translate_rk_to_keysym((enum retro_key)id);
return id < RETROK_LAST && BIT_GET(udev->key_state, bit);
}
case RETRO_DEVICE_MOUSE:
@ -603,19 +603,19 @@ static bool open_devices(udev_input_t *udev, const char *type, device_handle_cb
udev_enumerate_add_match_property(enumerate, type, "1");
udev_enumerate_scan_devices(enumerate);
devs = udev_enumerate_get_list_entry(enumerate);
for (item = devs; item; item = udev_list_entry_get_next(item))
{
const char *name = udev_list_entry_get_name(item);
const char *name = udev_list_entry_get_name(item);
/* Get the filename of the /sys entry for the device
* and create a udev_device object (dev) representing it. */
struct udev_device *dev = udev_device_new_from_syspath(udev->udev, name);
const char *devnode = udev_device_get_devnode(dev);
int fd = devnode ? open(devnode, O_RDONLY | O_NONBLOCK) : -1;
if (devnode)
{
int fd = open(devnode, O_RDONLY | O_NONBLOCK);
RARCH_LOG("[udev] Adding device %s as type %s.\n", devnode, type);
if (!add_device(udev, devnode, cb))
RARCH_ERR("[udev] Failed to open device: %s (%s).\n", devnode, strerror(errno));
@ -802,7 +802,7 @@ static void *udev_input_init(void)
RARCH_WARN("[udev]: Couldn't open any keyboard, mouse or touchpad. Are permissions set correctly for /dev/input/event*?\n");
udev->joypad = input_joypad_init_driver(g_settings.input.joypad_driver);
input_init_keyboard_lut(rarch_key_map_linux);
input_keymaps_init_keyboard_lut(rarch_key_map_linux);
disable_terminal_input();
return udev;

View File

@ -60,19 +60,23 @@ static void *x_input_init(void)
x11->win = (Window)driver.video_window;
x11->joypad = input_joypad_init_driver(g_settings.input.joypad_driver);
input_init_keyboard_lut(rarch_key_map_x11);
input_keymaps_init_keyboard_lut(rarch_key_map_x11);
return x11;
}
static bool x_key_pressed(x11_input_t *x11, int key)
{
unsigned sym;
int keycode;
bool ret;
if (key >= RETROK_LAST)
return false;
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));
sym = input_keymaps_translate_rk_to_keysym((enum retro_key)key);
keycode = XKeysymToKeycode(x11->display, sym);
ret = x11->state[keycode >> 3] & (1 << (keycode & 7));
return ret;
}
@ -90,18 +94,25 @@ static bool x_is_pressed(x11_input_t *x11,
static int16_t x_pressed_analog(x11_input_t *x11,
const struct retro_keybind *binds, unsigned idx, unsigned id)
{
int16_t pressed_minus = 0, pressed_plus = 0;
unsigned id_minus = 0;
unsigned id_plus = 0;
input_conv_analog_id_to_bind_id(idx, id, &id_minus, &id_plus);
int16_t pressed_minus = x_is_pressed(x11, binds, id_minus) ? -0x7fff : 0;
int16_t pressed_plus = x_is_pressed(x11, binds, id_plus) ? 0x7fff : 0;
if (x_is_pressed(x11, binds, id_minus))
pressed_minus = -0x7fff;
if (x_is_pressed(x11, binds, id_plus))
pressed_plus = 0x7fff;
return pressed_plus + pressed_minus;
}
static bool x_bind_button_pressed(void *data, int key)
{
x11_input_t *x11 = (x11_input_t*)data;
if (!x11)
return false;
return x_is_pressed(x11, g_settings.input.binds[0], key) ||
input_joypad_pressed(x11->joypad, 0, g_settings.input.binds[0], key);
}
@ -132,11 +143,13 @@ static int16_t x_mouse_state(x11_input_t *x11, unsigned id)
static int16_t x_pointer_state(x11_input_t *x11,
unsigned idx, unsigned id, bool screen)
{
int16_t res_x = 0, res_y = 0, res_screen_x = 0, res_screen_y = 0;
bool valid, inside;
if (idx != 0)
return 0;
int16_t res_x = 0, res_y = 0, res_screen_x = 0, res_screen_y = 0;
bool valid = input_translate_coord_viewport(x11->mouse_x, x11->mouse_y,
valid = input_translate_coord_viewport(x11->mouse_x, x11->mouse_y,
&res_x, &res_y, &res_screen_x, &res_screen_y);
if (!valid)
@ -148,7 +161,7 @@ static int16_t x_pointer_state(x11_input_t *x11,
res_y = res_screen_y;
}
bool inside = (res_x >= -0x7fff) && (res_y >= -0x7fff);
inside = (res_x >= -0x7fff) && (res_y >= -0x7fff);
if (!inside)
return 0;
@ -184,17 +197,17 @@ static int16_t x_lightgun_state(x11_input_t *x11, unsigned id)
return x11->mouse_m && x11->mouse_r;
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
return x11->mouse_m && x11->mouse_l;
default:
return 0;
}
return 0;
}
static int16_t x_input_state(void *data,
const struct retro_keybind **binds, unsigned port,
unsigned device, unsigned idx, unsigned id)
{
x11_input_t *x11 = (x11_input_t*)data;
int16_t ret;
x11_input_t *x11 = (x11_input_t*)data;
switch (device)
{
@ -304,13 +317,16 @@ static void x_input_poll(void *data)
static void x_grab_mouse(void *data, bool state)
{
x11_input_t *x11 = (x11_input_t*)data;
x11->grab_mouse = state;
if (x11)
x11->grab_mouse = state;
}
static bool x_set_rumble(void *data, unsigned port,
enum retro_rumble_effect effect, uint16_t strength)
{
x11_input_t *x11 = (x11_input_t*)data;
if (!x11)
return false;
return input_joypad_set_rumble(x11->joypad, port, effect, strength);
}

View File

@ -21,6 +21,7 @@
#include "config.def.h"
#include <file/file_path.h>
#include "input/input_common.h"
#include "input/input_keymaps.h"
#include "settings.h"
#ifdef HAVE_CONFIG_H
@ -1535,7 +1536,7 @@ static void save_keybind_key(config_file_t *conf, const char *prefix,
char key[64], btn[64];
snprintf(key, sizeof(key), "%s_%s", prefix, base);
input_translate_rk_to_str(bind->key, btn, sizeof(btn));
input_keymaps_translate_rk_to_str(bind->key, btn, sizeof(btn));
config_set_string(conf, key, btn);
}