Permalink
Browse files

Merge branch 'joybutton-ordering-osx' of git://github.com/ryanfields/…

…SFML into fix/joystick
  • Loading branch information...
2 parents a674135 + 8e4091f commit 13eb86768671a80bef5bf3edc29f8df8a20f1a63 @mantognini mantognini committed Jan 21, 2013
Showing with 12 additions and 0 deletions.
  1. +12 −0 src/SFML/Window/OSX/JoystickImpl.cpp
@@ -30,6 +30,14 @@
#include <SFML/Window/OSX/HIDInputManager.hpp>
#include <SFML/Window/OSX/HIDJoystickManager.hpp>
+// Translation unit namespace
+namespace {
+ ////////////////////////////////////////////////////////////
+ bool JoystickButtonSortPredicate(IOHIDElementRef b1, IOHIDElementRef b2)
+ {
+ return IOHIDElementGetUsage(b1) < IOHIDElementGetUsage(b2);
+ }
+}
namespace sf
{
@@ -218,6 +226,10 @@ bool JoystickImpl::open(unsigned int index)
}
}
+ // Ensure that the buttons will be indexed in the same order as their
+ // HID Usage (assigned by manufacturer and/or a driver).
+ std::sort(m_buttons.begin(), m_buttons.end(), JoystickButtonSortPredicate);
+
// Note : Joy::AxisPovX/Y are not supported (yet).
// Maybe kIOHIDElementTypeInput_Axis is the corresponding type but I can't test.

0 comments on commit 13eb867

Please sign in to comment.