Browse Source

Merge pull request #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
Thaddeus Crews 5 months ago
parent
commit
4950deeea0
2 changed files with 27 additions and 4 deletions
  1. 2 1
      drivers/apple/joypad_apple.h
  2. 25 3
      drivers/apple/joypad_apple.mm

+ 2 - 1
drivers/apple/joypad_apple.h

@@ -46,7 +46,8 @@ struct GameController {
 	RumbleContext *rumble_context API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) = nil;
 	NSInteger ff_effect_timestamp = 0;
 	bool force_feedback = false;
-	bool nintendo_button_layout = false;
+	bool double_nintendo_joycon_layout = false;
+	bool single_nintendo_joycon_layout = false;
 
 	bool axis_changed[(int)JoyAxis::MAX];
 	double axis_value[(int)JoyAxis::MAX];

+ 25 - 3
drivers/apple/joypad_apple.mm

@@ -151,7 +151,11 @@ GameController::GameController(int p_joy_id, GCController *p_controller) :
 
 	if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) {
 		if ([controller.productCategory isEqualToString:@"Switch Pro Controller"] || [controller.productCategory isEqualToString:@"Nintendo Switch Joy-Con (L/R)"]) {
-			nintendo_button_layout = true;
+			double_nintendo_joycon_layout = true;
+		}
+
+		if ([controller.productCategory isEqualToString:@"Nintendo Switch Joy-Con (L)"] || [controller.productCategory isEqualToString:@"Nintendo Switch Joy-Con (R)"]) {
+			single_nintendo_joycon_layout = true;
 		}
 	}
 
@@ -207,7 +211,7 @@ GameController::GameController(int p_joy_id, GCController *p_controller) :
 			GCControllerButtonInput *buttonB = profile.buttons[GCInputButtonB];
 			GCControllerButtonInput *buttonX = profile.buttons[GCInputButtonX];
 			GCControllerButtonInput *buttonY = profile.buttons[GCInputButtonY];
-			if (nintendo_button_layout) {
+			if (double_nintendo_joycon_layout) {
 				if (buttonA) {
 					buttonA.pressedChangedHandler = BUTTON(JoyButton::B);
 				}
@@ -220,6 +224,19 @@ GameController::GameController(int p_joy_id, GCController *p_controller) :
 				if (buttonY) {
 					buttonY.pressedChangedHandler = BUTTON(JoyButton::X);
 				}
+			} else if (single_nintendo_joycon_layout) {
+				if (buttonA) {
+					buttonA.pressedChangedHandler = BUTTON(JoyButton::A);
+				}
+				if (buttonB) {
+					buttonB.pressedChangedHandler = BUTTON(JoyButton::X);
+				}
+				if (buttonX) {
+					buttonX.pressedChangedHandler = BUTTON(JoyButton::B);
+				}
+				if (buttonY) {
+					buttonY.pressedChangedHandler = BUTTON(JoyButton::Y);
+				}
 			} else {
 				if (buttonA) {
 					buttonA.pressedChangedHandler = BUTTON(JoyButton::A);
@@ -326,11 +343,16 @@ GameController::GameController(int p_joy_id, GCController *p_controller) :
 	} else if (controller.extendedGamepad != nil) {
 		GCExtendedGamepad *gamepad = controller.extendedGamepad;
 
-		if (nintendo_button_layout) {
+		if (double_nintendo_joycon_layout) {
 			gamepad.buttonA.pressedChangedHandler = BUTTON(JoyButton::B);
 			gamepad.buttonB.pressedChangedHandler = BUTTON(JoyButton::A);
 			gamepad.buttonX.pressedChangedHandler = BUTTON(JoyButton::Y);
 			gamepad.buttonY.pressedChangedHandler = BUTTON(JoyButton::X);
+		} else if (single_nintendo_joycon_layout) {
+			gamepad.buttonA.pressedChangedHandler = BUTTON(JoyButton::A);
+			gamepad.buttonB.pressedChangedHandler = BUTTON(JoyButton::X);
+			gamepad.buttonX.pressedChangedHandler = BUTTON(JoyButton::B);
+			gamepad.buttonY.pressedChangedHandler = BUTTON(JoyButton::Y);
 		} else {
 			gamepad.buttonA.pressedChangedHandler = BUTTON(JoyButton::A);
 			gamepad.buttonB.pressedChangedHandler = BUTTON(JoyButton::B);