mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 04:54:35 +00:00
Rename joystick ID variables
This commit is contained in:
parent
bf747e32b4
commit
efc6b35615
@ -572,7 +572,7 @@ The callback function receives the ID of the joystick that has been connected
|
|||||||
and disconnected and the event that occurred.
|
and disconnected and the event that occurred.
|
||||||
|
|
||||||
@code
|
@code
|
||||||
void joystick_callback(int joy, int event)
|
void joystick_callback(int jid, int event)
|
||||||
{
|
{
|
||||||
if (event == GLFW_CONNECTED)
|
if (event == GLFW_CONNECTED)
|
||||||
{
|
{
|
||||||
|
@ -1128,7 +1128,7 @@ typedef void (* GLFWmonitorfun)(GLFWmonitor*,int);
|
|||||||
* This is the function signature for joystick configuration callback
|
* This is the function signature for joystick configuration callback
|
||||||
* functions.
|
* functions.
|
||||||
*
|
*
|
||||||
* @param[in] joy The joystick that was connected or disconnected.
|
* @param[in] jid The joystick that was connected or disconnected.
|
||||||
* @param[in] event One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`.
|
* @param[in] event One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`.
|
||||||
*
|
*
|
||||||
* @sa @ref joystick_event
|
* @sa @ref joystick_event
|
||||||
@ -3584,7 +3584,7 @@ GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun cbfun);
|
|||||||
*
|
*
|
||||||
* This function returns whether the specified joystick is present.
|
* This function returns whether the specified joystick is present.
|
||||||
*
|
*
|
||||||
* @param[in] joy The [joystick](@ref joysticks) to query.
|
* @param[in] jid The [joystick](@ref joysticks) to query.
|
||||||
* @return `GLFW_TRUE` if the joystick is present, or `GLFW_FALSE` otherwise.
|
* @return `GLFW_TRUE` if the joystick is present, or `GLFW_FALSE` otherwise.
|
||||||
*
|
*
|
||||||
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
|
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
|
||||||
@ -3598,7 +3598,7 @@ GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun cbfun);
|
|||||||
*
|
*
|
||||||
* @ingroup input
|
* @ingroup input
|
||||||
*/
|
*/
|
||||||
GLFWAPI int glfwJoystickPresent(int joy);
|
GLFWAPI int glfwJoystickPresent(int jid);
|
||||||
|
|
||||||
/*! @brief Returns the values of all axes of the specified joystick.
|
/*! @brief Returns the values of all axes of the specified joystick.
|
||||||
*
|
*
|
||||||
@ -3609,7 +3609,7 @@ GLFWAPI int glfwJoystickPresent(int joy);
|
|||||||
* cause this function to return `NULL`. Call @ref glfwJoystickPresent to
|
* cause this function to return `NULL`. Call @ref glfwJoystickPresent to
|
||||||
* check device presence.
|
* check device presence.
|
||||||
*
|
*
|
||||||
* @param[in] joy The [joystick](@ref joysticks) to query.
|
* @param[in] jid The [joystick](@ref joysticks) to query.
|
||||||
* @param[out] count Where to store the number of axis values in the returned
|
* @param[out] count Where to store the number of axis values in the returned
|
||||||
* array. This is set to zero if the joystick is not present or an error
|
* array. This is set to zero if the joystick is not present or an error
|
||||||
* occurred.
|
* occurred.
|
||||||
@ -3632,7 +3632,7 @@ GLFWAPI int glfwJoystickPresent(int joy);
|
|||||||
*
|
*
|
||||||
* @ingroup input
|
* @ingroup input
|
||||||
*/
|
*/
|
||||||
GLFWAPI const float* glfwGetJoystickAxes(int joy, int* count);
|
GLFWAPI const float* glfwGetJoystickAxes(int jid, int* count);
|
||||||
|
|
||||||
/*! @brief Returns the state of all buttons of the specified joystick.
|
/*! @brief Returns the state of all buttons of the specified joystick.
|
||||||
*
|
*
|
||||||
@ -3643,7 +3643,7 @@ GLFWAPI const float* glfwGetJoystickAxes(int joy, int* count);
|
|||||||
* cause this function to return `NULL`. Call @ref glfwJoystickPresent to
|
* cause this function to return `NULL`. Call @ref glfwJoystickPresent to
|
||||||
* check device presence.
|
* check device presence.
|
||||||
*
|
*
|
||||||
* @param[in] joy The [joystick](@ref joysticks) to query.
|
* @param[in] jid The [joystick](@ref joysticks) to query.
|
||||||
* @param[out] count Where to store the number of button states in the returned
|
* @param[out] count Where to store the number of button states in the returned
|
||||||
* array. This is set to zero if the joystick is not present or an error
|
* array. This is set to zero if the joystick is not present or an error
|
||||||
* occurred.
|
* occurred.
|
||||||
@ -3667,7 +3667,7 @@ GLFWAPI const float* glfwGetJoystickAxes(int joy, int* count);
|
|||||||
*
|
*
|
||||||
* @ingroup input
|
* @ingroup input
|
||||||
*/
|
*/
|
||||||
GLFWAPI const unsigned char* glfwGetJoystickButtons(int joy, int* count);
|
GLFWAPI const unsigned char* glfwGetJoystickButtons(int jid, int* count);
|
||||||
|
|
||||||
/*! @brief Returns the name of the specified joystick.
|
/*! @brief Returns the name of the specified joystick.
|
||||||
*
|
*
|
||||||
@ -3679,7 +3679,7 @@ GLFWAPI const unsigned char* glfwGetJoystickButtons(int joy, int* count);
|
|||||||
* cause this function to return `NULL`. Call @ref glfwJoystickPresent to
|
* cause this function to return `NULL`. Call @ref glfwJoystickPresent to
|
||||||
* check device presence.
|
* check device presence.
|
||||||
*
|
*
|
||||||
* @param[in] joy The [joystick](@ref joysticks) to query.
|
* @param[in] jid The [joystick](@ref joysticks) to query.
|
||||||
* @return The UTF-8 encoded name of the joystick, or `NULL` if the joystick
|
* @return The UTF-8 encoded name of the joystick, or `NULL` if the joystick
|
||||||
* is not present or an [error](@ref error_handling) occurred.
|
* is not present or an [error](@ref error_handling) occurred.
|
||||||
*
|
*
|
||||||
@ -3699,7 +3699,7 @@ GLFWAPI const unsigned char* glfwGetJoystickButtons(int joy, int* count);
|
|||||||
*
|
*
|
||||||
* @ingroup input
|
* @ingroup input
|
||||||
*/
|
*/
|
||||||
GLFWAPI const char* glfwGetJoystickName(int joy);
|
GLFWAPI const char* glfwGetJoystickName(int jid);
|
||||||
|
|
||||||
/*! @brief Sets the joystick configuration callback.
|
/*! @brief Sets the joystick configuration callback.
|
||||||
*
|
*
|
||||||
|
@ -272,24 +272,24 @@ static void matchCallback(void* context,
|
|||||||
IOHIDDeviceRef deviceRef)
|
IOHIDDeviceRef deviceRef)
|
||||||
{
|
{
|
||||||
_GLFWjoystickNS* js;
|
_GLFWjoystickNS* js;
|
||||||
int joy;
|
int jid;
|
||||||
|
|
||||||
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
|
for (jid = GLFW_JOYSTICK_1; jid <= GLFW_JOYSTICK_LAST; jid++)
|
||||||
{
|
{
|
||||||
if (_glfw.ns_js[joy].present && _glfw.ns_js[joy].deviceRef == deviceRef)
|
if (_glfw.ns_js[jid].present && _glfw.ns_js[jid].deviceRef == deviceRef)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
|
for (jid = GLFW_JOYSTICK_1; jid <= GLFW_JOYSTICK_LAST; jid++)
|
||||||
{
|
{
|
||||||
if (!_glfw.ns_js[joy].present)
|
if (!_glfw.ns_js[jid].present)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (joy > GLFW_JOYSTICK_LAST)
|
if (jid > GLFW_JOYSTICK_LAST)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
js = _glfw.ns_js + joy;
|
js = _glfw.ns_js + jid;
|
||||||
js->present = GLFW_TRUE;
|
js->present = GLFW_TRUE;
|
||||||
js->deviceRef = deviceRef;
|
js->deviceRef = deviceRef;
|
||||||
|
|
||||||
@ -324,7 +324,7 @@ static void matchCallback(void* context,
|
|||||||
js->buttons = calloc(CFArrayGetCount(js->buttonElements) +
|
js->buttons = calloc(CFArrayGetCount(js->buttonElements) +
|
||||||
CFArrayGetCount(js->hatElements) * 4, 1);
|
CFArrayGetCount(js->hatElements) * 4, 1);
|
||||||
|
|
||||||
_glfwInputJoystickChange(joy, GLFW_CONNECTED);
|
_glfwInputJoystickChange(jid, GLFW_CONNECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback for user-initiated joystick removal
|
// Callback for user-initiated joystick removal
|
||||||
@ -334,13 +334,13 @@ static void removeCallback(void* context,
|
|||||||
void* sender,
|
void* sender,
|
||||||
IOHIDDeviceRef deviceRef)
|
IOHIDDeviceRef deviceRef)
|
||||||
{
|
{
|
||||||
int joy;
|
int jid;
|
||||||
|
|
||||||
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
|
for (jid = GLFW_JOYSTICK_1; jid <= GLFW_JOYSTICK_LAST; jid++)
|
||||||
{
|
{
|
||||||
if (_glfw.ns_js[joy].deviceRef == deviceRef)
|
if (_glfw.ns_js[jid].deviceRef == deviceRef)
|
||||||
{
|
{
|
||||||
removeJoystick(_glfw.ns_js + joy);
|
removeJoystick(_glfw.ns_js + jid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -456,11 +456,11 @@ void _glfwInitJoysticksNS(void)
|
|||||||
//
|
//
|
||||||
void _glfwTerminateJoysticksNS(void)
|
void _glfwTerminateJoysticksNS(void)
|
||||||
{
|
{
|
||||||
int joy;
|
int jid;
|
||||||
|
|
||||||
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
|
for (jid = GLFW_JOYSTICK_1; jid <= GLFW_JOYSTICK_LAST; jid++)
|
||||||
{
|
{
|
||||||
_GLFWjoystickNS* js = _glfw.ns_js + joy;
|
_GLFWjoystickNS* js = _glfw.ns_js + jid;
|
||||||
removeJoystick(js);
|
removeJoystick(js);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -473,15 +473,15 @@ void _glfwTerminateJoysticksNS(void)
|
|||||||
////// GLFW platform API //////
|
////// GLFW platform API //////
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int _glfwPlatformJoystickPresent(int joy)
|
int _glfwPlatformJoystickPresent(int jid)
|
||||||
{
|
{
|
||||||
_GLFWjoystickNS* js = _glfw.ns_js + joy;
|
_GLFWjoystickNS* js = _glfw.ns_js + jid;
|
||||||
return js->present;
|
return js->present;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
|
const float* _glfwPlatformGetJoystickAxes(int jid, int* count)
|
||||||
{
|
{
|
||||||
_GLFWjoystickNS* js = _glfw.ns_js + joy;
|
_GLFWjoystickNS* js = _glfw.ns_js + jid;
|
||||||
if (!pollJoystickAxisEvents(js))
|
if (!pollJoystickAxisEvents(js))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -489,9 +489,9 @@ const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
|
|||||||
return js->axes;
|
return js->axes;
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count)
|
const unsigned char* _glfwPlatformGetJoystickButtons(int jid, int* count)
|
||||||
{
|
{
|
||||||
_GLFWjoystickNS* js = _glfw.ns_js + joy;
|
_GLFWjoystickNS* js = _glfw.ns_js + jid;
|
||||||
if (!pollJoystickButtonEvents(js))
|
if (!pollJoystickButtonEvents(js))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -500,9 +500,9 @@ const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count)
|
|||||||
return js->buttons;
|
return js->buttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* _glfwPlatformGetJoystickName(int joy)
|
const char* _glfwPlatformGetJoystickName(int jid)
|
||||||
{
|
{
|
||||||
_GLFWjoystickNS* js = _glfw.ns_js + joy;
|
_GLFWjoystickNS* js = _glfw.ns_js + jid;
|
||||||
if (!js->present)
|
if (!js->present)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
36
src/input.c
36
src/input.c
@ -124,10 +124,10 @@ void _glfwInputDrop(_GLFWwindow* window, int count, const char** paths)
|
|||||||
window->callbacks.drop((GLFWwindow*) window, count, paths);
|
window->callbacks.drop((GLFWwindow*) window, count, paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glfwInputJoystickChange(int joy, int event)
|
void _glfwInputJoystickChange(int jid, int event)
|
||||||
{
|
{
|
||||||
if (_glfw.callbacks.joystick)
|
if (_glfw.callbacks.joystick)
|
||||||
_glfw.callbacks.joystick(joy, event);
|
_glfw.callbacks.joystick(jid, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -553,62 +553,62 @@ GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* handle, GLFWdropfun cbfun)
|
|||||||
return cbfun;
|
return cbfun;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI int glfwJoystickPresent(int joy)
|
GLFWAPI int glfwJoystickPresent(int jid)
|
||||||
{
|
{
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(0);
|
_GLFW_REQUIRE_INIT_OR_RETURN(0);
|
||||||
|
|
||||||
if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
|
if (jid < 0 || jid > GLFW_JOYSTICK_LAST)
|
||||||
{
|
{
|
||||||
_glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick %i", joy);
|
_glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick %i", jid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _glfwPlatformJoystickPresent(joy);
|
return _glfwPlatformJoystickPresent(jid);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI const float* glfwGetJoystickAxes(int joy, int* count)
|
GLFWAPI const float* glfwGetJoystickAxes(int jid, int* count)
|
||||||
{
|
{
|
||||||
assert(count != NULL);
|
assert(count != NULL);
|
||||||
*count = 0;
|
*count = 0;
|
||||||
|
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
|
||||||
if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
|
if (jid < 0 || jid > GLFW_JOYSTICK_LAST)
|
||||||
{
|
{
|
||||||
_glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick %i", joy);
|
_glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick %i", jid);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _glfwPlatformGetJoystickAxes(joy, count);
|
return _glfwPlatformGetJoystickAxes(jid, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI const unsigned char* glfwGetJoystickButtons(int joy, int* count)
|
GLFWAPI const unsigned char* glfwGetJoystickButtons(int jid, int* count)
|
||||||
{
|
{
|
||||||
assert(count != NULL);
|
assert(count != NULL);
|
||||||
*count = 0;
|
*count = 0;
|
||||||
|
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
|
||||||
if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
|
if (jid < 0 || jid > GLFW_JOYSTICK_LAST)
|
||||||
{
|
{
|
||||||
_glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick %i", joy);
|
_glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick %i", jid);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _glfwPlatformGetJoystickButtons(joy, count);
|
return _glfwPlatformGetJoystickButtons(jid, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI const char* glfwGetJoystickName(int joy)
|
GLFWAPI const char* glfwGetJoystickName(int jid)
|
||||||
{
|
{
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
|
|
||||||
if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
|
if (jid < 0 || jid > GLFW_JOYSTICK_LAST)
|
||||||
{
|
{
|
||||||
_glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick %i", joy);
|
_glfwInputError(GLFW_INVALID_ENUM, "Invalid joystick %i", jid);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _glfwPlatformGetJoystickName(joy);
|
return _glfwPlatformGetJoystickName(jid);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun cbfun)
|
GLFWAPI GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun cbfun)
|
||||||
|
@ -608,22 +608,22 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window);
|
|||||||
/*! @copydoc glfwJoystickPresent
|
/*! @copydoc glfwJoystickPresent
|
||||||
* @ingroup platform
|
* @ingroup platform
|
||||||
*/
|
*/
|
||||||
int _glfwPlatformJoystickPresent(int joy);
|
int _glfwPlatformJoystickPresent(int jid);
|
||||||
|
|
||||||
/*! @copydoc glfwGetJoystickAxes
|
/*! @copydoc glfwGetJoystickAxes
|
||||||
* @ingroup platform
|
* @ingroup platform
|
||||||
*/
|
*/
|
||||||
const float* _glfwPlatformGetJoystickAxes(int joy, int* count);
|
const float* _glfwPlatformGetJoystickAxes(int jid, int* count);
|
||||||
|
|
||||||
/*! @copydoc glfwGetJoystickButtons
|
/*! @copydoc glfwGetJoystickButtons
|
||||||
* @ingroup platform
|
* @ingroup platform
|
||||||
*/
|
*/
|
||||||
const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count);
|
const unsigned char* _glfwPlatformGetJoystickButtons(int jid, int* count);
|
||||||
|
|
||||||
/*! @copydoc glfwGetJoystickName
|
/*! @copydoc glfwGetJoystickName
|
||||||
* @ingroup platform
|
* @ingroup platform
|
||||||
*/
|
*/
|
||||||
const char* _glfwPlatformGetJoystickName(int joy);
|
const char* _glfwPlatformGetJoystickName(int jid);
|
||||||
|
|
||||||
/*! @copydoc glfwGetTimerValue
|
/*! @copydoc glfwGetTimerValue
|
||||||
* @ingroup platform
|
* @ingroup platform
|
||||||
@ -961,11 +961,11 @@ void _glfwInputError(int error, const char* format, ...);
|
|||||||
void _glfwInputDrop(_GLFWwindow* window, int count, const char** names);
|
void _glfwInputDrop(_GLFWwindow* window, int count, const char** names);
|
||||||
|
|
||||||
/*! @brief Notifies shared code of a joystick connection/disconnection event.
|
/*! @brief Notifies shared code of a joystick connection/disconnection event.
|
||||||
* @param[in] joy The joystick that was connected or disconnected.
|
* @param[in] jid The joystick that was connected or disconnected.
|
||||||
* @param[in] event One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`.
|
* @param[in] event One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`.
|
||||||
* @ingroup event
|
* @ingroup event
|
||||||
*/
|
*/
|
||||||
void _glfwInputJoystickChange(int joy, int event);
|
void _glfwInputJoystickChange(int jid, int event);
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -50,25 +50,25 @@ static GLFWbool openJoystickDevice(const char* path)
|
|||||||
{
|
{
|
||||||
char axisCount, buttonCount;
|
char axisCount, buttonCount;
|
||||||
char name[256] = "";
|
char name[256] = "";
|
||||||
int joy, fd, version;
|
int jid, fd, version;
|
||||||
_GLFWjoystickLinux* js;
|
_GLFWjoystickLinux* js;
|
||||||
|
|
||||||
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
|
for (jid = GLFW_JOYSTICK_1; jid <= GLFW_JOYSTICK_LAST; jid++)
|
||||||
{
|
{
|
||||||
if (!_glfw.linux_js.js[joy].present)
|
if (!_glfw.linux_js.js[jid].present)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (strcmp(_glfw.linux_js.js[joy].path, path) == 0)
|
if (strcmp(_glfw.linux_js.js[jid].path, path) == 0)
|
||||||
return GLFW_FALSE;
|
return GLFW_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
|
for (jid = GLFW_JOYSTICK_1; jid <= GLFW_JOYSTICK_LAST; jid++)
|
||||||
{
|
{
|
||||||
if (!_glfw.linux_js.js[joy].present)
|
if (!_glfw.linux_js.js[jid].present)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (joy > GLFW_JOYSTICK_LAST)
|
if (jid > GLFW_JOYSTICK_LAST)
|
||||||
return GLFW_FALSE;
|
return GLFW_FALSE;
|
||||||
|
|
||||||
fd = open(path, O_RDONLY | O_NONBLOCK);
|
fd = open(path, O_RDONLY | O_NONBLOCK);
|
||||||
@ -87,7 +87,7 @@ static GLFWbool openJoystickDevice(const char* path)
|
|||||||
if (ioctl(fd, JSIOCGNAME(sizeof(name)), name) < 0)
|
if (ioctl(fd, JSIOCGNAME(sizeof(name)), name) < 0)
|
||||||
strncpy(name, "Unknown", sizeof(name));
|
strncpy(name, "Unknown", sizeof(name));
|
||||||
|
|
||||||
js = _glfw.linux_js.js + joy;
|
js = _glfw.linux_js.js + jid;
|
||||||
js->present = GLFW_TRUE;
|
js->present = GLFW_TRUE;
|
||||||
js->name = strdup(name);
|
js->name = strdup(name);
|
||||||
js->path = strdup(path);
|
js->path = strdup(path);
|
||||||
@ -101,7 +101,7 @@ static GLFWbool openJoystickDevice(const char* path)
|
|||||||
js->buttonCount = (int) buttonCount;
|
js->buttonCount = (int) buttonCount;
|
||||||
js->buttons = calloc(buttonCount, 1);
|
js->buttons = calloc(buttonCount, 1);
|
||||||
|
|
||||||
_glfwInputJoystickChange(joy, GLFW_CONNECTED);
|
_glfwInputJoystickChange(jid, GLFW_CONNECTED);
|
||||||
return GLFW_TRUE;
|
return GLFW_TRUE;
|
||||||
}
|
}
|
||||||
#endif // __linux__
|
#endif // __linux__
|
||||||
@ -304,15 +304,15 @@ void _glfwPollJoystickEvents(void)
|
|||||||
////// GLFW platform API //////
|
////// GLFW platform API //////
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int _glfwPlatformJoystickPresent(int joy)
|
int _glfwPlatformJoystickPresent(int jid)
|
||||||
{
|
{
|
||||||
_GLFWjoystickLinux* js = _glfw.linux_js.js + joy;
|
_GLFWjoystickLinux* js = _glfw.linux_js.js + jid;
|
||||||
return pollJoystickEvents(js);
|
return pollJoystickEvents(js);
|
||||||
}
|
}
|
||||||
|
|
||||||
const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
|
const float* _glfwPlatformGetJoystickAxes(int jid, int* count)
|
||||||
{
|
{
|
||||||
_GLFWjoystickLinux* js = _glfw.linux_js.js + joy;
|
_GLFWjoystickLinux* js = _glfw.linux_js.js + jid;
|
||||||
if (!pollJoystickEvents(js))
|
if (!pollJoystickEvents(js))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -320,9 +320,9 @@ const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
|
|||||||
return js->axes;
|
return js->axes;
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count)
|
const unsigned char* _glfwPlatformGetJoystickButtons(int jid, int* count)
|
||||||
{
|
{
|
||||||
_GLFWjoystickLinux* js = _glfw.linux_js.js + joy;
|
_GLFWjoystickLinux* js = _glfw.linux_js.js + jid;
|
||||||
if (!pollJoystickEvents(js))
|
if (!pollJoystickEvents(js))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -330,9 +330,9 @@ const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count)
|
|||||||
return js->buttons;
|
return js->buttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* _glfwPlatformGetJoystickName(int joy)
|
const char* _glfwPlatformGetJoystickName(int jid)
|
||||||
{
|
{
|
||||||
_GLFWjoystickLinux* js = _glfw.linux_js.js + joy;
|
_GLFWjoystickLinux* js = _glfw.linux_js.js + jid;
|
||||||
if (!pollJoystickEvents(js))
|
if (!pollJoystickEvents(js))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -332,26 +332,26 @@ static BOOL CALLBACK deviceObjectCallback(const DIDEVICEOBJECTINSTANCEW* doi,
|
|||||||
//
|
//
|
||||||
static BOOL CALLBACK deviceCallback(const DIDEVICEINSTANCE* di, void* user)
|
static BOOL CALLBACK deviceCallback(const DIDEVICEINSTANCE* di, void* user)
|
||||||
{
|
{
|
||||||
int joy = 0;
|
int jid = 0;
|
||||||
DIDEVCAPS dc;
|
DIDEVCAPS dc;
|
||||||
DIPROPDWORD dipd;
|
DIPROPDWORD dipd;
|
||||||
IDirectInputDevice8* device;
|
IDirectInputDevice8* device;
|
||||||
_GLFWobjenumWin32 data;
|
_GLFWobjenumWin32 data;
|
||||||
_GLFWjoystickWin32* js;
|
_GLFWjoystickWin32* js;
|
||||||
|
|
||||||
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
|
for (jid = GLFW_JOYSTICK_1; jid <= GLFW_JOYSTICK_LAST; jid++)
|
||||||
{
|
{
|
||||||
if (memcmp(&_glfw.win32_js[joy].guid, &di->guidInstance, sizeof(GUID)) == 0)
|
if (memcmp(&_glfw.win32_js[jid].guid, &di->guidInstance, sizeof(GUID)) == 0)
|
||||||
return DIENUM_CONTINUE;
|
return DIENUM_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
|
for (jid = GLFW_JOYSTICK_1; jid <= GLFW_JOYSTICK_LAST; jid++)
|
||||||
{
|
{
|
||||||
if (!_glfw.win32_js[joy].present)
|
if (!_glfw.win32_js[jid].present)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (joy > GLFW_JOYSTICK_LAST)
|
if (jid > GLFW_JOYSTICK_LAST)
|
||||||
return DIENUM_STOP;
|
return DIENUM_STOP;
|
||||||
|
|
||||||
if (supportsXInput(&di->guidProduct))
|
if (supportsXInput(&di->guidProduct))
|
||||||
@ -426,7 +426,7 @@ static BOOL CALLBACK deviceCallback(const DIDEVICEINSTANCE* di, void* user)
|
|||||||
sizeof(_GLFWjoyobjectWin32),
|
sizeof(_GLFWjoyobjectWin32),
|
||||||
compareJoystickObjects);
|
compareJoystickObjects);
|
||||||
|
|
||||||
js = _glfw.win32_js + joy;
|
js = _glfw.win32_js + jid;
|
||||||
js->device = device;
|
js->device = device;
|
||||||
js->guid = di->guidInstance;
|
js->guid = di->guidInstance;
|
||||||
js->axisCount = data.axisCount + data.sliderCount;
|
js->axisCount = data.axisCount + data.sliderCount;
|
||||||
@ -438,7 +438,7 @@ static BOOL CALLBACK deviceCallback(const DIDEVICEINSTANCE* di, void* user)
|
|||||||
js->name = _glfwCreateUTF8FromWideStringWin32(di->tszInstanceName);
|
js->name = _glfwCreateUTF8FromWideStringWin32(di->tszInstanceName);
|
||||||
js->present = GLFW_TRUE;
|
js->present = GLFW_TRUE;
|
||||||
|
|
||||||
_glfwInputJoystickChange(joy, GLFW_CONNECTED);
|
_glfwInputJoystickChange(jid, GLFW_CONNECTED);
|
||||||
return DIENUM_CONTINUE;
|
return DIENUM_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -447,33 +447,33 @@ static BOOL CALLBACK deviceCallback(const DIDEVICEINSTANCE* di, void* user)
|
|||||||
//
|
//
|
||||||
static GLFWbool openXinputDevice(DWORD index)
|
static GLFWbool openXinputDevice(DWORD index)
|
||||||
{
|
{
|
||||||
int joy;
|
int jid;
|
||||||
XINPUT_CAPABILITIES xic;
|
XINPUT_CAPABILITIES xic;
|
||||||
_GLFWjoystickWin32* js;
|
_GLFWjoystickWin32* js;
|
||||||
|
|
||||||
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
|
for (jid = GLFW_JOYSTICK_1; jid <= GLFW_JOYSTICK_LAST; jid++)
|
||||||
{
|
{
|
||||||
if (_glfw.win32_js[joy].present &&
|
if (_glfw.win32_js[jid].present &&
|
||||||
_glfw.win32_js[joy].device == NULL &&
|
_glfw.win32_js[jid].device == NULL &&
|
||||||
_glfw.win32_js[joy].index == index)
|
_glfw.win32_js[jid].index == index)
|
||||||
{
|
{
|
||||||
return GLFW_FALSE;
|
return GLFW_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
|
for (jid = GLFW_JOYSTICK_1; jid <= GLFW_JOYSTICK_LAST; jid++)
|
||||||
{
|
{
|
||||||
if (!_glfw.win32_js[joy].present)
|
if (!_glfw.win32_js[jid].present)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (joy > GLFW_JOYSTICK_LAST)
|
if (jid > GLFW_JOYSTICK_LAST)
|
||||||
return GLFW_FALSE;
|
return GLFW_FALSE;
|
||||||
|
|
||||||
if (_glfw_XInputGetCapabilities(index, 0, &xic) != ERROR_SUCCESS)
|
if (_glfw_XInputGetCapabilities(index, 0, &xic) != ERROR_SUCCESS)
|
||||||
return GLFW_FALSE;
|
return GLFW_FALSE;
|
||||||
|
|
||||||
js = _glfw.win32_js + joy;
|
js = _glfw.win32_js + jid;
|
||||||
js->axisCount = 6;
|
js->axisCount = 6;
|
||||||
js->axes = calloc(js->axisCount, sizeof(float));
|
js->axes = calloc(js->axisCount, sizeof(float));
|
||||||
js->buttonCount = 14;
|
js->buttonCount = 14;
|
||||||
@ -482,7 +482,7 @@ static GLFWbool openXinputDevice(DWORD index)
|
|||||||
js->name = strdup(getDeviceDescription(&xic));
|
js->name = strdup(getDeviceDescription(&xic));
|
||||||
js->index = index;
|
js->index = index;
|
||||||
|
|
||||||
_glfwInputJoystickChange(joy, GLFW_CONNECTED);
|
_glfwInputJoystickChange(jid, GLFW_CONNECTED);
|
||||||
|
|
||||||
return GLFW_TRUE;
|
return GLFW_TRUE;
|
||||||
}
|
}
|
||||||
@ -675,10 +675,10 @@ void _glfwInitJoysticksWin32(void)
|
|||||||
//
|
//
|
||||||
void _glfwTerminateJoysticksWin32(void)
|
void _glfwTerminateJoysticksWin32(void)
|
||||||
{
|
{
|
||||||
int joy;
|
int jid;
|
||||||
|
|
||||||
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
|
for (jid = GLFW_JOYSTICK_1; jid <= GLFW_JOYSTICK_LAST; jid++)
|
||||||
closeJoystick(_glfw.win32_js + joy);
|
closeJoystick(_glfw.win32_js + jid);
|
||||||
|
|
||||||
if (_glfw.win32.dinput8.api)
|
if (_glfw.win32.dinput8.api)
|
||||||
IDirectInput8_Release(_glfw.win32.dinput8.api);
|
IDirectInput8_Release(_glfw.win32.dinput8.api);
|
||||||
@ -715,10 +715,10 @@ void _glfwDetectJoystickConnectionWin32(void)
|
|||||||
//
|
//
|
||||||
void _glfwDetectJoystickDisconnectionWin32(void)
|
void _glfwDetectJoystickDisconnectionWin32(void)
|
||||||
{
|
{
|
||||||
int joy;
|
int jid;
|
||||||
|
|
||||||
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
|
for (jid = GLFW_JOYSTICK_1; jid <= GLFW_JOYSTICK_LAST; jid++)
|
||||||
pollJoystickState(_glfw.win32_js + joy, _GLFW_PRESENCE_ONLY);
|
pollJoystickState(_glfw.win32_js + jid, _GLFW_PRESENCE_ONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -726,15 +726,15 @@ void _glfwDetectJoystickDisconnectionWin32(void)
|
|||||||
////// GLFW platform API //////
|
////// GLFW platform API //////
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int _glfwPlatformJoystickPresent(int joy)
|
int _glfwPlatformJoystickPresent(int jid)
|
||||||
{
|
{
|
||||||
_GLFWjoystickWin32* js = _glfw.win32_js + joy;
|
_GLFWjoystickWin32* js = _glfw.win32_js + jid;
|
||||||
return pollJoystickState(js, _GLFW_PRESENCE_ONLY);
|
return pollJoystickState(js, _GLFW_PRESENCE_ONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
|
const float* _glfwPlatformGetJoystickAxes(int jid, int* count)
|
||||||
{
|
{
|
||||||
_GLFWjoystickWin32* js = _glfw.win32_js + joy;
|
_GLFWjoystickWin32* js = _glfw.win32_js + jid;
|
||||||
if (!pollJoystickState(js, _GLFW_UPDATE_STATE))
|
if (!pollJoystickState(js, _GLFW_UPDATE_STATE))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -742,9 +742,9 @@ const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
|
|||||||
return js->axes;
|
return js->axes;
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count)
|
const unsigned char* _glfwPlatformGetJoystickButtons(int jid, int* count)
|
||||||
{
|
{
|
||||||
_GLFWjoystickWin32* js = _glfw.win32_js + joy;
|
_GLFWjoystickWin32* js = _glfw.win32_js + jid;
|
||||||
if (!pollJoystickState(js, _GLFW_UPDATE_STATE))
|
if (!pollJoystickState(js, _GLFW_UPDATE_STATE))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -752,9 +752,9 @@ const unsigned char* _glfwPlatformGetJoystickButtons(int joy, int* count)
|
|||||||
return js->buttons;
|
return js->buttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* _glfwPlatformGetJoystickName(int joy)
|
const char* _glfwPlatformGetJoystickName(int jid)
|
||||||
{
|
{
|
||||||
_GLFWjoystickWin32* js = _glfw.win32_js + joy;
|
_GLFWjoystickWin32* js = _glfw.win32_js + jid;
|
||||||
if (!pollJoystickState(js, _GLFW_PRESENCE_ONLY))
|
if (!pollJoystickState(js, _GLFW_PRESENCE_ONLY))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -459,26 +459,26 @@ static void monitor_callback(GLFWmonitor* monitor, int event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void joystick_callback(int joy, int event)
|
static void joystick_callback(int jid, int event)
|
||||||
{
|
{
|
||||||
if (event == GLFW_CONNECTED)
|
if (event == GLFW_CONNECTED)
|
||||||
{
|
{
|
||||||
int axisCount, buttonCount;
|
int axisCount, buttonCount;
|
||||||
|
|
||||||
glfwGetJoystickAxes(joy, &axisCount);
|
glfwGetJoystickAxes(jid, &axisCount);
|
||||||
glfwGetJoystickButtons(joy, &buttonCount);
|
glfwGetJoystickButtons(jid, &buttonCount);
|
||||||
|
|
||||||
printf("%08x at %0.3f: Joystick %i (%s) was connected with %i axes and %i buttons\n",
|
printf("%08x at %0.3f: Joystick %i (%s) was connected with %i axes and %i buttons\n",
|
||||||
counter++, glfwGetTime(),
|
counter++, glfwGetTime(),
|
||||||
joy,
|
jid,
|
||||||
glfwGetJoystickName(joy),
|
glfwGetJoystickName(jid),
|
||||||
axisCount,
|
axisCount,
|
||||||
buttonCount);
|
buttonCount);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("%08x at %0.3f: Joystick %i was disconnected\n",
|
printf("%08x at %0.3f: Joystick %i was disconnected\n",
|
||||||
counter++, glfwGetTime(), joy);
|
counter++, glfwGetTime(), jid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,17 +60,17 @@ static void error_callback(int error, const char* description)
|
|||||||
fprintf(stderr, "Error: %s\n", description);
|
fprintf(stderr, "Error: %s\n", description);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void joystick_callback(int joy, int event)
|
static void joystick_callback(int jid, int event)
|
||||||
{
|
{
|
||||||
if (event == GLFW_CONNECTED)
|
if (event == GLFW_CONNECTED)
|
||||||
joysticks[joystick_count++] = joy;
|
joysticks[joystick_count++] = jid;
|
||||||
else if (event == GLFW_DISCONNECTED)
|
else if (event == GLFW_DISCONNECTED)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < joystick_count; i++)
|
for (i = 0; i < joystick_count; i++)
|
||||||
{
|
{
|
||||||
if (joysticks[i] == joy)
|
if (joysticks[i] == jid)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ static const char* joystick_label(int jid)
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
int joy;
|
int jid;
|
||||||
GLFWwindow* window;
|
GLFWwindow* window;
|
||||||
struct nk_context* nk;
|
struct nk_context* nk;
|
||||||
struct nk_font_atlas* atlas;
|
struct nk_font_atlas* atlas;
|
||||||
@ -102,10 +102,10 @@ int main(void)
|
|||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
for (joy = GLFW_JOYSTICK_1; joy <= GLFW_JOYSTICK_LAST; joy++)
|
for (jid = GLFW_JOYSTICK_1; jid <= GLFW_JOYSTICK_LAST; jid++)
|
||||||
{
|
{
|
||||||
if (glfwJoystickPresent(joy))
|
if (glfwJoystickPresent(jid))
|
||||||
joystick_callback(joy, GLFW_CONNECTED);
|
joystick_callback(jid, GLFW_CONNECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetJoystickCallback(joystick_callback);
|
glfwSetJoystickCallback(joystick_callback);
|
||||||
|
Loading…
Reference in New Issue
Block a user