diff --git a/src/SFML/Window/Linux/Joystick.cpp b/src/SFML/Window/Linux/Joystick.cpp index e8267d48..4f3ca725 100644 --- a/src/SFML/Window/Linux/Joystick.cpp +++ b/src/SFML/Window/Linux/Joystick.cpp @@ -28,13 +28,6 @@ #include #include -#if defined(SFML_SYSTEM_LINUX) - #include - #include -#elif defined(SFML_SYSTEM_FREEBSD) - // #include ? -#endif - namespace sf { @@ -69,7 +62,7 @@ void Joystick::Initialize(unsigned int Index) { // Use non-blocking mode fcntl(myDescriptor, F_SETFL, O_NONBLOCK); - + // Get number of buttons char NbButtons; ioctl(myDescriptor, JSIOCGBUTTONS, &NbButtons); @@ -78,12 +71,12 @@ void Joystick::Initialize(unsigned int Index) myNbButtons = Joy::ButtonCount; // Get the supported axes - char NbAxes, Axes[ABS_MAX + 1]; - ioctl(myDescriptor, JSIOCGAXES, &NbAxes); - ioctl(myDescriptor, JSIOCGAXMAP, Axes); + char NbAxes; + ioctl(myDescriptor, JSIOCGAXES, &NbAxes); + ioctl(myDescriptor, JSIOCGAXMAP, myAxesMapping); for (int i = 0; i < NbAxes; ++i) { - switch (Axes[i]) + switch (myAxesMapping[i]) { case ABS_X : myAxes[Joy::AxisX] = true; break; case ABS_Y : myAxes[Joy::AxisY] = true; break; @@ -114,7 +107,7 @@ JoystickState Joystick::UpdateState() // An axis has been moved case JS_EVENT_AXIS : { - switch (JoyState.number) + switch (myAxesMapping[JoyState.number]) { case ABS_X : myState.Axis[Joy::AxisX] = JoyState.value * 100.f / 32767.f; break; case ABS_Y : myState.Axis[Joy::AxisY] = JoyState.value * 100.f / 32767.f; break; diff --git a/src/SFML/Window/Linux/Joystick.hpp b/src/SFML/Window/Linux/Joystick.hpp index ea780f49..c03bf08e 100644 --- a/src/SFML/Window/Linux/Joystick.hpp +++ b/src/SFML/Window/Linux/Joystick.hpp @@ -28,6 +28,12 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// +#if defined(SFML_SYSTEM_LINUX) + #include + #include +#elif defined(SFML_SYSTEM_FREEBSD) + // #include ? +#endif namespace sf @@ -80,12 +86,13 @@ private : //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - int myDescriptor; ///< Linux descriptor of the joystick - unsigned int myNbButtons; ///< Number of buttons supported by the joystick - bool myAxes[Joy::AxisCount]; ///< Supported axes - JoystickState myState; ///< Current state of the joystick - int myPovX; ///< Last X position of the POV - int myPovY; ///< Last Y position of the POV + int myDescriptor; ///< Linux descriptor of the joystick + unsigned int myNbButtons; ///< Number of buttons supported by the joystick + bool myAxes[Joy::AxisCount]; ///< Supported axes + JoystickState myState; ///< Current state of the joystick + int myPovX; ///< Last X position of the POV + int myPovY; ///< Last Y position of the POV + char myAxesMapping[ABS_MAX + 1]; ///< Axes mapping (index --> axis id) }; } // namespace priv