Keyboard device mapper rework

This commit is contained in:
sonninnos 2020-12-26 04:44:54 +02:00
parent 9489a1d507
commit 73feffc4d1
2 changed files with 22 additions and 17 deletions

View File

@ -21750,8 +21750,6 @@ static void input_driver_poll(void)
const input_device_driver_t *joypad_driver const input_device_driver_t *joypad_driver
= p_rarch->joypad; = p_rarch->joypad;
memset(handle->keys, 0, sizeof(handle->keys));
for (i = 0; i < max_users; i++) for (i = 0; i < max_users; i++)
{ {
input_bits_t current_inputs; input_bits_t current_inputs;
@ -21833,13 +21831,10 @@ static void input_driver_poll(void)
for (j = 0; j < RARCH_CUSTOM_BIND_LIST_END; j++) for (j = 0; j < RARCH_CUSTOM_BIND_LIST_END; j++)
{ {
unsigned current_button_value; unsigned current_button_value;
unsigned remap_button = unsigned remap_key =
settings->uints.input_keymapper_ids[i][j]; settings->uints.input_keymapper_ids[i][j];
bool remap_valid =
remap_button != RETROK_UNKNOWN &&
!MAPPER_GET_KEY(handle, remap_button);
if (!remap_valid) if (remap_key == RETROK_UNKNOWN)
continue; continue;
current_button_value = current_button_value =
@ -21857,21 +21852,28 @@ static void input_driver_poll(void)
BIT256_GET(ol_state->buttons, j); BIT256_GET(ol_state->buttons, j);
} }
#endif #endif
/* Press */
if ((current_button_value == 1) if ((current_button_value == 1)
&& (j != remap_button)) && !MAPPER_GET_KEY(handle, remap_key))
{ {
MAPPER_SET_KEY (handle, handle->key_button[remap_key] = j;
remap_button); MAPPER_SET_KEY(handle, remap_key);
input_keyboard_event(true, input_keyboard_event(true,
remap_button, remap_key,
0, 0, RETRO_DEVICE_KEYBOARD); 0, 0, RETRO_DEVICE_KEYBOARD);
continue;
} }
/* Release */
else if ((current_button_value == 0)
&& MAPPER_GET_KEY(handle, remap_key))
{
if (handle->key_button[remap_key] != j)
continue;
/* Release keyboard event*/ MAPPER_UNSET_KEY(handle, remap_key);
input_keyboard_event(false, input_keyboard_event(false,
remap_button, remap_key,
0, 0, RETRO_DEVICE_KEYBOARD); 0, 0, RETRO_DEVICE_KEYBOARD);
}
} }
break; break;

View File

@ -274,6 +274,7 @@
#define MAPPER_GET_KEY(state, key) (((state)->keys[(key) / 32] >> ((key) % 32)) & 1) #define MAPPER_GET_KEY(state, key) (((state)->keys[(key) / 32] >> ((key) % 32)) & 1)
#define MAPPER_SET_KEY(state, key) (state)->keys[(key) / 32] |= 1 << ((key) % 32) #define MAPPER_SET_KEY(state, key) (state)->keys[(key) / 32] |= 1 << ((key) % 32)
#define MAPPER_UNSET_KEY(state, key) (state)->keys[(key) / 32] &= ~(1 << ((key) % 32))
#ifdef HAVE_MENU #ifdef HAVE_MENU
@ -1645,8 +1646,10 @@ typedef struct input_mapper
{ {
/* Left X, Left Y, Right X, Right Y */ /* Left X, Left Y, Right X, Right Y */
int16_t analog_value[MAX_USERS][8]; int16_t analog_value[MAX_USERS][8];
/* the whole keyboard state */ /* The whole keyboard state */
uint32_t keys[RETROK_LAST / 32 + 1]; uint32_t keys[RETROK_LAST / 32 + 1];
/* RetroPad button state of remapped keyboard keys */
unsigned key_button[RETROK_LAST];
/* This is a bitmask of (1 << key_bind_id). */ /* This is a bitmask of (1 << key_bind_id). */
input_bits_t buttons[MAX_USERS]; input_bits_t buttons[MAX_USERS];
} input_mapper_t; } input_mapper_t;