diff --git a/configuration.c b/configuration.c index b5bb4572de..572d5375db 100644 --- a/configuration.c +++ b/configuration.c @@ -1775,14 +1775,7 @@ static struct config_uint_setting *populate_settings_uint(settings_t *settings, SETTING_UINT("rgui_particle_effect", &settings->uints.menu_rgui_particle_effect, true, rgui_particle_effect, false); #endif #ifdef HAVE_LIBNX - SETTING_UINT("split_joycon_p1", &settings->uints.input_split_joycon[0], true, 0, false); - SETTING_UINT("split_joycon_p2", &settings->uints.input_split_joycon[1], true, 0, false); - SETTING_UINT("split_joycon_p3", &settings->uints.input_split_joycon[2], true, 0, false); - SETTING_UINT("split_joycon_p4", &settings->uints.input_split_joycon[3], true, 0, false); - SETTING_UINT("split_joycon_p5", &settings->uints.input_split_joycon[4], true, 0, false); - SETTING_UINT("split_joycon_p6", &settings->uints.input_split_joycon[5], true, 0, false); - SETTING_UINT("split_joycon_p7", &settings->uints.input_split_joycon[6], true, 0, false); - SETTING_UINT("split_joycon_p8", &settings->uints.input_split_joycon[7], true, 0, false); + SETTING_UINT("split_joycon", &settings->uints.input_split_joycon, true, 0, false); #endif #ifdef HAVE_XMB SETTING_UINT("menu_xmb_animation_opening_main_menu", &settings->uints.menu_xmb_animation_opening_main_menu, true, 0 /* TODO/FIXME - implement */, false); diff --git a/configuration.h b/configuration.h index 44a1a6de64..5f775a113f 100644 --- a/configuration.h +++ b/configuration.h @@ -543,7 +543,7 @@ typedef struct settings unsigned input_overlay_show_physical_inputs_port; - unsigned input_split_joycon[MAX_USERS]; + unsigned input_split_joycon; unsigned input_joypad_map[MAX_USERS]; unsigned input_device[MAX_USERS]; unsigned input_mouse_index[MAX_USERS]; diff --git a/input/drivers_joypad/switch_joypad.c b/input/drivers_joypad/switch_joypad.c index 60851674f1..2e7cf8f5fa 100644 --- a/input/drivers_joypad/switch_joypad.c +++ b/input/drivers_joypad/switch_joypad.c @@ -29,7 +29,7 @@ static HidVibrationValue vibration_values[DEFAULT_MAX_PADS][2]; static HidVibrationValue vibration_stop; static int previous_handheld = -1; /* 1 = handheld, 0 = docked, -1 = first use */ -static uint previous_split_joycon_setting[MAX_USERS] = { 0 }; +static uint previous_split_joycon_setting = { -1 }; #endif static const char *switch_joypad_name(unsigned pad) @@ -166,8 +166,7 @@ static void switch_joypad_destroy(void) previous_handheld = -1; - for (i = 0; i < MAX_USERS; i++) - previous_split_joycon_setting[i] = 0; + previous_split_joycon_setting = 0; for (i = 0; i < DEFAULT_MAX_PADS; i++) { @@ -185,6 +184,46 @@ static void switch_joypad_destroy(void) #ifdef HAVE_LIBNX +static void switch_split_joycons(void) +{ + unsigned i; + for (i = 0; i < MAX_USERS; i += 2) + { + hidSetNpadJoyAssignmentModeSingleByDefault(i); + hidSetNpadJoyAssignmentModeSingleByDefault(i + 1); + hidSetNpadJoyHoldType(HidJoyHoldType_Horizontal); + } +} + +static void switch_join_joycons(void) +{ + /* find all left/right single JoyCon pairs and join them together */ + int id, id_0, id_1; + int last_right_id = MAX_USERS; + for (id = 0; id < MAX_USERS; id++) + hidSetNpadJoyAssignmentModeDual(id); + + for (id_0 = 0; id_0 < MAX_USERS; id_0++) + { + if (hidGetControllerType(id_0) & TYPE_JOYCON_LEFT) + { + for (id_1 = last_right_id - 1; id_1 >= 0; id_1--) + { + if (hidGetControllerType(id_1) & TYPE_JOYCON_RIGHT) + { + /* prevent missing player numbers */ + last_right_id = id_1; + if (id_0 < id_1) + hidMergeSingleJoyAsDualJoy(id_0, id_1); + else if (id_0 > id_1) + hidMergeSingleJoyAsDualJoy(id_1, id_0); + break; + } + } + } + } +} + static void switch_joypad_poll(void) { int i, handheld; @@ -192,106 +231,49 @@ static void switch_joypad_poll(void) hidScanInput(); + /* handheld means the Switch is neither docked nor in tabletop mode */ + /* e.g. it is used held in hands with both joycons attached */ handheld = hidGetHandheldMode(); if (previous_handheld == -1) { - /* First call of this function, apply joycon settings - * according to preferences, init variables */ - if (!handheld) - { - for (i = 0; i < MAX_USERS; i += 2) - { - if (settings->uints.input_split_joycon[i]) - { - hidSetNpadJoyAssignmentModeSingleByDefault(i); - hidSetNpadJoyAssignmentModeSingleByDefault(i + 1); - hidSetNpadJoyHoldType(HidJoyHoldType_Horizontal); - } - else if (!settings->uints.input_split_joycon[i]) - { - hidSetNpadJoyAssignmentModeDual(i); - hidSetNpadJoyAssignmentModeDual(i + 1); - hidMergeSingleJoyAsDualJoy(i, i + 1); - } - } - } - previous_handheld = handheld; - for (i = 0; i < MAX_USERS; i += 2) - previous_split_joycon_setting[i] = settings->uints.input_split_joycon[i]; + /* first call of this function, apply joycon settings + * according to preferences */ + if (!handheld && settings->uints.input_split_joycon) + switch_split_joycons(); + else + switch_join_joycons(); } - - if (!handheld && previous_handheld) + else { - /* switching out of handheld, so make sure - * joycons are correctly split. */ - for (i = 0; i < MAX_USERS; i += 2) + if (!handheld && previous_handheld) { - /* CONTROLLER_PLAYER_X, X == i++ */ - if (settings->uints.input_split_joycon[i]) + /* switching out of handheld, so make sure + * joycons are correctly split. */ + if (settings->uints.input_split_joycon) + switch_split_joycons(); + } + else if (handheld && !previous_handheld) + { + /* switching into handheld, so make sure all split joycons are joined */ + switch_join_joycons(); + } + else if (!handheld) + { + /* the user might have changed the split joycon setting, so respond */ + if (settings->uints.input_split_joycon && !previous_split_joycon_setting) { - hidSetNpadJoyAssignmentModeSingleByDefault(i); - hidSetNpadJoyAssignmentModeSingleByDefault(i + 1); - hidSetNpadJoyHoldType(HidJoyHoldType_Horizontal); + /* setting changed from unsplit to split, so split them all */ + switch_split_joycons(); + } + else if (!settings->uints.input_split_joycon && previous_split_joycon_setting) + { + /* setting changed from split to unsplit, so join them all */ + switch_join_joycons(); } } } - else if (handheld && !previous_handheld) - { - /* switching into handheld, so make sure all split joycons are joined */ - for (i = 0; i < MAX_USERS; i += 2) - { - /* find all left/right single JoyCon pairs and join them together */ - int id, id_0, id_1; - int last_right_id = MAX_USERS; - for (id = 0; id < MAX_USERS; id++) - hidSetNpadJoyAssignmentModeDual(id); - - for (id_0 = 0; id_0 < MAX_USERS; id_0++) - { - if (hidGetControllerType(id_0) & TYPE_JOYCON_LEFT) - { - for (id_1 = last_right_id - 1; id_1 >= 0; id_1--) - { - if (hidGetControllerType(id_1) & TYPE_JOYCON_RIGHT) - { - /* prevent missing player numbers */ - last_right_id = id_1; - if (id_0 < id_1) - hidMergeSingleJoyAsDualJoy(id_0, id_1); - else if (id_0 > id_1) - hidMergeSingleJoyAsDualJoy(id_1, id_0); - break; - } - } - } - } - } - } - else if (!handheld) - { - /* split or join joycons every time the user changes a setting */ - for (i = 0; i < MAX_USERS; i += 2) - { - if ( settings->uints.input_split_joycon[i] - && !previous_split_joycon_setting[i]) - { - hidSetNpadJoyAssignmentModeSingleByDefault(i); - hidSetNpadJoyAssignmentModeSingleByDefault(i + 1); - hidSetNpadJoyHoldType(HidJoyHoldType_Horizontal); - } - else if (!settings->uints.input_split_joycon[i] - && previous_split_joycon_setting[i]) - { - hidSetNpadJoyAssignmentModeDual(i); - hidSetNpadJoyAssignmentModeDual(i + 1); - hidMergeSingleJoyAsDualJoy(i, i + 1); - } - } - } - - for (i = 0; i < MAX_USERS; i += 2) - previous_split_joycon_setting[i] = settings->uints.input_split_joycon[i]; + previous_split_joycon_setting = settings->uints.input_split_joycon; previous_handheld = handheld; for (i = 0; i < DEFAULT_MAX_PADS; i++) diff --git a/intl/msg_hash_ar.h b/intl/msg_hash_ar.h index e303497e2c..90e2830e67 100644 --- a/intl/msg_hash_ar.h +++ b/intl/msg_hash_ar.h @@ -3728,7 +3728,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE, "Title of Stream") MSG_HASH( MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON, - "Split Joy-Con" + "Split Joy-Cons" ) MSG_HASH( MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG, diff --git a/intl/msg_hash_cht.h b/intl/msg_hash_cht.h index bbf27ff32d..871cdb6121 100644 --- a/intl/msg_hash_cht.h +++ b/intl/msg_hash_cht.h @@ -3504,7 +3504,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE, "串流名稱") MSG_HASH( MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON, - "Split Joy-Con" + "Split Joy-Cons" ) MSG_HASH( MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG, diff --git a/intl/msg_hash_de.h b/intl/msg_hash_de.h index 1a21f5b29f..cb1e2e9a9f 100644 --- a/intl/msg_hash_de.h +++ b/intl/msg_hash_de.h @@ -3633,7 +3633,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE, "Streamtitel") MSG_HASH( MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON, - "Split Joy-Con" + "Split Joy-Cons" ) MSG_HASH( MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG, diff --git a/intl/msg_hash_eo.h b/intl/msg_hash_eo.h index 8cb5caefb0..d84f020992 100644 --- a/intl/msg_hash_eo.h +++ b/intl/msg_hash_eo.h @@ -3392,7 +3392,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE, "Title of Stream") MSG_HASH( MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON, - "Split Joy-Con" + "Split Joy-Cons" ) MSG_HASH( MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG, diff --git a/intl/msg_hash_ja.h b/intl/msg_hash_ja.h index fd7231587e..5a042040e7 100644 --- a/intl/msg_hash_ja.h +++ b/intl/msg_hash_ja.h @@ -8863,7 +8863,7 @@ MSG_HASH( ) MSG_HASH( MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON, - "Split Joy-Con" + "Split Joy-Cons" ) MSG_HASH( MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG, diff --git a/intl/msg_hash_nl.h b/intl/msg_hash_nl.h index b5e3f66148..c597d7d071 100644 --- a/intl/msg_hash_nl.h +++ b/intl/msg_hash_nl.h @@ -3382,7 +3382,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE, "Titel van Stream") MSG_HASH( MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON, - "Split Joy-Con" + "Split Joy-Cons" ) MSG_HASH( MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG, diff --git a/intl/msg_hash_pt_br.h b/intl/msg_hash_pt_br.h index a99b5fb54c..cd66c50846 100644 --- a/intl/msg_hash_pt_br.h +++ b/intl/msg_hash_pt_br.h @@ -8697,7 +8697,7 @@ MSG_HASH( ) MSG_HASH( MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON, - "Split Joy-Con" + "Split Joy-Cons" ) MSG_HASH( MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG, diff --git a/intl/msg_hash_pt_pt.h b/intl/msg_hash_pt_pt.h index 6343264d37..c39bd1dc18 100644 --- a/intl/msg_hash_pt_pt.h +++ b/intl/msg_hash_pt_pt.h @@ -3458,7 +3458,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE, "Title of Stream") MSG_HASH( MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON, - "Split Joy-Con" + "Split Joy-Cons" ) MSG_HASH( MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG, diff --git a/intl/msg_hash_ru.h b/intl/msg_hash_ru.h index 8c8ee89e52..4142c3bbce 100644 --- a/intl/msg_hash_ru.h +++ b/intl/msg_hash_ru.h @@ -3656,7 +3656,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE, "Title of Stream") MSG_HASH( MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON, - "Split Joy-Con" + "Split Joy-Cons" ) MSG_HASH( MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG, diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 14ef4ea7ba..f182479372 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -8761,7 +8761,7 @@ MSG_HASH( ) MSG_HASH( MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON, - "Split Joy-Con" + "Split Joy-Cons" ) MSG_HASH( MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG, diff --git a/intl/msg_hash_vn.h b/intl/msg_hash_vn.h index e2641541eb..2858258708 100644 --- a/intl/msg_hash_vn.h +++ b/intl/msg_hash_vn.h @@ -3546,7 +3546,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE, "Title of Stream") MSG_HASH( MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON, - "Split Joy-Con" + "Split Joy-Cons" ) MSG_HASH( MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG, diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 0be1cce8f1..561d00f3a9 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -3835,23 +3835,17 @@ unsigned menu_displaylist_build_list(file_list_t *list, enum menu_displaylist_ct #ifdef HAVE_LIBNX { - unsigned user; + char key_split_joycon[PATH_MAX_LENGTH]; - for (user = 0; user < 8; user++) - { - char key_split_joycon[PATH_MAX_LENGTH]; - unsigned val = user + 1; + key_split_joycon[0] = '\0'; - key_split_joycon[0] = '\0'; + snprintf(key_split_joycon, sizeof(key_split_joycon), + "%s", + msg_hash_to_str(MENU_ENUM_LABEL_INPUT_SPLIT_JOYCON)); - snprintf(key_split_joycon, sizeof(key_split_joycon), - "%s_%u", - msg_hash_to_str(MENU_ENUM_LABEL_INPUT_SPLIT_JOYCON), val); - - if (menu_displaylist_parse_settings(list, - key_split_joycon, PARSE_ONLY_UINT, true, 0) != -1) - count++; - } + if (menu_displaylist_parse_settings(list, + key_split_joycon, PARSE_ONLY_UINT, true, 0) != -1) + count++; } #endif diff --git a/menu/menu_setting.c b/menu/menu_setting.c index d4c25a6591..a0b8ab0880 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -5763,8 +5763,7 @@ static void get_string_representation_split_joycon(rarch_setting_t *setting, cha size_t len) { settings_t *settings = config_get_ptr(); - unsigned index_offset = setting->index_offset; - unsigned map = settings->uints.input_split_joycon[index_offset]; + unsigned map = settings->uints.input_split_joycon; if (map == 0) strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF), len); @@ -6490,8 +6489,8 @@ static bool setting_append_list_input_player_options( static char key_analog[MAX_USERS][64]; static char key_bind_all[MAX_USERS][64]; static char key_bind_all_save_autoconfig[MAX_USERS][64]; - static char split_joycon[MAX_USERS][64]; - static char split_joycon_lbl[MAX_USERS][64]; + static char split_joycon[64]; + static char split_joycon_lbl[64]; static char key_bind_defaults[MAX_USERS][64]; static char mouse_index[MAX_USERS][64]; @@ -6515,10 +6514,9 @@ static bool setting_append_list_input_player_options( snprintf(key_analog[user], sizeof(key_analog[user]), msg_hash_to_str(MENU_ENUM_LABEL_INPUT_PLAYER_ANALOG_DPAD_MODE), user + 1); - snprintf(split_joycon[user], sizeof(split_joycon[user]), - "%s_%u", - msg_hash_to_str(MENU_ENUM_LABEL_INPUT_SPLIT_JOYCON), - user + 1); + snprintf(split_joycon, sizeof(split_joycon), + "%s", + msg_hash_to_str(MENU_ENUM_LABEL_INPUT_SPLIT_JOYCON)); fill_pathname_join_delim(key_bind_all[user], tmp_string, "bind_all", '_', sizeof(key_bind_all[user])); fill_pathname_join_delim(key_bind_all_save_autoconfig[user], @@ -6530,8 +6528,8 @@ static bool setting_append_list_input_player_options( fill_pathname_join_delim(mouse_index[user], tmp_string, "mouse_index", '_', sizeof(mouse_index[user])); - snprintf(split_joycon_lbl[user], sizeof(label[user]), - "%s %u", msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON), user + 1); + snprintf(split_joycon_lbl, sizeof(label), + "%s", msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON)); snprintf(label[user], sizeof(label[user]), "%s %u %s", msg_hash_to_str(MENU_ENUM_LABEL_VALUE_USER), user + 1, @@ -6604,9 +6602,9 @@ static bool setting_append_list_input_player_options( #ifdef HAVE_LIBNX CONFIG_UINT_ALT( list, list_info, - &settings->uints.input_split_joycon[user], - split_joycon[user], - split_joycon_lbl[user], + &settings->uints.input_split_joycon, + split_joycon, + split_joycon_lbl, user, &group_info, &subgroup_info,