Index: src/OFGameController.h ================================================================== --- src/OFGameController.h +++ src/OFGameController.h @@ -56,10 +56,12 @@ * * @ref OFGameControllerButtonDPadRight * * @ref OFGameControllerButtonCPadUp * * @ref OFGameControllerButtonCPadDown * * @ref OFGameControllerButtonCPadLeft * * @ref OFGameControllerButtonCPadRight + * * @ref OFGameControllerButtonSL + * * @ref OFGameControllerButtonSR * * @ref OFGameControllerButtonMode */ typedef OFConstantString *OFGameControllerButton; #ifdef __cplusplus @@ -184,10 +186,30 @@ /** * @brief The C-Pad Right button on a game controller. */ extern const OFGameControllerButton OFGameControllerButtonCPadRight; +/** + * @brief The + button on a game controller. + */ +extern const OFGameControllerButton OFGameControllerButtonPlus; + +/** + * @brief The - button on a game controller. + */ +extern const OFGameControllerButton OFGameControllerButtonMinus; + +/** + * @brief The SL button on a game controller. + */ +extern const OFGameControllerButton OFGameControllerButtonSL; + +/** + * @brief The SR button on a game controller. + */ +extern const OFGameControllerButton OFGameControllerButtonSR; + /** * @brief The Mode button on a game controller. */ extern const OFGameControllerButton OFGameControllerButtonMode; #ifdef __cplusplus Index: src/OFGameController.m ================================================================== --- src/OFGameController.m +++ src/OFGameController.m @@ -44,10 +44,14 @@ const OFGameControllerButton OFGameControllerButtonDPadRight = @"D-Pad Right"; const OFGameControllerButton OFGameControllerButtonCPadUp = @"C-Pad Up"; const OFGameControllerButton OFGameControllerButtonCPadDown = @"C-Pad Down"; const OFGameControllerButton OFGameControllerButtonCPadLeft = @"C-Pad Left"; const OFGameControllerButton OFGameControllerButtonCPadRight = @"C-Pad Right"; +const OFGameControllerButton OFGameControllerButtonPlus = @"+"; +const OFGameControllerButton OFGameControllerButtonMinus = @"-"; +const OFGameControllerButton OFGameControllerButtonSL = @"SL"; +const OFGameControllerButton OFGameControllerButtonSR = @"SR"; const OFGameControllerButton OFGameControllerButtonMode = @"Mode"; #if defined(OF_LINUX) && defined(OF_HAVE_FILES) # include "platform/Linux/OFGameController.m" #elif defined(OF_WINDOWS) Index: src/platform/Linux/OFGameController.m ================================================================== --- src/platform/Linux/OFGameController.m +++ src/platform/Linux/OFGameController.m @@ -38,10 +38,12 @@ #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" static const uint16_t vendorIDNintendo = 0x057E; +static const uint16_t productIDLeftJoycon = 0x2006; +static const uint16_t productIDRightJoycon = 0x2007; static const uint16_t productIDN64Controller = 0x2019; @interface OFGameController () - (instancetype)of_initWithPath: (OFString *)path OF_METHOD_FAMILY(init); @end @@ -54,10 +56,36 @@ static OFGameControllerButton buttonToName(uint16_t button, uint16_t vendorID, uint16_t productID) { if (vendorID == vendorIDNintendo && + productID == productIDLeftJoycon) { + switch (button) { + case BTN_SELECT: + return OFGameControllerButtonMinus; + case BTN_Z: + return OFGameControllerButtonCapture; + case BTN_TR: + return OFGameControllerButtonSL; + case BTN_TR2: + return OFGameControllerButtonSR; + } + } else if (vendorID == vendorIDNintendo && + productID == productIDRightJoycon) { + switch (button) { + case BTN_B: + return OFGameControllerButtonA; + case BTN_A: + return OFGameControllerButtonB; + case BTN_START: + return OFGameControllerButtonPlus; + case BTN_TL: + return OFGameControllerButtonSL; + case BTN_TL2: + return OFGameControllerButtonSR; + } + } else if (vendorID == vendorIDNintendo && productID == productIDN64Controller) { switch (button) { case BTN_TL2: return OFGameControllerButtonZ; case BTN_Y: @@ -213,11 +241,12 @@ if (ioctl(_fd, EVIOCGBIT(EV_KEY, sizeof(keyBits)), keyBits) == -1) @throw [OFInitializationFailedException exception]; - if (!OFBitSetIsSet(keyBits, BTN_GAMEPAD)) + if (!OFBitSetIsSet(keyBits, BTN_GAMEPAD) && + !OFBitSetIsSet(keyBits, BTN_DPAD_UP)) @throw [OFInvalidArgumentException exception]; if (ioctl(_fd, EVIOCGID, &inputID) == -1) @throw [OFInvalidArgumentException exception];