Skip to content

Commit 4950dee

Browse files
committed
Merge pull request godotengine#104726 from Meorge/bugfix/reversed-buttons-do-not-spark-joy-con
Fix Apple's incorrect mapping of Joy-Con (L) and Joy-Con (R) face buttons
2 parents e8b56aa + 722b412 commit 4950dee

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

drivers/apple/joypad_apple.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ struct GameController {
4646
RumbleContext *rumble_context API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) = nil;
4747
NSInteger ff_effect_timestamp = 0;
4848
bool force_feedback = false;
49-
bool nintendo_button_layout = false;
49+
bool double_nintendo_joycon_layout = false;
50+
bool single_nintendo_joycon_layout = false;
5051

5152
bool axis_changed[(int)JoyAxis::MAX];
5253
double axis_value[(int)JoyAxis::MAX];

drivers/apple/joypad_apple.mm

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ void play_strong_pattern(CHHapticPattern *p_pattern) {
151151

152152
if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) {
153153
if ([controller.productCategory isEqualToString:@"Switch Pro Controller"] || [controller.productCategory isEqualToString:@"Nintendo Switch Joy-Con (L/R)"]) {
154-
nintendo_button_layout = true;
154+
double_nintendo_joycon_layout = true;
155+
}
156+
157+
if ([controller.productCategory isEqualToString:@"Nintendo Switch Joy-Con (L)"] || [controller.productCategory isEqualToString:@"Nintendo Switch Joy-Con (R)"]) {
158+
single_nintendo_joycon_layout = true;
155159
}
156160
}
157161

@@ -207,7 +211,7 @@ void play_strong_pattern(CHHapticPattern *p_pattern) {
207211
GCControllerButtonInput *buttonB = profile.buttons[GCInputButtonB];
208212
GCControllerButtonInput *buttonX = profile.buttons[GCInputButtonX];
209213
GCControllerButtonInput *buttonY = profile.buttons[GCInputButtonY];
210-
if (nintendo_button_layout) {
214+
if (double_nintendo_joycon_layout) {
211215
if (buttonA) {
212216
buttonA.pressedChangedHandler = BUTTON(JoyButton::B);
213217
}
@@ -220,6 +224,19 @@ void play_strong_pattern(CHHapticPattern *p_pattern) {
220224
if (buttonY) {
221225
buttonY.pressedChangedHandler = BUTTON(JoyButton::X);
222226
}
227+
} else if (single_nintendo_joycon_layout) {
228+
if (buttonA) {
229+
buttonA.pressedChangedHandler = BUTTON(JoyButton::A);
230+
}
231+
if (buttonB) {
232+
buttonB.pressedChangedHandler = BUTTON(JoyButton::X);
233+
}
234+
if (buttonX) {
235+
buttonX.pressedChangedHandler = BUTTON(JoyButton::B);
236+
}
237+
if (buttonY) {
238+
buttonY.pressedChangedHandler = BUTTON(JoyButton::Y);
239+
}
223240
} else {
224241
if (buttonA) {
225242
buttonA.pressedChangedHandler = BUTTON(JoyButton::A);
@@ -326,11 +343,16 @@ void play_strong_pattern(CHHapticPattern *p_pattern) {
326343
} else if (controller.extendedGamepad != nil) {
327344
GCExtendedGamepad *gamepad = controller.extendedGamepad;
328345

329-
if (nintendo_button_layout) {
346+
if (double_nintendo_joycon_layout) {
330347
gamepad.buttonA.pressedChangedHandler = BUTTON(JoyButton::B);
331348
gamepad.buttonB.pressedChangedHandler = BUTTON(JoyButton::A);
332349
gamepad.buttonX.pressedChangedHandler = BUTTON(JoyButton::Y);
333350
gamepad.buttonY.pressedChangedHandler = BUTTON(JoyButton::X);
351+
} else if (single_nintendo_joycon_layout) {
352+
gamepad.buttonA.pressedChangedHandler = BUTTON(JoyButton::A);
353+
gamepad.buttonB.pressedChangedHandler = BUTTON(JoyButton::X);
354+
gamepad.buttonX.pressedChangedHandler = BUTTON(JoyButton::B);
355+
gamepad.buttonY.pressedChangedHandler = BUTTON(JoyButton::Y);
334356
} else {
335357
gamepad.buttonA.pressedChangedHandler = BUTTON(JoyButton::A);
336358
gamepad.buttonB.pressedChangedHandler = BUTTON(JoyButton::B);

0 commit comments

Comments
 (0)