Skip to content

Commit

Permalink
Don't make device reservation specific to Android
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickStankard committed Feb 21, 2024
1 parent 395607c commit 7976bac
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 86 deletions.
33 changes: 17 additions & 16 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -1509,24 +1509,25 @@ static struct config_array_setting *populate_settings_array(
SETTING_ARRAY("input_keyboard_layout", settings->arrays.input_keyboard_layout, false, NULL, true);
#ifdef ANDROID
SETTING_ARRAY("input_android_physical_keyboard", settings->arrays.input_android_physical_keyboard, false, NULL, true);
SETTING_ARRAY("input_android_player1_reserved_device", settings->arrays.input_android_player1_reserved_device, false, NULL, true);
SETTING_ARRAY("input_android_player2_reserved_device", settings->arrays.input_android_player2_reserved_device, false, NULL, true);
SETTING_ARRAY("input_android_player3_reserved_device", settings->arrays.input_android_player3_reserved_device, false, NULL, true);
SETTING_ARRAY("input_android_player4_reserved_device", settings->arrays.input_android_player4_reserved_device, false, NULL, true);
SETTING_ARRAY("input_android_player5_reserved_device", settings->arrays.input_android_player5_reserved_device, false, NULL, true);
SETTING_ARRAY("input_android_player6_reserved_device", settings->arrays.input_android_player6_reserved_device, false, NULL, true);
SETTING_ARRAY("input_android_player7_reserved_device", settings->arrays.input_android_player7_reserved_device, false, NULL, true);
SETTING_ARRAY("input_android_player8_reserved_device", settings->arrays.input_android_player8_reserved_device, false, NULL, true);
SETTING_ARRAY("input_android_player9_reserved_device", settings->arrays.input_android_player9_reserved_device, false, NULL, true);
SETTING_ARRAY("input_android_player10_reserved_device", settings->arrays.input_android_player10_reserved_device, false, NULL, true);
SETTING_ARRAY("input_android_player11_reserved_device", settings->arrays.input_android_player11_reserved_device, false, NULL, true);
SETTING_ARRAY("input_android_player12_reserved_device", settings->arrays.input_android_player12_reserved_device, false, NULL, true);
SETTING_ARRAY("input_android_player13_reserved_device", settings->arrays.input_android_player13_reserved_device, false, NULL, true);
SETTING_ARRAY("input_android_player14_reserved_device", settings->arrays.input_android_player14_reserved_device, false, NULL, true);
SETTING_ARRAY("input_android_player15_reserved_device", settings->arrays.input_android_player15_reserved_device, false, NULL, true);
SETTING_ARRAY("input_android_player16_reserved_device", settings->arrays.input_android_player16_reserved_device, 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);

#ifdef HAVE_MENU
SETTING_ARRAY("menu_driver", settings->arrays.menu_driver, false, NULL, true);
#endif
Expand Down
33 changes: 17 additions & 16 deletions configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,24 +465,25 @@ typedef struct settings

#ifdef ANDROID
char input_android_physical_keyboard[255];
char input_android_player1_reserved_device[255];
char input_android_player2_reserved_device[255];
char input_android_player3_reserved_device[255];
char input_android_player4_reserved_device[255];
char input_android_player5_reserved_device[255];
char input_android_player6_reserved_device[255];
char input_android_player7_reserved_device[255];
char input_android_player8_reserved_device[255];
char input_android_player9_reserved_device[255];
char input_android_player10_reserved_device[255];
char input_android_player11_reserved_device[255];
char input_android_player12_reserved_device[255];
char input_android_player13_reserved_device[255];
char input_android_player14_reserved_device[255];
char input_android_player15_reserved_device[255];
char input_android_player16_reserved_device[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 audio_device[255];
char camera_device[255];
char netplay_mitm_server[255];
Expand Down
55 changes: 1 addition & 54 deletions input/drivers/android_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,59 +1014,6 @@ static int android_input_recover_port(android_input_t *android, int id)
return ret;
}

static int android_input_get_reserved_device_port(int vendor_id, int product_id, const char *device_name)
{
settings_t *settings = config_get_ptr();

int i;
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->arrays.input_android_player1_reserved_device,
settings->arrays.input_android_player2_reserved_device,
settings->arrays.input_android_player3_reserved_device,
settings->arrays.input_android_player4_reserved_device,
settings->arrays.input_android_player5_reserved_device,
settings->arrays.input_android_player6_reserved_device,
settings->arrays.input_android_player7_reserved_device,
settings->arrays.input_android_player8_reserved_device,
settings->arrays.input_android_player9_reserved_device,
settings->arrays.input_android_player10_reserved_device,
settings->arrays.input_android_player11_reserved_device,
settings->arrays.input_android_player12_reserved_device,
settings->arrays.input_android_player13_reserved_device,
settings->arrays.input_android_player14_reserved_device,
settings->arrays.input_android_player15_reserved_device,
settings->arrays.input_android_player16_reserved_device,
};

for (i = 0; i < MAX_USERS; i++)
{
strlcpy(settings_value, settings_values[i], sizeof(settings_value));

if (!string_is_empty(settings_value))
{
if (sscanf(settings_value, "%04x:%04x ", &settings_value_vendor_id, &settings_value_product_id) != 2)
{
strlcpy(settings_value_device_name, settings_value, sizeof(settings_value_device_name));
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) return i;
}
}

return -1;
}

static bool is_configured_as_physical_keyboard(int vendor_id, int product_id, const char *device_name)
{
bool is_keyboard;
Expand Down Expand Up @@ -1420,7 +1367,7 @@ static void handle_hotplug(android_input_t *android,
else if (strstr(android_app->current_ime, "com.hexad.bluezime"))
strlcpy(name_buf, android_app->current_ime, sizeof(name_buf));

reserved_port = android_input_get_reserved_device_port(
reserved_port = input_device_get_reserved_port(
vendorId, productId, device_name);

if (reserved_port > -1) {
Expand Down
59 changes: 59 additions & 0 deletions input/input_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -6750,3 +6750,62 @@ void input_keyboard_event(bool down, unsigned code,
}
}
}

static int input_device_get_reserved_port(int vendor_id,
int product_id, const char *device_name)
{
settings_t *settings = config_get_ptr();

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->arrays.input_player1_reserved_device,
settings->arrays.input_player2_reserved_device,
settings->arrays.input_player3_reserved_device,
settings->arrays.input_player4_reserved_device,
settings->arrays.input_player5_reserved_device,
settings->arrays.input_player6_reserved_device,
settings->arrays.input_player7_reserved_device,
settings->arrays.input_player8_reserved_device,
settings->arrays.input_player9_reserved_device,
settings->arrays.input_player10_reserved_device,
settings->arrays.input_player11_reserved_device,
settings->arrays.input_player12_reserved_device,
settings->arrays.input_player13_reserved_device,
settings->arrays.input_player14_reserved_device,
settings->arrays.input_player15_reserved_device,
settings->arrays.input_player16_reserved_device,
};

for (port = 0; port < MAX_USERS; port++)
{
strlcpy(settings_value, settings_values[port], sizeof(settings_value));

if (!string_is_empty(settings_value))
{
if (sscanf(settings_value, "%04x:%04x ", &settings_value_vendor_id, &settings_value_product_id) != 2)
{
strlcpy(settings_value_device_name, settings_value, sizeof(settings_value_device_name));
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)
{
RARCH_LOG("[Input]: Device \"%s\" (%d:%d) is reserved for port %d.\n",
device_name, vendor_id, product_id, port);
return port;
}
}
}

return -1;
}

0 comments on commit 7976bac

Please sign in to comment.