Skip to content

Commit

Permalink
Enable also alternative device names (#17412)
Browse files Browse the repository at this point in the history
Enable input_device_device_display_name to also have alt_ variants.
Tests updated.
  • Loading branch information
zoltanvb authored Jan 14, 2025
1 parent 0bb0077 commit 3153443
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
41 changes: 30 additions & 11 deletions tasks/task_autodetect.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ static void input_autoconfigure_free(retro_task_t *task)
* 'affinity' between the connected input
* device and the specified config file
* > 0: No match
* > 2: Device name matches
* > 3: VID+PID match
* > 5: Both device name and VID+PID match */
* > 20-29: Device name matches
* > 30-39: VID+PID match
* > 50-59: Both device name and VID+PID match */
static unsigned input_autoconfigure_get_config_file_affinity(
autoconfig_handle_t *autoconfig_handle,
config_file_t *config)
Expand Down Expand Up @@ -172,7 +172,7 @@ static unsigned input_autoconfigure_get_config_file_affinity(
#endif

if (pid_match)
affinity += 3;
affinity += 30;

/* Check for matching device name */
_len = strlcpy(config_key, "input_device",
Expand All @@ -183,7 +183,11 @@ static unsigned input_autoconfigure_get_config_file_affinity(
&& !string_is_empty(entry->value)
&& string_is_equal(entry->value,
autoconfig_handle->device_info.name))
affinity += 2;
affinity += 20;

/* Store the selected alternative as last digit of affinity. */
if (affinity > 0)
affinity += i;

if (max_affinity < affinity)
max_affinity = affinity;
Expand All @@ -196,9 +200,12 @@ static unsigned input_autoconfigure_get_config_file_affinity(
* handle, parsing required device info metadata */
static void input_autoconfigure_set_config_file(
autoconfig_handle_t *autoconfig_handle,
config_file_t *config)
config_file_t *config, unsigned alternative)
{
struct config_entry_list *entry = NULL;
char config_key[32] = {0};
char config_key_postfix[7] = {0};
size_t _len;

/* Attach config file */
autoconfig_handle->autoconfig_file = config;
Expand All @@ -214,7 +221,17 @@ static void input_autoconfigure_set_config_file(
}

/* Read device display name */
if ( (entry = config_get_entry(config, "input_device_display_name"))
if (alternative > 0)
snprintf(config_key_postfix, sizeof(config_key_postfix),
"_alt%d",alternative);

/* Parse config file */
_len = strlcpy(config_key, "input_device_display_name",
sizeof(config_key));
_len += strlcpy(config_key + _len, config_key_postfix,
sizeof(config_key) - _len);

if ( (entry = config_get_entry(config, config_key))
&& !string_is_empty(entry->value))
strlcpy(autoconfig_handle->device_info.display_name,
entry->value,
Expand Down Expand Up @@ -299,9 +316,9 @@ static bool input_autoconfigure_scan_config_files_external(
config = NULL;
max_affinity = affinity;

/* An affinity of 5 is a 'perfect' match,
/* An affinity of 5x is a 'perfect' match,
* and means we can return immediately */
if (affinity == 5)
if (affinity >= 50)
break;
}
/* No match - just clean up config file */
Expand All @@ -318,7 +335,8 @@ static bool input_autoconfigure_scan_config_files_external(
{
if (autoconfig_handle && best_config)
input_autoconfigure_set_config_file(
autoconfig_handle, best_config);
autoconfig_handle, best_config,
max_affinity % 10);
match_found = true;
}

Expand Down Expand Up @@ -372,7 +390,8 @@ static bool input_autoconfigure_scan_config_files_internal(
{
if (autoconfig_handle && config)
input_autoconfigure_set_config_file(
autoconfig_handle, config);
autoconfig_handle, config,
affinity % 10);
return true;
}

Expand Down
5 changes: 3 additions & 2 deletions tests-other/autoconf/TestpadD_alternative.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ input_device = "Test joypad device D"
input_vendor_id = 1
input_product_id = 2
input_device_alt1 = "Test joypad device E"
input_device_alt8 = "Test joypad device F"
input_device_display_name_alt1 = "Test joypad device name E"
input_device_alt8 = "Test joypad dev F"
input_vendor_id_alt8 = 21
input_product_id_alt8 = 22
input_device_display_name = "Test joypad device D/E/F"
input_device_display_name = "Test joypad device name D"
input_b_btn = "0"
input_y_btn = "1"
input_select_btn = "2"
Expand Down
2 changes: 1 addition & 1 deletion tests-other/testinput_alternative_autoconfig.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# - A device is connected with autoconfig profile
# - A second device is connected which matches autoconfig profile alt1
# - A third device is connected which matches autoconfig profile alt8 (only by vid/pid)
# - VALIDATE: check that Player 1..3 have "Test joypad D/E/F" configured
# - VALIDATE: check that Player 1..3 have "Test joypad D/E/X" configured

input_joypad_driver = "test"
test_input_file_joypad = "tests-other/test_input_joypad_alternative_autoconfig.ratst"
Expand Down

0 comments on commit 3153443

Please sign in to comment.