1
0
mirror of https://github.com/libretro/RetroArch synced 2025-04-03 01:21:10 +00:00

(linuxraw_input.c) simplifications

This commit is contained in:
twinaphex 2017-06-07 01:12:35 +02:00
parent 3dede6d71a
commit 9e93bdbe27

@ -72,14 +72,6 @@ static void *linuxraw_input_init(const char *joypad_driver)
return linuxraw; return linuxraw;
} }
static bool linuxraw_is_pressed(linuxraw_input_t *linuxraw,
const struct retro_keybind *binds, unsigned id)
{
const struct retro_keybind *bind = &binds[id];
unsigned sym = rarch_keysym_lut[(enum retro_key)binds[id].key];
return linuxraw->state[sym];
}
static int16_t linuxraw_analog_pressed(linuxraw_input_t *linuxraw, static int16_t linuxraw_analog_pressed(linuxraw_input_t *linuxraw,
const struct retro_keybind *binds, unsigned idx, unsigned id) const struct retro_keybind *binds, unsigned idx, unsigned id)
{ {
@ -90,10 +82,12 @@ static int16_t linuxraw_analog_pressed(linuxraw_input_t *linuxraw,
input_conv_analog_id_to_bind_id(idx, id, &id_minus, &id_plus); input_conv_analog_id_to_bind_id(idx, id, &id_minus, &id_plus);
if ((id_minus < RARCH_BIND_LIST_END) && binds && binds->valid && if ((id_minus < RARCH_BIND_LIST_END) && binds && binds->valid &&
linuxraw_is_pressed(linuxraw, binds, id_minus)) linuxraw->state[rarch_keysym_lut[(enum retro_key)binds[id_minus].key]]
)
pressed_minus = -0x7fff; pressed_minus = -0x7fff;
if ((id_plus < RARCH_BIND_LIST_END) && binds && binds->valid && if ((id_plus < RARCH_BIND_LIST_END) && binds && binds->valid &&
linuxraw_is_pressed(linuxraw, binds, id_plus)) linuxraw->state[rarch_keysym_lut[(enum retro_key)binds[id_plus].key]]
)
pressed_plus = 0x7fff; pressed_plus = 0x7fff;
return pressed_plus + pressed_minus; return pressed_plus + pressed_minus;
@ -109,21 +103,26 @@ static int16_t linuxraw_input_state(void *data,
const struct retro_keybind **binds, unsigned port, const struct retro_keybind **binds, unsigned port,
unsigned device, unsigned idx, unsigned id) unsigned device, unsigned idx, unsigned id)
{ {
int16_t ret = 0;
linuxraw_input_t *linuxraw = (linuxraw_input_t*)data; linuxraw_input_t *linuxraw = (linuxraw_input_t*)data;
switch (device) switch (device)
{ {
case RETRO_DEVICE_JOYPAD: case RETRO_DEVICE_JOYPAD:
return ((id < RARCH_BIND_LIST_END) && binds[port]->valid && return ((id < RARCH_BIND_LIST_END) && binds[port]->valid &&
linuxraw_is_pressed(linuxraw, binds[port], id)) || linuxraw->state[rarch_keysym_lut[(enum retro_key)binds[port][id].key]]
input_joypad_pressed(linuxraw->joypad, joypad_info, port, binds[port], id); )
|| input_joypad_pressed(linuxraw->joypad,
joypad_info, port, binds[port], id);
case RETRO_DEVICE_ANALOG: case RETRO_DEVICE_ANALOG:
if (binds[port]) if (binds[port])
ret = linuxraw_analog_pressed(linuxraw, binds[port], idx, id); {
if (!ret && binds[port]) int16_t ret = linuxraw_analog_pressed(linuxraw, binds[port], idx, id);
ret = input_joypad_analog(linuxraw->joypad, joypad_info, port, idx, id, binds[port]); if (!ret)
return ret; ret = input_joypad_analog(linuxraw->joypad,
joypad_info, port, idx, id, binds[port]);
return ret;
}
break;
} }
return 0; return 0;
@ -163,12 +162,12 @@ static const input_device_driver_t *linuxraw_get_joypad_driver(void *data)
static void linuxraw_input_poll(void *data) static void linuxraw_input_poll(void *data)
{ {
uint8_t c; uint8_t c;
uint16_t t;
linuxraw_input_t *linuxraw = (linuxraw_input_t*)data; linuxraw_input_t *linuxraw = (linuxraw_input_t*)data;
while (read(STDIN_FILENO, &c, 1) > 0) while (read(STDIN_FILENO, &c, 1) > 0)
{ {
bool pressed; bool pressed;
uint16_t t;
if (c == KEY_C && (linuxraw->state[KEY_LEFTCTRL] || linuxraw->state[KEY_RIGHTCTRL])) if (c == KEY_C && (linuxraw->state[KEY_LEFTCTRL] || linuxraw->state[KEY_RIGHTCTRL]))
kill(getpid(), SIGINT); kill(getpid(), SIGINT);