Index: src/platform/Linux/OFGameController.m ================================================================== --- src/platform/Linux/OFGameController.m +++ src/platform/Linux/OFGameController.m @@ -36,14 +36,11 @@ #import "OFInvalidArgumentException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" -static const uint16_t vendorIDMicrosoft = 0x045E; static const uint16_t vendorIDNintendo = 0x057E; - -static const uint16_t productIDXbox360Controller = 0x028E; static const uint16_t productIDN64Controller = 0x2019; @interface OFGameController () - (instancetype)of_initWithPath: (OFString *)path OF_METHOD_FAMILY(init); - (void)of_processEvents; @@ -56,18 +53,11 @@ }; static OFGameControllerButton buttonToName(uint16_t button, uint16_t vendorID, uint16_t productID) { - if (vendorID == vendorIDMicrosoft && - productID == productIDXbox360Controller) { - switch (button) { - case BTN_C: - case BTN_Z: - return nil; - } - } else if (vendorID == vendorIDNintendo && + if (vendorID == vendorIDNintendo && productID == productIDN64Controller) { switch (button) { case BTN_TL2: return OFGameControllerButtonZ; case BTN_Y: @@ -80,13 +70,10 @@ return OFGameControllerButtonCPadDown; case BTN_MODE: return OFGameControllerButtonHome; case BTN_Z: return OFGameControllerButtonCapture; - case BTN_THUMBL: - case BTN_THUMBR: - return nil; } } switch (button) { case BTN_A: @@ -241,17 +228,14 @@ _name = [[OFString alloc] initWithCString: name encoding: encoding]; _buttons = [[OFMutableSet alloc] init]; for (size_t i = 0; i < sizeof(buttons) / sizeof(*buttons); - i++) { - OFGameControllerButton buttonName = - buttonToName(buttons[i], _vendorID, _productID); - - if (buttonName != nil) - [_buttons addObject: buttonName]; - } + i++) + if (OFBitSetIsSet(keyBits, buttons[i])) + [_buttons addObject: buttonToName( + buttons[i], _vendorID, _productID)]; _pressedButtons = [[OFMutableSet alloc] init]; if (OFBitSetIsSet(evBits, EV_ABS)) { if (ioctl(_fd, EVIOCGBIT(EV_ABS, sizeof(absBits)), @@ -368,12 +352,10 @@ - (void)of_processEvents { struct input_event event; for (;;) { - OFGameControllerButton name; - errno = 0; if (read(_fd, &event, sizeof(event)) < (int)sizeof(event)) { if (errno == EWOULDBLOCK) return; @@ -384,17 +366,16 @@ errNo: errno]; } switch (event.type) { case EV_KEY: - if ((name = buttonToName(event.code, _vendorID, - _productID)) != nil) { - if (event.value) - [_pressedButtons addObject: name]; - else - [_pressedButtons removeObject: name]; - } + if (event.value) + [_pressedButtons addObject: buttonToName( + event.code, _vendorID, _productID)]; + else + [_pressedButtons removeObject: buttonToName( + event.code, _vendorID, _productID)]; break; case EV_ABS: switch (event.code) { case ABS_X: _leftAnalogStickPosition.x = scale(event.value,