Index: src/hid/OFXInputGameController.m ================================================================== --- src/hid/OFXInputGameController.m +++ src/hid/OFXInputGameController.m @@ -26,10 +26,14 @@ #import "OFInitializationFailedException.h" #import "OFReadFailedException.h" #include + +#ifndef XINPUT_GAMEPAD_GUIDE +# define XINPUT_GAMEPAD_GUIDE 0x400 +#endif struct XInputCapabilitiesEx { XINPUT_CAPABILITIES capabilities; WORD vendorID; WORD productID; @@ -39,11 +43,11 @@ }; static WINAPI DWORD (*XInputGetStateFuncPtr)(DWORD, XINPUT_STATE *); static WINAPI DWORD (*XInputGetCapabilitiesExFuncPtr)(DWORD, DWORD, DWORD, struct XInputCapabilitiesEx *); -static const char *XInputVersion; +static int XInputVersion; @implementation OFXInputGameController @synthesize vendorID = _vendorID, productID = _productID; @synthesize leftAnalogStickPosition = _leftAnalogStickPosition; @synthesize rightAnalogStickPosition = _rightAnalogStickPosition; @@ -56,25 +60,25 @@ return; if ((module = LoadLibraryA("xinput1_4.dll")) != NULL) { XInputGetStateFuncPtr = (WINAPI DWORD (*)(DWORD, XINPUT_STATE *)) - GetProcAddress(module, "XInputGetState"); + GetProcAddress(module, (LPCSTR)100); XInputGetCapabilitiesExFuncPtr = (WINAPI DWORD (*)(DWORD, DWORD, DWORD, struct XInputCapabilitiesEx *)) GetProcAddress(module, "XInputGetCapabilitiesEx"); - XInputVersion = "1.4"; + XInputVersion = 14; } else if ((module = LoadLibraryA("xinput1_3.dll")) != NULL) { XInputGetStateFuncPtr = (WINAPI DWORD (*)(DWORD, XINPUT_STATE *)) - GetProcAddress(module, "XInputGetState"); - XInputVersion = "1.3"; + GetProcAddress(module, (LPCSTR)100); + XInputVersion = 13; } else if ((module = LoadLibraryA("xinput9_1_0.dll")) != NULL) { XInputGetStateFuncPtr = (WINAPI DWORD (*)(DWORD, XINPUT_STATE *)) GetProcAddress(module, "XInputGetState"); - XInputVersion = "9.1.0"; + XInputVersion = 910; } } + (OFArray OF_GENERIC(OFGameController *) *)controllers { @@ -131,11 +135,11 @@ initWithUnsignedShort: capabilities.productID]; } } - _pressedButtons = [[OFMutableSet alloc] initWithCapacity: 16]; + _pressedButtons = [[OFMutableSet alloc] initWithCapacity: 17]; [self retrieveState]; } @catch (id e) { [self release]; @throw e; @@ -191,10 +195,13 @@ [_pressedButtons addObject: OFGameControllerDPadRightButton]; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_START) [_pressedButtons addObject: OFGameControllerStartButton]; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK) [_pressedButtons addObject: OFGameControllerSelectButton]; + if (XInputVersion != 910 && + state.Gamepad.wButtons & XINPUT_GAMEPAD_GUIDE) + [_pressedButtons addObject: OFGameControllerHomeButton]; _leftTriggerPressure = (float)state.Gamepad.bLeftTrigger / 255; _rightTriggerPressure = (float)state.Gamepad.bRightTrigger / 255; if (_leftTriggerPressure > 0) @@ -214,11 +221,20 @@ (state.Gamepad.sThumbRY < 0 ? -INT16_MIN : INT16_MAX)); } - (OFString *)name { - return [OFString stringWithFormat: @"XInput %s device", XInputVersion]; + switch (XInputVersion) { + case 14: + return @"XInput 1.4 device"; + case 13: + return @"XInput 1.3 device"; + case 910: + return @"XInput 9.1.0 device"; + } + + return nil; } - (OFSet OF_GENERIC(OFGameControllerButton) *)buttons { return [OFSet setWithObjects: @@ -235,11 +251,12 @@ OFGameControllerDPadLeftButton, OFGameControllerDPadRightButton, OFGameControllerDPadUpButton, OFGameControllerDPadDownButton, OFGameControllerStartButton, - OFGameControllerSelectButton, nil]; + OFGameControllerSelectButton, + (XInputVersion != 910 ? OFGameControllerHomeButton : nil), nil]; } - (OFSet OF_GENERIC(OFGameControllerButton) *)pressedButtons { return [[_pressedButtons copy] autorelease]; Index: tests/gamecontroller/GameControllerTests.m ================================================================== --- tests/gamecontroller/GameControllerTests.m +++ tests/gamecontroller/GameControllerTests.m @@ -60,11 +60,11 @@ # define gray silver #endif @interface GameControllerTests: OFObject { - OFArray OF_GENERIC(OFGameController) *_controllers; + OFArray OF_GENERIC(OFGameController *) *_controllers; OFDate *_lastControllersUpdate; } @end OF_APPLICATION_DELEGATE(GameControllerTests)