Skip to content

Commit 65ad8ca

Browse files
committed
Swap Nintendo face buttons on macOS
1 parent 134da37 commit 65ad8ca

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

drivers/apple/joypad_apple.h

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct GameController {
4343
RumbleContext *rumble_context API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) = nil;
4444
NSInteger ff_effect_timestamp = 0;
4545
bool force_feedback = false;
46+
bool nintendo_button_layout = false;
4647

4748
GameController(int p_joy_id, GCController *p_controller);
4849
~GameController();

drivers/apple/joypad_apple.mm

+19-4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ void play_strong_pattern(CHHapticPattern *p_pattern) {
143143
force_feedback = rumble_context->has_motors();
144144
}
145145
}
146+
147+
if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) {
148+
if ([controller.productCategory isEqualToString: @"Switch Pro Controller"]
149+
|| [controller.productCategory isEqualToString: @"Nintendo Switch Joy-Con (L/R)"]) {
150+
nintendo_button_layout = true;
151+
}
152+
}
146153

147154
int l_joy_id = joy_id;
148155

@@ -155,10 +162,18 @@ void play_strong_pattern(CHHapticPattern *p_pattern) {
155162
if (controller.extendedGamepad != nil) {
156163
GCExtendedGamepad *gamepad = controller.extendedGamepad;
157164

158-
gamepad.buttonA.pressedChangedHandler = BUTTON(JoyButton::A);
159-
gamepad.buttonB.pressedChangedHandler = BUTTON(JoyButton::B);
160-
gamepad.buttonX.pressedChangedHandler = BUTTON(JoyButton::X);
161-
gamepad.buttonY.pressedChangedHandler = BUTTON(JoyButton::Y);
165+
if (nintendo_button_layout) {
166+
gamepad.buttonA.pressedChangedHandler = BUTTON(JoyButton::B);
167+
gamepad.buttonB.pressedChangedHandler = BUTTON(JoyButton::A);
168+
gamepad.buttonX.pressedChangedHandler = BUTTON(JoyButton::Y);
169+
gamepad.buttonY.pressedChangedHandler = BUTTON(JoyButton::X);
170+
} else {
171+
gamepad.buttonA.pressedChangedHandler = BUTTON(JoyButton::A);
172+
gamepad.buttonB.pressedChangedHandler = BUTTON(JoyButton::B);
173+
gamepad.buttonX.pressedChangedHandler = BUTTON(JoyButton::X);
174+
gamepad.buttonY.pressedChangedHandler = BUTTON(JoyButton::Y);
175+
}
176+
162177
gamepad.leftShoulder.pressedChangedHandler = BUTTON(JoyButton::LEFT_SHOULDER);
163178
gamepad.rightShoulder.pressedChangedHandler = BUTTON(JoyButton::RIGHT_SHOULDER);
164179
gamepad.dpad.up.pressedChangedHandler = BUTTON(JoyButton::DPAD_UP);

0 commit comments

Comments
 (0)