Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(ios): map Nintendo controller buttons by label
  • Loading branch information
peterkmet committed Oct 29, 2026
commit 52ce0ed77af7854ef5dbc17dbfdedbc1cd9f08b3
4 changes: 3 additions & 1 deletion dm/ios/Sources/DmGamepad.m
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,14 @@ - (void)refresh { // pressed state → fill, sticks → knob position
static GCController *g_held[DM_PLAYERS]; // the controller of each slot, kept alive while it holds it (the slot table keys on its pointer)
static int g_merge;
static int32_t axis(float v) { return (int32_t)(fmaxf(-1.f, fminf(1.f, v)) * 32767); }
static int pad_nintendo(GCController *c) { NSString *k = c.productCategory; return [k isEqualToString:@"Switch Pro Controller"] || [k containsString:@"Joy-Con"]; }
static void read_pad(GCExtendedGamepad *g) {
int p = g_merge ? 0 : pad_slot_of(&g_slots, (__bridge const void *)g.controller); if (p < 0) return;
dm_haptics_apple_controller(p, g.controller);
uint64_t m = 0;
#define K(btn, bit) if (btn.isPressed) m |= 1ull << bit
K(g.buttonB, B_A); K(g.buttonA, B_B); K(g.buttonY, B_X); K(g.buttonX, B_Y); // by position: right A, bottom B, top X, left Y
if (pad_nintendo(g.controller)) { K(g.buttonA, B_A); K(g.buttonB, B_B); K(g.buttonX, B_X); K(g.buttonY, B_Y); } // iOS names a Nintendo pad's buttons by their labels
else { K(g.buttonB, B_A); K(g.buttonA, B_B); K(g.buttonY, B_X); K(g.buttonX, B_Y); } // by position: right A, bottom B, top X, left Y
K(g.leftShoulder, B_L); K(g.rightShoulder, B_R); K(g.leftTrigger, B_ZL); K(g.rightTrigger, B_ZR);
K(g.buttonMenu, B_PLUS); if (g.buttonOptions) K(g.buttonOptions, B_MINUS);
if (g.leftThumbstickButton) K(g.leftThumbstickButton, B_LS); if (g.rightThumbstickButton) K(g.rightThumbstickButton, B_RS);
Expand Down