Index: src/hid/platform/Linux/OFGameController.m ================================================================== --- src/hid/platform/Linux/OFGameController.m +++ src/hid/platform/Linux/OFGameController.m @@ -37,13 +37,27 @@ #import "OFInvalidArgumentException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" +/* + * Controllers with tested correct mapping: + * + * Microsoft X-Box 360 pad [045E:028E] + * Joy-Con (L) [057E:2006] + * Joy-Con (R) [057E:2007] + * N64 Controller [057E:2019] + * Sony Interactive Entertainment DualSense Wireless Controller [054C:0CE6] + */ + +static const uint16_t vendorIDMicrosoft = 0x045E; static const uint16_t vendorIDNintendo = 0x057E; static const uint16_t vendorIDSony = 0x054C; +/* Microsoft controllers */ +static const uint16_t productIDXbox360 = 0x028E; + /* Nintendo controllers */ static const uint16_t productIDLeftJoycon = 0x2006; static const uint16_t productIDRightJoycon = 0x2007; static const uint16_t productIDN64Controller = 0x2019; @@ -61,11 +75,18 @@ }; static OFGameControllerButton buttonToName(uint16_t button, uint16_t vendorID, uint16_t productID) { - if (vendorID == vendorIDNintendo && + if (vendorID == vendorIDMicrosoft && productID == productIDXbox360) { + switch (button) { + case BTN_Y: + return OFGameControllerNorthButton; + case BTN_X: + return OFGameControllerWestButton; + } + } else if (vendorID == vendorIDNintendo && productID == productIDLeftJoycon) { switch (button) { case BTN_SELECT: return OFGameControllerMinusButton; case BTN_Z: @@ -76,14 +97,10 @@ return OFGameControllerSRButton; } } else if (vendorID == vendorIDNintendo && productID == productIDRightJoycon) { switch (button) { - case BTN_X: - return OFGameControllerNorthButton; - case BTN_Y: - return OFGameControllerWestButton; case BTN_START: return OFGameControllerPlusButton; case BTN_TL: return OFGameControllerSLButton; case BTN_TL2: @@ -105,28 +122,20 @@ case BTN_C: return OFGameControllerCPadRightButton; case BTN_Z: return OFGameControllerCaptureButton; } - } else if (vendorID == vendorIDSony && - productID == productIDDualSense) { - switch (button) { - case BTN_X: - return OFGameControllerNorthButton; - case BTN_Y: - return OFGameControllerWestButton; - } } switch (button) { - case BTN_Y: + case BTN_NORTH: return OFGameControllerNorthButton; - case BTN_A: + case BTN_SOUTH: return OFGameControllerSouthButton; - case BTN_X: + case BTN_WEST: return OFGameControllerWestButton; - case BTN_B: + case BTN_EAST: return OFGameControllerEastButton; case BTN_TL2: return OFGameControllerLeftTriggerButton; case BTN_TR2: return OFGameControllerRightTriggerButton;