Skip to content

Commit 8c0c0e3

Browse files
committed
[Switch] Really fix splitting/joining JoyCons via single option
1 parent 4a65436 commit 8c0c0e3

16 files changed

+101
-134
lines changed

configuration.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,14 +1775,7 @@ static struct config_uint_setting *populate_settings_uint(settings_t *settings,
17751775
SETTING_UINT("rgui_particle_effect", &settings->uints.menu_rgui_particle_effect, true, rgui_particle_effect, false);
17761776
#endif
17771777
#ifdef HAVE_LIBNX
1778-
SETTING_UINT("split_joycon_p1", &settings->uints.input_split_joycon[0], true, 0, false);
1779-
SETTING_UINT("split_joycon_p2", &settings->uints.input_split_joycon[1], true, 0, false);
1780-
SETTING_UINT("split_joycon_p3", &settings->uints.input_split_joycon[2], true, 0, false);
1781-
SETTING_UINT("split_joycon_p4", &settings->uints.input_split_joycon[3], true, 0, false);
1782-
SETTING_UINT("split_joycon_p5", &settings->uints.input_split_joycon[4], true, 0, false);
1783-
SETTING_UINT("split_joycon_p6", &settings->uints.input_split_joycon[5], true, 0, false);
1784-
SETTING_UINT("split_joycon_p7", &settings->uints.input_split_joycon[6], true, 0, false);
1785-
SETTING_UINT("split_joycon_p8", &settings->uints.input_split_joycon[7], true, 0, false);
1778+
SETTING_UINT("split_joycon", &settings->uints.input_split_joycon, true, 0, false);
17861779
#endif
17871780
#ifdef HAVE_XMB
17881781
SETTING_UINT("menu_xmb_animation_opening_main_menu", &settings->uints.menu_xmb_animation_opening_main_menu, true, 0 /* TODO/FIXME - implement */, false);

configuration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ typedef struct settings
543543

544544
unsigned input_overlay_show_physical_inputs_port;
545545

546-
unsigned input_split_joycon[MAX_USERS];
546+
unsigned input_split_joycon;
547547
unsigned input_joypad_map[MAX_USERS];
548548
unsigned input_device[MAX_USERS];
549549
unsigned input_mouse_index[MAX_USERS];

input/drivers_joypad/switch_joypad.c

Lines changed: 69 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static HidVibrationValue vibration_values[DEFAULT_MAX_PADS][2];
2929
static HidVibrationValue vibration_stop;
3030
static int previous_handheld = -1;
3131
/* 1 = handheld, 0 = docked, -1 = first use */
32-
static uint previous_split_joycon_setting[MAX_USERS] = { 0 };
32+
static uint previous_split_joycon_setting = { -1 };
3333
#endif
3434

3535
static const char *switch_joypad_name(unsigned pad)
@@ -166,8 +166,7 @@ static void switch_joypad_destroy(void)
166166

167167
previous_handheld = -1;
168168

169-
for (i = 0; i < MAX_USERS; i++)
170-
previous_split_joycon_setting[i] = 0;
169+
previous_split_joycon_setting = 0;
171170

172171
for (i = 0; i < DEFAULT_MAX_PADS; i++)
173172
{
@@ -185,113 +184,96 @@ static void switch_joypad_destroy(void)
185184

186185
#ifdef HAVE_LIBNX
187186

188-
static void switch_joypad_poll(void)
187+
static void switch_split_joycons(void)
189188
{
190-
int i, handheld;
191-
settings_t *settings = config_get_ptr();
192-
193-
hidScanInput();
189+
unsigned i;
190+
for (i = 0; i < MAX_USERS; i += 2)
191+
{
192+
hidSetNpadJoyAssignmentModeSingleByDefault(i);
193+
hidSetNpadJoyAssignmentModeSingleByDefault(i + 1);
194+
hidSetNpadJoyHoldType(HidJoyHoldType_Horizontal);
195+
}
196+
}
194197

195-
handheld = hidGetHandheldMode();
198+
static void switch_join_joycons(void)
199+
{
200+
/* find all left/right single JoyCon pairs and join them together */
201+
int id, id_0, id_1;
202+
int last_right_id = MAX_USERS;
203+
for (id = 0; id < MAX_USERS; id++)
204+
hidSetNpadJoyAssignmentModeDual(id);
196205

197-
if (previous_handheld == -1)
206+
for (id_0 = 0; id_0 < MAX_USERS; id_0++)
198207
{
199-
/* First call of this function, apply joycon settings
200-
* according to preferences, init variables */
201-
if (!handheld)
208+
if (hidGetControllerType(id_0) & TYPE_JOYCON_LEFT)
202209
{
203-
for (i = 0; i < MAX_USERS; i += 2)
210+
for (id_1 = last_right_id - 1; id_1 >= 0; id_1--)
204211
{
205-
if (settings->uints.input_split_joycon[i])
206-
{
207-
hidSetNpadJoyAssignmentModeSingleByDefault(i);
208-
hidSetNpadJoyAssignmentModeSingleByDefault(i + 1);
209-
hidSetNpadJoyHoldType(HidJoyHoldType_Horizontal);
210-
}
211-
else if (!settings->uints.input_split_joycon[i])
212+
if (hidGetControllerType(id_1) & TYPE_JOYCON_RIGHT)
212213
{
213-
hidSetNpadJoyAssignmentModeDual(i);
214-
hidSetNpadJoyAssignmentModeDual(i + 1);
215-
hidMergeSingleJoyAsDualJoy(i, i + 1);
214+
/* prevent missing player numbers */
215+
last_right_id = id_1;
216+
if (id_0 < id_1)
217+
hidMergeSingleJoyAsDualJoy(id_0, id_1);
218+
else if (id_0 > id_1)
219+
hidMergeSingleJoyAsDualJoy(id_1, id_0);
220+
break;
216221
}
217222
}
218223
}
219-
previous_handheld = handheld;
220-
for (i = 0; i < MAX_USERS; i += 2)
221-
previous_split_joycon_setting[i] = settings->uints.input_split_joycon[i];
222224
}
225+
}
226+
227+
static void switch_joypad_poll(void)
228+
{
229+
int i, handheld;
230+
settings_t *settings = config_get_ptr();
231+
232+
hidScanInput();
223233

224-
if (!handheld && previous_handheld)
234+
/* handheld means the Switch is neither docked nor in tabletop mode */
235+
/* e.g. it is used held in hands with both joycons attached */
236+
handheld = hidGetHandheldMode();
237+
238+
if (previous_handheld == -1)
225239
{
226-
/* switching out of handheld, so make sure
227-
* joycons are correctly split. */
228-
for (i = 0; i < MAX_USERS; i += 2)
229-
{
230-
/* CONTROLLER_PLAYER_X, X == i++ */
231-
if (settings->uints.input_split_joycon[i])
232-
{
233-
hidSetNpadJoyAssignmentModeSingleByDefault(i);
234-
hidSetNpadJoyAssignmentModeSingleByDefault(i + 1);
235-
hidSetNpadJoyHoldType(HidJoyHoldType_Horizontal);
236-
}
237-
}
240+
/* first call of this function, apply joycon settings
241+
* according to preferences */
242+
if (!handheld && settings->uints.input_split_joycon)
243+
switch_split_joycons();
244+
else
245+
switch_join_joycons();
238246
}
239-
else if (handheld && !previous_handheld)
247+
else
240248
{
241-
/* switching into handheld, so make sure all split joycons are joined */
242-
for (i = 0; i < MAX_USERS; i += 2)
249+
if (!handheld && previous_handheld)
243250
{
244-
/* find all left/right single JoyCon pairs and join them together */
245-
int id, id_0, id_1;
246-
int last_right_id = MAX_USERS;
247-
for (id = 0; id < MAX_USERS; id++)
248-
hidSetNpadJoyAssignmentModeDual(id);
249-
250-
for (id_0 = 0; id_0 < MAX_USERS; id_0++)
251-
{
252-
if (hidGetControllerType(id_0) & TYPE_JOYCON_LEFT)
253-
{
254-
for (id_1 = last_right_id - 1; id_1 >= 0; id_1--)
255-
{
256-
if (hidGetControllerType(id_1) & TYPE_JOYCON_RIGHT)
257-
{
258-
/* prevent missing player numbers */
259-
last_right_id = id_1;
260-
if (id_0 < id_1)
261-
hidMergeSingleJoyAsDualJoy(id_0, id_1);
262-
else if (id_0 > id_1)
263-
hidMergeSingleJoyAsDualJoy(id_1, id_0);
264-
break;
265-
}
266-
}
267-
}
268-
}
251+
/* switching out of handheld, so make sure
252+
* joycons are correctly split. */
253+
if (settings->uints.input_split_joycon)
254+
switch_split_joycons();
269255
}
270-
}
271-
else if (!handheld)
272-
{
273-
/* split or join joycons every time the user changes a setting */
274-
for (i = 0; i < MAX_USERS; i += 2)
256+
else if (handheld && !previous_handheld)
275257
{
276-
if ( settings->uints.input_split_joycon[i]
277-
&& !previous_split_joycon_setting[i])
258+
/* switching into handheld, so make sure all split joycons are joined */
259+
switch_join_joycons();
260+
}
261+
else if (!handheld)
262+
{
263+
/* the user might have changed the split joycon setting, so respond */
264+
if (settings->uints.input_split_joycon && !previous_split_joycon_setting)
278265
{
279-
hidSetNpadJoyAssignmentModeSingleByDefault(i);
280-
hidSetNpadJoyAssignmentModeSingleByDefault(i + 1);
281-
hidSetNpadJoyHoldType(HidJoyHoldType_Horizontal);
282-
}
283-
else if (!settings->uints.input_split_joycon[i]
284-
&& previous_split_joycon_setting[i])
266+
/* setting changed from unsplit to split, so split them all */
267+
switch_split_joycons();
268+
}
269+
else if (!settings->uints.input_split_joycon && previous_split_joycon_setting)
285270
{
286-
hidSetNpadJoyAssignmentModeDual(i);
287-
hidSetNpadJoyAssignmentModeDual(i + 1);
288-
hidMergeSingleJoyAsDualJoy(i, i + 1);
271+
/* setting changed from split to unsplit, so join them all */
272+
switch_join_joycons();
289273
}
290274
}
291275
}
292-
293-
for (i = 0; i < MAX_USERS; i += 2)
294-
previous_split_joycon_setting[i] = settings->uints.input_split_joycon[i];
276+
previous_split_joycon_setting = settings->uints.input_split_joycon;
295277
previous_handheld = handheld;
296278

297279
for (i = 0; i < DEFAULT_MAX_PADS; i++)

intl/msg_hash_ar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3728,7 +3728,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE,
37283728
"Title of Stream")
37293729
MSG_HASH(
37303730
MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON,
3731-
"Split Joy-Con"
3731+
"Split Joy-Cons"
37323732
)
37333733
MSG_HASH(
37343734
MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG,

intl/msg_hash_cht.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3504,7 +3504,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE,
35043504
"串流名稱")
35053505
MSG_HASH(
35063506
MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON,
3507-
"Split Joy-Con"
3507+
"Split Joy-Cons"
35083508
)
35093509
MSG_HASH(
35103510
MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG,

intl/msg_hash_de.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3633,7 +3633,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE,
36333633
"Streamtitel")
36343634
MSG_HASH(
36353635
MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON,
3636-
"Split Joy-Con"
3636+
"Split Joy-Cons"
36373637
)
36383638
MSG_HASH(
36393639
MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG,

intl/msg_hash_eo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3392,7 +3392,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE,
33923392
"Title of Stream")
33933393
MSG_HASH(
33943394
MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON,
3395-
"Split Joy-Con"
3395+
"Split Joy-Cons"
33963396
)
33973397
MSG_HASH(
33983398
MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG,

intl/msg_hash_ja.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8863,7 +8863,7 @@ MSG_HASH(
88638863
)
88648864
MSG_HASH(
88658865
MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON,
8866-
"Split Joy-Con"
8866+
"Split Joy-Cons"
88678867
)
88688868
MSG_HASH(
88698869
MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG,

intl/msg_hash_nl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3382,7 +3382,7 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_STREAMING_TITLE,
33823382
"Titel van Stream")
33833383
MSG_HASH(
33843384
MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON,
3385-
"Split Joy-Con"
3385+
"Split Joy-Cons"
33863386
)
33873387
MSG_HASH(
33883388
MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG,

intl/msg_hash_pt_br.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8697,7 +8697,7 @@ MSG_HASH(
86978697
)
86988698
MSG_HASH(
86998699
MENU_ENUM_LABEL_VALUE_INPUT_SPLIT_JOYCON,
8700-
"Split Joy-Con"
8700+
"Split Joy-Cons"
87018701
)
87028702
MSG_HASH(
87038703
MENU_ENUM_LABEL_VALUE_RESET_TO_DEFAULT_CONFIG,

0 commit comments

Comments
 (0)