Skip to content

Commit

Permalink
Add a configurable workaround for Android reconnecting devices
Browse files Browse the repository at this point in the history
Closes #3414
  • Loading branch information
phcoder committed Feb 21, 2022
1 parent c292275 commit 07af575
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 2 deletions.
4 changes: 4 additions & 0 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -2008,6 +2008,10 @@ static struct config_bool_setting *populate_settings_bool(
SETTING_BOOL("wifi_enabled", &settings->bools.wifi_enabled, true, DEFAULT_WIFI_ENABLE, false);
SETTING_BOOL("gamemode_enable", &settings->bools.gamemode_enable, true, DEFAULT_GAMEMODE_ENABLE, false);

#ifdef ANDROID
SETTING_BOOL("android_input_disconnect_workaround", &settings->bools.android_input_disconnect_workaround, true, false, false);
#endif

*size = count;

return tmp;
Expand Down
4 changes: 4 additions & 0 deletions configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,10 @@ typedef struct settings
bool ai_service_pause;

bool gamemode_enable;

#ifdef ANDROID
bool android_input_disconnect_workaround;
#endif
} bools;

} settings_t;
Expand Down
24 changes: 22 additions & 2 deletions input/drivers/android_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,6 @@ static int android_input_get_id_port(android_input_t *android, int id,
return ret;
}

#ifdef HAVE_DYNAMIC
/* Returns the index inside android->pad_state */
static int android_input_get_id_index_from_name(android_input_t *android,
const char *name)
Expand All @@ -852,7 +851,25 @@ static int android_input_get_id_index_from_name(android_input_t *android,

return -1;
}
#endif

static int android_input_recover_port(android_input_t *android, int id)
{
char device_name[256] = { 0 };
int vendorId = 0;
int productId = 0;
settings_t *settings = config_get_ptr();

if (!settings->bools.android_input_disconnect_workaround)
return -1;
if (!engine_lookup_name(device_name, &vendorId,
&productId, sizeof(device_name), id))
return -1;
int ret = android_input_get_id_index_from_name(android, device_name);
if (ret >= 0)
android->pad_states[ret].id = id;
return ret;
}


static void handle_hotplug(android_input_t *android,
struct android_app *android_app, int *port, int id,
Expand Down Expand Up @@ -1195,6 +1212,9 @@ static void android_input_poll_input(android_input_t *android,
int id = android_input_get_id(event);
int port = android_input_get_id_port(android, id, source);

if (port < 0 && !android_is_keyboard_id(id))
port = android_input_recover_port(android, id);

if (port < 0 && !android_is_keyboard_id(id))
handle_hotplug(android, android_app,
&port, id, source);
Expand Down
9 changes: 9 additions & 0 deletions intl/msg_hash_us.h
Original file line number Diff line number Diff line change
Expand Up @@ -2456,6 +2456,15 @@ MSG_HASH(
"Allow any user to control the menu. If disabled, only User 1 can control the menu."
)

MSG_HASH(
MENU_ENUM_LABEL_VALUE_ANDROID_INPUT_DISCONNECT_WORKAROUND,
"Android disconnect workaround"
)
MSG_HASH(
MENU_ENUM_LABEL_ANDROID_INPUT_DISCONNECT_WORKAROUND,
"Workaround for controllers disconnecting and reconnecting. Impedes 2 players with the identical controllers."
)

/* Settings > Input > Hotkeys */

MSG_HASH(
Expand Down
1 change: 1 addition & 0 deletions menu/cbs/menu_cbs_sublabel.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_nowinkey_enable, MENU_
#endif
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_sensors_enable, MENU_ENUM_SUBLABEL_INPUT_SENSORS_ENABLE)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_auto_mouse_grab, MENU_ENUM_SUBLABEL_INPUT_AUTO_MOUSE_GRAB)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_android_input_disconnect_workaround, MENU_ENUM_SUBLABEL_ANDROID_INPUT_DISCONNECT_WORKAROUND)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_auto_game_focus, MENU_ENUM_SUBLABEL_INPUT_AUTO_GAME_FOCUS)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_swap_ok_cancel, MENU_ENUM_SUBLABEL_MENU_INPUT_SWAP_OK_CANCEL)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_pause_libretro, MENU_ENUM_SUBLABEL_PAUSE_LIBRETRO)
Expand Down
6 changes: 6 additions & 0 deletions menu/menu_displaylist.c
Original file line number Diff line number Diff line change
Expand Up @@ -6525,6 +6525,12 @@ unsigned menu_displaylist_build_list(
MENU_ENUM_LABEL_INPUT_AUTO_MOUSE_GRAB,
PARSE_ONLY_BOOL, false) == 0)
count++;
#ifdef ANDROID
if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list,
MENU_ENUM_LABEL_ANDROID_INPUT_DISCONNECT_WORKAROUND,
PARSE_ONLY_BOOL, false) == 0)
count++;
#endif
if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list,
MENU_ENUM_LABEL_INPUT_AUTO_GAME_FOCUS,
PARSE_ONLY_UINT, false) == 0)
Expand Down
18 changes: 18 additions & 0 deletions menu/menu_setting.c
Original file line number Diff line number Diff line change
Expand Up @@ -13406,6 +13406,24 @@ static bool setting_append_list(
SD_FLAG_NONE
);

#ifdef ANDROID
CONFIG_BOOL(
list, list_info,
&settings->bools.android_input_disconnect_workaround,
MENU_ENUM_LABEL_ANDROID_INPUT_DISCONNECT_WORKAROUND,
MENU_ENUM_LABEL_VALUE_ANDROID_INPUT_DISCONNECT_WORKAROUND,
false,
MENU_ENUM_LABEL_VALUE_OFF,
MENU_ENUM_LABEL_VALUE_ON,
&group_info,
&subgroup_info,
parent_group,
general_write_handler,
general_read_handler,
SD_FLAG_NONE
);
#endif

CONFIG_UINT(
list, list_info,
&settings->uints.input_auto_game_focus,
Expand Down
2 changes: 2 additions & 0 deletions msg_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,8 @@ enum msg_hash_enums
MENU_LABEL(QUIT_PRESS_TWICE),
MENU_LABEL(QUIT_ON_CLOSE_CONTENT),

MENU_LABEL(ANDROID_INPUT_DISCONNECT_WORKAROUND),

MENU_ENUM_LABEL_VALUE_QUIT_ON_CLOSE_CONTENT_DISABLED,
MENU_ENUM_LABEL_VALUE_QUIT_ON_CLOSE_CONTENT_ENABLED,
MENU_ENUM_LABEL_VALUE_QUIT_ON_CLOSE_CONTENT_CLI,
Expand Down

0 comments on commit 07af575

Please sign in to comment.