Skip to content

Commit cdcee78

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

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

drivers/apple/joypad_apple.h

Lines changed: 1 addition & 0 deletions
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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ void play_strong_pattern(CHHapticPattern *p_pattern) {
144144
}
145145
}
146146

147+
if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) {
148+
if ([controller.productCategory isEqualToString:@"Switch Pro Controller"] || [controller.productCategory isEqualToString:@"Nintendo Switch Joy-Con (L/R)"]) {
149+
nintendo_button_layout = true;
150+
}
151+
}
152+
147153
int l_joy_id = joy_id;
148154

149155
auto BUTTON = [l_joy_id](JoyButton p_button) {
@@ -155,10 +161,18 @@ void play_strong_pattern(CHHapticPattern *p_pattern) {
155161
if (controller.extendedGamepad != nil) {
156162
GCExtendedGamepad *gamepad = controller.extendedGamepad;
157163

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);
164+
if (nintendo_button_layout) {
165+
gamepad.buttonA.pressedChangedHandler = BUTTON(JoyButton::B);
166+
gamepad.buttonB.pressedChangedHandler = BUTTON(JoyButton::A);
167+
gamepad.buttonX.pressedChangedHandler = BUTTON(JoyButton::Y);
168+
gamepad.buttonY.pressedChangedHandler = BUTTON(JoyButton::X);
169+
} else {
170+
gamepad.buttonA.pressedChangedHandler = BUTTON(JoyButton::A);
171+
gamepad.buttonB.pressedChangedHandler = BUTTON(JoyButton::B);
172+
gamepad.buttonX.pressedChangedHandler = BUTTON(JoyButton::X);
173+
gamepad.buttonY.pressedChangedHandler = BUTTON(JoyButton::Y);
174+
}
175+
162176
gamepad.leftShoulder.pressedChangedHandler = BUTTON(JoyButton::LEFT_SHOULDER);
163177
gamepad.rightShoulder.pressedChangedHandler = BUTTON(JoyButton::RIGHT_SHOULDER);
164178
gamepad.dpad.up.pressedChangedHandler = BUTTON(JoyButton::DPAD_UP);

0 commit comments

Comments
 (0)