Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apple: improved Nintendo Switch Online controller support through mfi #16477

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 39 additions & 3 deletions input/drivers_joypad/mfi_joypad.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ static bool apple_gamecontroller_available(void)
return true;
}

static bool mfi_controller_is_siri_remote(GCController *controller)
{
return controller.microGamepad && !controller.extendedGamepad && [@"Remote" isEqualToString:controller.vendorName];
}

static void apple_gamecontroller_joypad_poll_internal(GCController *controller, uint32_t slot)
{
uint32_t *buttons = &mfi_buttons[slot];
Expand All @@ -91,7 +96,36 @@ static void apple_gamecontroller_joypad_poll_internal(GCController *controller,
}
memset(mfi_axes[slot], 0, sizeof(mfi_axes[0]));

if (controller.extendedGamepad)
if (@available(macOS 11, iOS 14, tvOS 14, *))
{
GCPhysicalInputProfile *profile = controller.physicalInputProfile;

*buttons |= [[profile.dpads[GCInputDirectionPad] up] isPressed] ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
*buttons |= [[profile.dpads[GCInputDirectionPad] down] isPressed] ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
*buttons |= [[profile.dpads[GCInputDirectionPad] left] isPressed] ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
*buttons |= [[profile.dpads[GCInputDirectionPad] right] isPressed] ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
*buttons |= [profile.buttons[GCInputButtonA] isPressed] ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0;
*buttons |= [profile.buttons[GCInputButtonB] isPressed] ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0;
*buttons |= [profile.buttons[GCInputButtonX] isPressed] ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0;
*buttons |= [profile.buttons[GCInputButtonY] isPressed] ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0;
*buttons |= [profile.buttons[GCInputLeftShoulder] isPressed] ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0;
*buttons |= [profile.buttons[GCInputRightShoulder] isPressed] ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0;
*buttons |= [profile.buttons[GCInputLeftTrigger] isPressed] ? (1 << RETRO_DEVICE_ID_JOYPAD_L2) : 0;
*buttons |= [profile.buttons[GCInputRightTrigger] isPressed] ? (1 << RETRO_DEVICE_ID_JOYPAD_R2) : 0;
*buttons |= [profile.buttons[GCInputLeftThumbstickButton] isPressed] ? (1 << RETRO_DEVICE_ID_JOYPAD_L3) : 0;
*buttons |= [profile.buttons[GCInputRightThumbstickButton] isPressed] ? (1 << RETRO_DEVICE_ID_JOYPAD_R3) : 0;
*buttons |= [profile.buttons[GCInputButtonOptions] isPressed] ? (1 << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0;
*buttons |= [profile.buttons[GCInputButtonMenu] isPressed] ? (1 << RETRO_DEVICE_ID_JOYPAD_START) : 0;
*buttons |= [profile.buttons[GCInputButtonHome] isPressed] ? (1 << RARCH_FIRST_CUSTOM_BIND) : 0;

mfi_axes[slot][0] = [[profile.dpads[GCInputLeftThumbstick] xAxis] value] * 32767.0f;
mfi_axes[slot][1] = [[profile.dpads[GCInputLeftThumbstick] yAxis] value] * 32767.0f;
mfi_axes[slot][2] = [[profile.dpads[GCInputRightThumbstick] xAxis] value] * 32767.0f;
mfi_axes[slot][3] = [[profile.dpads[GCInputRightThumbstick] yAxis] value] * 32767.0f;
mfi_axes[slot][4] = [profile.buttons[GCInputLeftTrigger] value] * 32767.0f;
mfi_axes[slot][5] = [profile.buttons[GCInputRightTrigger] value] * 32767.0f;
}
else if (controller.extendedGamepad)
{
GCExtendedGamepad *gp = (GCExtendedGamepad *)controller.extendedGamepad;

Expand Down Expand Up @@ -185,7 +219,9 @@ static void apple_gamecontroller_joypad_poll(void)
for (GCController *controller in [GCController controllers])
{
/* If we have not assigned a slot to this controller yet, ignore it. */
if (controller && (controller.playerIndex >= 0) && (controller.playerIndex < MAX_USERS))
if ( controller &&
(controller.playerIndex >= 0) && (controller.playerIndex < MAX_USERS) &&
!mfi_controller_is_siri_remote(controller))
apple_gamecontroller_joypad_poll_internal(controller, (uint32_t)controller.playerIndex);
}
}
Expand Down Expand Up @@ -454,7 +490,7 @@ static void apple_gamecontroller_joypad_connect(GCController *controller)
gc.playerIndex = newPlayerIndex++;
}

if (controller.microGamepad && !controller.extendedGamepad)
if (mfi_controller_is_siri_remote(controller))
return;

apple_gamecontroller_joypad_register(controller);
Expand Down