Merge branch '3.3-stable' into new-cursors-on-3.3-stable

This commit is contained in:
Camilla Löwy
2023-12-12 23:03:54 +01:00
59 changed files with 8870 additions and 3842 deletions

View File

@@ -360,6 +360,11 @@ void _glfwInputJoystick(_GLFWjoystick* js, int event)
{
const int jid = (int) (js - _glfw.joysticks);
if (event == GLFW_CONNECTED)
js->connected = GLFW_TRUE;
else if (event == GLFW_DISCONNECTED)
js->connected = GLFW_FALSE;
if (_glfw.callbacks.joystick)
_glfw.callbacks.joystick(jid, event);
}
@@ -415,7 +420,7 @@ void _glfwInitGamepadMappings(void)
for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{
_GLFWjoystick* js = _glfw.joysticks + jid;
if (js->present)
if (js->connected)
js->mapping = findValidMapping(js);
}
}
@@ -433,7 +438,7 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name,
for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{
if (!_glfw.joysticks[jid].present)
if (!_glfw.joysticks[jid].allocated)
break;
}
@@ -441,7 +446,7 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name,
return NULL;
js = _glfw.joysticks + jid;
js->present = GLFW_TRUE;
js->allocated = GLFW_TRUE;
js->axes = calloc(axisCount, sizeof(float));
js->buttons = calloc(buttonCount + (size_t) hatCount * 4, 1);
js->hats = calloc(hatCount, 1);
@@ -611,6 +616,12 @@ GLFWAPI const char* glfwGetKeyName(int key, int scancode)
if (key != GLFW_KEY_UNKNOWN)
{
if (key < GLFW_KEY_SPACE || key > GLFW_KEY_LAST)
{
_glfwInputError(GLFW_INVALID_ENUM, "Invalid key %i", key);
return NULL;
}
if (key != GLFW_KEY_KP_EQUAL &&
(key < GLFW_KEY_KP_0 || key > GLFW_KEY_KP_ADD) &&
(key < GLFW_KEY_APOSTROPHE || key > GLFW_KEY_WORLD_2))
@@ -631,7 +642,7 @@ GLFWAPI int glfwGetKeyScancode(int key)
if (key < GLFW_KEY_SPACE || key > GLFW_KEY_LAST)
{
_glfwInputError(GLFW_INVALID_ENUM, "Invalid key %i", key);
return GLFW_RELEASE;
return -1;
}
return _glfwPlatformGetKeyScancode(key);
@@ -743,9 +754,16 @@ GLFWAPI GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot)
_GLFWcursor* cursor;
assert(image != NULL);
assert(image->pixels != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
if (image->width <= 0 || image->height <= 0)
{
_glfwInputError(GLFW_INVALID_VALUE, "Invalid image dimensions for cursor");
return NULL;
}
cursor = calloc(1, sizeof(_GLFWcursor));
cursor->next = _glfw.cursorListHead;
_glfw.cursorListHead = cursor;
@@ -941,7 +959,7 @@ GLFWAPI int glfwJoystickPresent(int jid)
}
js = _glfw.joysticks + jid;
if (!js->present)
if (!js->connected)
return GLFW_FALSE;
return _glfwPlatformPollJoystick(js, _GLFW_POLL_PRESENCE);
@@ -966,7 +984,7 @@ GLFWAPI const float* glfwGetJoystickAxes(int jid, int* count)
}
js = _glfw.joysticks + jid;
if (!js->present)
if (!js->connected)
return NULL;
if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_AXES))
@@ -995,7 +1013,7 @@ GLFWAPI const unsigned char* glfwGetJoystickButtons(int jid, int* count)
}
js = _glfw.joysticks + jid;
if (!js->present)
if (!js->connected)
return NULL;
if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_BUTTONS))
@@ -1028,7 +1046,7 @@ GLFWAPI const unsigned char* glfwGetJoystickHats(int jid, int* count)
}
js = _glfw.joysticks + jid;
if (!js->present)
if (!js->connected)
return NULL;
if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_BUTTONS))
@@ -1054,7 +1072,7 @@ GLFWAPI const char* glfwGetJoystickName(int jid)
}
js = _glfw.joysticks + jid;
if (!js->present)
if (!js->connected)
return NULL;
if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_PRESENCE))
@@ -1079,7 +1097,7 @@ GLFWAPI const char* glfwGetJoystickGUID(int jid)
}
js = _glfw.joysticks + jid;
if (!js->present)
if (!js->connected)
return NULL;
if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_PRESENCE))
@@ -1098,7 +1116,7 @@ GLFWAPI void glfwSetJoystickUserPointer(int jid, void* pointer)
_GLFW_REQUIRE_INIT();
js = _glfw.joysticks + jid;
if (!js->present)
if (!js->allocated)
return;
js->userPointer = pointer;
@@ -1114,7 +1132,7 @@ GLFWAPI void* glfwGetJoystickUserPointer(int jid)
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
js = _glfw.joysticks + jid;
if (!js->present)
if (!js->allocated)
return NULL;
return js->userPointer;
@@ -1180,7 +1198,7 @@ GLFWAPI int glfwUpdateGamepadMappings(const char* string)
for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{
_GLFWjoystick* js = _glfw.joysticks + jid;
if (js->present)
if (js->connected)
js->mapping = findValidMapping(js);
}
@@ -1203,7 +1221,7 @@ GLFWAPI int glfwJoystickIsGamepad(int jid)
}
js = _glfw.joysticks + jid;
if (!js->present)
if (!js->connected)
return GLFW_FALSE;
if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_PRESENCE))
@@ -1228,7 +1246,7 @@ GLFWAPI const char* glfwGetGamepadName(int jid)
}
js = _glfw.joysticks + jid;
if (!js->present)
if (!js->connected)
return NULL;
if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_PRESENCE))
@@ -1260,7 +1278,7 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state)
}
js = _glfw.joysticks + jid;
if (!js->present)
if (!js->connected)
return GLFW_FALSE;
if (!_glfwPlatformPollJoystick(js, _GLFW_POLL_ALL))
@@ -1369,3 +1387,4 @@ GLFWAPI uint64_t glfwGetTimerFrequency(void)
_GLFW_REQUIRE_INIT_OR_RETURN(0);
return _glfwPlatformGetTimerFrequency();
}