Skip to content

Commit

Permalink
Merge pull request #5732 from arthurc/fix-multiple-axis-inputs
Browse files Browse the repository at this point in the history
Prevent multiple HID elements of same usage type on OSX
  • Loading branch information
leoetlino committed Sep 15, 2017
2 parents 2b4bf86 + 79a646a commit 7caf44c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm
Expand Up @@ -2,6 +2,7 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include <algorithm>
#include <sstream>

#include <Foundation/Foundation.h>
Expand Down Expand Up @@ -49,11 +50,26 @@

if (axes)
{
std::vector<IOHIDElementRef> elems;
for (int i = 0; i < CFArrayGetCount(axes); i++)
{
IOHIDElementRef e = (IOHIDElementRef)CFArrayGetValueAtIndex(axes, i);
// DeviceElementDebugPrint(e, nullptr);
uint32_t usage = IOHIDElementGetUsage(e);

// Check for any existing elements with the same usage
auto it = std::find_if(elems.begin(), elems.end(), [usage](const auto& ref) {
return usage == IOHIDElementGetUsage(ref);
});

if (it == elems.end())
elems.push_back(e);
else
*it = e;
}

for (auto e : elems)
{
if (IOHIDElementGetUsage(e) == kHIDUsage_GD_Hatswitch)
{
AddInput(new Hat(e, m_device, Hat::up));
Expand All @@ -67,6 +83,7 @@
new Axis(e, m_device, Axis::positive));
}
}

CFRelease(axes);
}

Expand Down

0 comments on commit 7caf44c

Please sign in to comment.