Get rid of udev_is_pressed

This commit is contained in:
twinaphex 2020-06-13 01:54:22 +02:00
parent 6cc9a3f9b4
commit 52ff31f877

View File

@ -932,30 +932,6 @@ static bool udev_mouse_button_pressed(
return false; return false;
} }
static int16_t udev_is_pressed(
udev_input_t *udev,
const input_device_driver_t *joypad,
rarch_joypad_info_t *joypad_info,
const struct retro_keybind *binds,
unsigned port, unsigned id)
{
const struct retro_keybind *bind = &binds[id];
/* Auto-binds are per joypad, not per user. */
const uint64_t joykey = (binds[id].joykey != NO_BTN)
? binds[id].joykey : joypad_info->auto_binds[id].joykey;
const uint32_t joyaxis = (binds[id].joyaxis != AXIS_NONE)
? binds[id].joyaxis : joypad_info->auto_binds[id].joyaxis;
if (udev_mouse_button_pressed(udev, port, bind->mbutton))
return 1;
if ((uint16_t)joykey != NO_BTN && joypad->button(
joypad_info->joy_idx, (uint16_t)joykey))
return 1;
if (((float)abs(joypad->axis(joypad_info->joy_idx, joyaxis))
/ 0x8000) > joypad_info->axis_threshold)
return 1;
return 0;
}
static int16_t udev_analog_pressed(const struct retro_keybind *binds, static int16_t udev_analog_pressed(const struct retro_keybind *binds,
unsigned idx, unsigned id) unsigned idx, unsigned id)
{ {
@ -1019,10 +995,12 @@ static int16_t udev_input_state(void *data,
{ {
if (binds[port][i].valid) if (binds[port][i].valid)
{ {
if (udev_is_pressed( if (button_is_pressed(
udev, udev->joypad, udev->joypad,
joypad_info, binds[port], port, i)) joypad_info, binds[port], port, i))
ret |= (1 << i); ret |= (1 << i);
else if (udev_mouse_button_pressed(udev, port, binds[port][i].mbutton))
ret |= (1 << i);
} }
} }
} }
@ -1032,12 +1010,14 @@ static int16_t udev_input_state(void *data,
{ {
if (binds[port][i].valid) if (binds[port][i].valid)
{ {
if (udev_is_pressed(udev, udev->joypad, if (button_is_pressed(udev->joypad,
joypad_info, binds[port], port, i)) joypad_info, binds[port], port, i))
ret |= (1 << i); ret |= (1 << i);
else if ((binds[port][i].key < RETROK_LAST) && else if ((binds[port][i].key < RETROK_LAST) &&
udev_keyboard_pressed(udev, binds[port][i].key)) udev_keyboard_pressed(udev, binds[port][i].key))
ret |= (1 << i); ret |= (1 << i);
else if (udev_mouse_button_pressed(udev, port, binds[port][i].mbutton))
ret |= (1 << i);
} }
} }
} }
@ -1050,7 +1030,7 @@ static int16_t udev_input_state(void *data,
{ {
if (binds[port][id].valid) if (binds[port][id].valid)
{ {
if (udev_is_pressed(udev, udev->joypad, if (button_is_pressed(udev->joypad,
joypad_info, binds[port], port, id)) joypad_info, binds[port], port, id))
return 1; return 1;
else if ( else if (
@ -1060,6 +1040,9 @@ static int16_t udev_input_state(void *data,
|| !input_udev.keyboard_mapping_blocked) || !input_udev.keyboard_mapping_blocked)
) )
return 1; return 1;
else if (udev_mouse_button_pressed(udev, port,
binds[port][id].mbutton))
return 1;
} }
} }
} }
@ -1106,9 +1089,16 @@ static int16_t udev_input_state(void *data,
[RARCH_LIGHTGUN_TRIGGER].key) ) [RARCH_LIGHTGUN_TRIGGER].key) )
return 1; return 1;
if (binds[port][RARCH_LIGHTGUN_TRIGGER].valid) if (binds[port][RARCH_LIGHTGUN_TRIGGER].valid)
return udev_is_pressed(udev, udev->joypad, {
joypad_info, binds[port], unsigned new_id = RARCH_LIGHTGUN_TRIGGER;
port, RARCH_LIGHTGUN_TRIGGER); if (button_is_pressed(udev->joypad,
joypad_info, binds[port],
port, new_id)
|| udev_mouse_button_pressed(udev, port,
binds[port][new_id].mbutton)
)
return 1;
}
break; break;
case RETRO_DEVICE_ID_LIGHTGUN_RELOAD: case RETRO_DEVICE_ID_LIGHTGUN_RELOAD:
if (!input_udev.keyboard_mapping_blocked) if (!input_udev.keyboard_mapping_blocked)
@ -1117,9 +1107,16 @@ static int16_t udev_input_state(void *data,
[RARCH_LIGHTGUN_RELOAD].key) ) [RARCH_LIGHTGUN_RELOAD].key) )
return 1; return 1;
if (binds[port][RARCH_LIGHTGUN_RELOAD].valid) if (binds[port][RARCH_LIGHTGUN_RELOAD].valid)
return udev_is_pressed(udev, udev->joypad, {
joypad_info, binds[port], unsigned new_id = RARCH_LIGHTGUN_RELOAD;
port, RARCH_LIGHTGUN_RELOAD); if (button_is_pressed(udev->joypad,
joypad_info, binds[port],
port, new_id)
|| udev_mouse_button_pressed(udev, port,
binds[port][new_id].mbutton)
)
return 1;
}
break; break;
case RETRO_DEVICE_ID_LIGHTGUN_AUX_A: case RETRO_DEVICE_ID_LIGHTGUN_AUX_A:
if (!input_udev.keyboard_mapping_blocked) if (!input_udev.keyboard_mapping_blocked)
@ -1128,9 +1125,16 @@ static int16_t udev_input_state(void *data,
[RARCH_LIGHTGUN_AUX_A].key) ) [RARCH_LIGHTGUN_AUX_A].key) )
return 1; return 1;
if (binds[port][RARCH_LIGHTGUN_AUX_A].valid) if (binds[port][RARCH_LIGHTGUN_AUX_A].valid)
return udev_is_pressed(udev, udev->joypad, {
joypad_info, binds[port], unsigned new_id = RARCH_LIGHTGUN_AUX_A;
port, RARCH_LIGHTGUN_AUX_A); if (button_is_pressed(udev->joypad,
joypad_info, binds[port],
port, new_id)
|| udev_mouse_button_pressed(udev, port,
binds[port][new_id].mbutton)
)
return 1;
}
break; break;
case RETRO_DEVICE_ID_LIGHTGUN_AUX_B: case RETRO_DEVICE_ID_LIGHTGUN_AUX_B:
if (!input_udev.keyboard_mapping_blocked) if (!input_udev.keyboard_mapping_blocked)
@ -1139,9 +1143,16 @@ static int16_t udev_input_state(void *data,
[RARCH_LIGHTGUN_AUX_B].key) ) [RARCH_LIGHTGUN_AUX_B].key) )
return 1; return 1;
if (binds[port][RARCH_LIGHTGUN_AUX_B].valid) if (binds[port][RARCH_LIGHTGUN_AUX_B].valid)
return udev_is_pressed(udev, udev->joypad, {
joypad_info, binds[port], unsigned new_id = RARCH_LIGHTGUN_AUX_B;
port, RARCH_LIGHTGUN_AUX_B); if (button_is_pressed(udev->joypad,
joypad_info, binds[port],
port, new_id)
|| udev_mouse_button_pressed(udev, port,
binds[port][new_id].mbutton)
)
return 1;
}
break; break;
case RETRO_DEVICE_ID_LIGHTGUN_AUX_C: case RETRO_DEVICE_ID_LIGHTGUN_AUX_C:
if (!input_udev.keyboard_mapping_blocked) if (!input_udev.keyboard_mapping_blocked)
@ -1150,9 +1161,16 @@ static int16_t udev_input_state(void *data,
[RARCH_LIGHTGUN_AUX_C].key) ) [RARCH_LIGHTGUN_AUX_C].key) )
return 1; return 1;
if (binds[port][RARCH_LIGHTGUN_AUX_C].valid) if (binds[port][RARCH_LIGHTGUN_AUX_C].valid)
return udev_is_pressed(udev, udev->joypad, {
joypad_info, binds[port], unsigned new_id = RARCH_LIGHTGUN_AUX_C;
port, RARCH_LIGHTGUN_AUX_C); if (button_is_pressed(udev->joypad,
joypad_info, binds[port],
port, new_id)
|| udev_mouse_button_pressed(udev, port,
binds[port][new_id].mbutton)
)
return 1;
}
break; break;
case RETRO_DEVICE_ID_LIGHTGUN_START: case RETRO_DEVICE_ID_LIGHTGUN_START:
if (!input_udev.keyboard_mapping_blocked) if (!input_udev.keyboard_mapping_blocked)
@ -1161,9 +1179,16 @@ static int16_t udev_input_state(void *data,
[RARCH_LIGHTGUN_START].key) ) [RARCH_LIGHTGUN_START].key) )
return 1; return 1;
if (binds[port][RARCH_LIGHTGUN_START].valid) if (binds[port][RARCH_LIGHTGUN_START].valid)
return udev_is_pressed(udev, udev->joypad, {
joypad_info, binds[port], unsigned new_id = RARCH_LIGHTGUN_START;
port, RARCH_LIGHTGUN_START); if (button_is_pressed(udev->joypad,
joypad_info, binds[port],
port, new_id)
|| udev_mouse_button_pressed(udev, port,
binds[port][new_id].mbutton)
)
return 1;
}
break; break;
case RETRO_DEVICE_ID_LIGHTGUN_SELECT: case RETRO_DEVICE_ID_LIGHTGUN_SELECT:
if (!input_udev.keyboard_mapping_blocked) if (!input_udev.keyboard_mapping_blocked)
@ -1172,9 +1197,16 @@ static int16_t udev_input_state(void *data,
[RARCH_LIGHTGUN_SELECT].key) ) [RARCH_LIGHTGUN_SELECT].key) )
return 1; return 1;
if (binds[port][RARCH_LIGHTGUN_SELECT].valid) if (binds[port][RARCH_LIGHTGUN_SELECT].valid)
return udev_is_pressed(udev, udev->joypad, {
joypad_info, binds[port], unsigned new_id = RARCH_LIGHTGUN_SELECT;
port, RARCH_LIGHTGUN_SELECT); if (button_is_pressed(udev->joypad,
joypad_info, binds[port],
port, new_id)
|| udev_mouse_button_pressed(udev, port,
binds[port][new_id].mbutton)
)
return 1;
}
break; break;
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP: case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP:
if (!input_udev.keyboard_mapping_blocked) if (!input_udev.keyboard_mapping_blocked)
@ -1183,9 +1215,16 @@ static int16_t udev_input_state(void *data,
[RARCH_LIGHTGUN_DPAD_UP].key) ) [RARCH_LIGHTGUN_DPAD_UP].key) )
return 1; return 1;
if (binds[port][RARCH_LIGHTGUN_DPAD_UP].valid) if (binds[port][RARCH_LIGHTGUN_DPAD_UP].valid)
return udev_is_pressed(udev, udev->joypad, {
joypad_info, binds[port], unsigned new_id = RARCH_LIGHTGUN_DPAD_UP;
port, RARCH_LIGHTGUN_DPAD_UP); if (button_is_pressed(udev->joypad,
joypad_info, binds[port],
port, new_id)
|| udev_mouse_button_pressed(udev, port,
binds[port][new_id].mbutton)
)
return 1;
}
break; break;
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN: case RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN:
if (!input_udev.keyboard_mapping_blocked) if (!input_udev.keyboard_mapping_blocked)
@ -1194,9 +1233,16 @@ static int16_t udev_input_state(void *data,
[RARCH_LIGHTGUN_DPAD_DOWN].key) ) [RARCH_LIGHTGUN_DPAD_DOWN].key) )
return 1; return 1;
if (binds[port][RARCH_LIGHTGUN_DPAD_DOWN].valid) if (binds[port][RARCH_LIGHTGUN_DPAD_DOWN].valid)
return udev_is_pressed(udev, udev->joypad, {
joypad_info, binds[port], unsigned new_id = RARCH_LIGHTGUN_DPAD_DOWN;
port, RARCH_LIGHTGUN_DPAD_DOWN); if (button_is_pressed(udev->joypad,
joypad_info, binds[port],
port, new_id)
|| udev_mouse_button_pressed(udev, port,
binds[port][new_id].mbutton)
)
return 1;
}
break; break;
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT: case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT:
if (!input_udev.keyboard_mapping_blocked) if (!input_udev.keyboard_mapping_blocked)
@ -1205,9 +1251,16 @@ static int16_t udev_input_state(void *data,
[RARCH_LIGHTGUN_DPAD_LEFT].key) ) [RARCH_LIGHTGUN_DPAD_LEFT].key) )
return 1; return 1;
if (binds[port][RARCH_LIGHTGUN_DPAD_LEFT].valid) if (binds[port][RARCH_LIGHTGUN_DPAD_LEFT].valid)
return udev_is_pressed(udev, udev->joypad, {
joypad_info, binds[port], unsigned new_id = RARCH_LIGHTGUN_DPAD_LEFT;
port, RARCH_LIGHTGUN_DPAD_LEFT); if (button_is_pressed(udev->joypad,
joypad_info, binds[port],
port, new_id)
|| udev_mouse_button_pressed(udev, port,
binds[port][new_id].mbutton)
)
return 1;
}
break; break;
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT: case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT:
if (!input_udev.keyboard_mapping_blocked) if (!input_udev.keyboard_mapping_blocked)
@ -1216,9 +1269,16 @@ static int16_t udev_input_state(void *data,
[RARCH_LIGHTGUN_DPAD_RIGHT].key) ) [RARCH_LIGHTGUN_DPAD_RIGHT].key) )
return 1; return 1;
if (binds[port][RARCH_LIGHTGUN_DPAD_RIGHT].valid) if (binds[port][RARCH_LIGHTGUN_DPAD_RIGHT].valid)
return udev_is_pressed(udev, udev->joypad, {
joypad_info, binds[port], unsigned new_id = RARCH_LIGHTGUN_DPAD_RIGHT;
port, RARCH_LIGHTGUN_DPAD_RIGHT); if (button_is_pressed(udev->joypad,
joypad_info, binds[port],
port, new_id)
|| udev_mouse_button_pressed(udev, port,
binds[port][new_id].mbutton)
)
return 1;
}
break; break;
/*deprecated*/ /*deprecated*/
@ -1239,9 +1299,14 @@ static int16_t udev_input_state(void *data,
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
if (binds[port][RARCH_LIGHTGUN_START].valid) if (binds[port][RARCH_LIGHTGUN_START].valid)
{ {
return udev_is_pressed(udev, udev->joypad, unsigned new_id = RARCH_LIGHTGUN_START;
joypad_info, if (button_is_pressed(udev->joypad,
binds[port], port, RARCH_LIGHTGUN_START); joypad_info, binds[port],
port, new_id)
|| udev_mouse_button_pressed(udev, port,
binds[port][new_id].mbutton)
)
return 1;
} }
break; break;
} }