Skip to content

Commit

Permalink
Refactor based on PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickStankard committed Apr 17, 2024
1 parent d4ab202 commit d6adef8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 55 deletions.
25 changes: 9 additions & 16 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -1511,22 +1511,15 @@ static struct config_array_setting *populate_settings_array(
SETTING_ARRAY("input_android_physical_keyboard", settings->arrays.input_android_physical_keyboard, false, NULL, true);
#endif

SETTING_ARRAY("input_player1_reserved_device", settings->arrays.input_player1_reserved_device, false, NULL, true);
SETTING_ARRAY("input_player2_reserved_device", settings->arrays.input_player2_reserved_device, false, NULL, true);
SETTING_ARRAY("input_player3_reserved_device", settings->arrays.input_player3_reserved_device, false, NULL, true);
SETTING_ARRAY("input_player4_reserved_device", settings->arrays.input_player4_reserved_device, false, NULL, true);
SETTING_ARRAY("input_player5_reserved_device", settings->arrays.input_player5_reserved_device, false, NULL, true);
SETTING_ARRAY("input_player6_reserved_device", settings->arrays.input_player6_reserved_device, false, NULL, true);
SETTING_ARRAY("input_player7_reserved_device", settings->arrays.input_player7_reserved_device, false, NULL, true);
SETTING_ARRAY("input_player8_reserved_device", settings->arrays.input_player8_reserved_device, false, NULL, true);
SETTING_ARRAY("input_player9_reserved_device", settings->arrays.input_player9_reserved_device, false, NULL, true);
SETTING_ARRAY("input_player10_reserved_device", settings->arrays.input_player10_reserved_device, false, NULL, true);
SETTING_ARRAY("input_player11_reserved_device", settings->arrays.input_player11_reserved_device, false, NULL, true);
SETTING_ARRAY("input_player12_reserved_device", settings->arrays.input_player12_reserved_device, false, NULL, true);
SETTING_ARRAY("input_player13_reserved_device", settings->arrays.input_player13_reserved_device, false, NULL, true);
SETTING_ARRAY("input_player14_reserved_device", settings->arrays.input_player14_reserved_device, false, NULL, true);
SETTING_ARRAY("input_player15_reserved_device", settings->arrays.input_player15_reserved_device, false, NULL, true);
SETTING_ARRAY("input_player16_reserved_device", settings->arrays.input_player16_reserved_device, false, NULL, true);
unsigned i;
char _tmp[64];
size_t _len = strlcpy(_tmp, "input_reserved_device_p", sizeof(_tmp));
for (i = 0; i < MAX_USERS; i++)
{
snprintf(_tmp + _len, sizeof(_tmp) - _len, "%u", i + 1);

SETTING_ARRAY(_tmp, settings->arrays.input_reserved_devices[i], false, NULL, true);
}

#ifdef HAVE_MENU
SETTING_ARRAY("menu_driver", settings->arrays.menu_driver, false, NULL, true);
Expand Down
17 changes: 1 addition & 16 deletions configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,22 +476,7 @@ typedef struct settings
char input_android_physical_keyboard[255];
#endif

char input_player1_reserved_device[255];
char input_player2_reserved_device[255];
char input_player3_reserved_device[255];
char input_player4_reserved_device[255];
char input_player5_reserved_device[255];
char input_player6_reserved_device[255];
char input_player7_reserved_device[255];
char input_player8_reserved_device[255];
char input_player9_reserved_device[255];
char input_player10_reserved_device[255];
char input_player11_reserved_device[255];
char input_player12_reserved_device[255];
char input_player13_reserved_device[255];
char input_player14_reserved_device[255];
char input_player15_reserved_device[255];
char input_player16_reserved_device[255];
char input_reserved_devices[MAX_USERS][255];

char audio_device[255];
char camera_device[255];
Expand Down
3 changes: 1 addition & 2 deletions input/drivers/android_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -1398,9 +1398,8 @@ static void handle_hotplug(android_input_t *android,
reserved_port = input_device_get_reserved_port(
vendorId, productId, device_name);

if (reserved_port > -1) {
if (reserved_port > -1)
*port = reserved_port;
}

if (*port < 0)
*port = android->pads_connected;
Expand Down
22 changes: 1 addition & 21 deletions input/input_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -7297,32 +7297,14 @@ static int input_device_get_reserved_port(int vendor_id,

int port;
bool is_reserved;
char settings_key[256];
char settings_value[256];
int settings_value_vendor_id;
int settings_value_product_id;
char settings_value_device_name[256];
char *settings_values[MAX_USERS];
settings_values[0] = settings->arrays.input_player1_reserved_device;
settings_values[1] = settings->arrays.input_player2_reserved_device;
settings_values[2] = settings->arrays.input_player3_reserved_device;
settings_values[3] = settings->arrays.input_player4_reserved_device;
settings_values[4] = settings->arrays.input_player5_reserved_device;
settings_values[5] = settings->arrays.input_player6_reserved_device;
settings_values[6] = settings->arrays.input_player7_reserved_device;
settings_values[7] = settings->arrays.input_player8_reserved_device;
settings_values[8] = settings->arrays.input_player9_reserved_device;
settings_values[9] = settings->arrays.input_player10_reserved_device;
settings_values[10] = settings->arrays.input_player11_reserved_device;
settings_values[11] = settings->arrays.input_player12_reserved_device;
settings_values[12] = settings->arrays.input_player13_reserved_device;
settings_values[13] = settings->arrays.input_player14_reserved_device;
settings_values[14] = settings->arrays.input_player15_reserved_device;
settings_values[15] = settings->arrays.input_player16_reserved_device;

for (port = 0; port < MAX_USERS; port++)
{
strlcpy(settings_value, settings_values[port], sizeof(settings_value));
strlcpy(settings_value, settings->arrays.input_reserved_devices[port], sizeof(settings_value));

if (!string_is_empty(settings_value))
{
Expand All @@ -7332,9 +7314,7 @@ static int input_device_get_reserved_port(int vendor_id,
is_reserved = string_is_equal(device_name, settings_value_device_name);
}
else
{
is_reserved = (vendor_id == settings_value_vendor_id && product_id == settings_value_product_id);
}

if (is_reserved)
{
Expand Down

0 comments on commit d6adef8

Please sign in to comment.