GLFW: Cleanup

From upstream: f771d41292.
This commit is contained in:
Luflosi 2020-07-23 13:52:28 +02:00
parent 785973bb5e
commit 06b30d1cc3
No known key found for this signature in database
GPG Key ID: 4E41E29EDCC345D0
2 changed files with 44 additions and 57 deletions

View File

@ -291,11 +291,9 @@ static void removeCallback(void* context UNUSED,
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////// GLFW internal API ////// ////// GLFW platform API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// Initialize joystick interface
//
bool _glfwPlatformInitJoysticks(void) bool _glfwPlatformInitJoysticks(void)
{ {
CFMutableArrayRef matching; CFMutableArrayRef matching;
@ -373,8 +371,6 @@ bool _glfwPlatformInitJoysticks(void)
return true; return true;
} }
// Close all opened joystick handles
//
void _glfwPlatformTerminateJoysticks(void) void _glfwPlatformTerminateJoysticks(void)
{ {
int jid; int jid;
@ -390,10 +386,6 @@ void _glfwPlatformTerminateJoysticks(void)
} }
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode) int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode)
{ {
if (mode & _GLFW_POLL_AXES) if (mode & _GLFW_POLL_AXES)

91
glfw/linux_joystick.c vendored
View File

@ -264,8 +264,49 @@ static int compareJoysticks(const void* fp, const void* sp)
////// GLFW internal API ////// ////// GLFW internal API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// Initialize joystick interface void _glfwDetectJoystickConnectionLinux(void)
// {
if (_glfw.linjs.inotify <= 0)
return;
ssize_t offset = 0;
char buffer[16384];
const ssize_t size = read(_glfw.linjs.inotify, buffer, sizeof(buffer));
while (size > offset)
{
regmatch_t match;
const struct inotify_event* e = (struct inotify_event*) (buffer + offset);
offset += sizeof(struct inotify_event) + e->len;
if (regexec(&_glfw.linjs.regex, e->name, 1, &match, 0) != 0)
continue;
char path[PATH_MAX];
snprintf(path, sizeof(path), "/dev/input/%s", e->name);
if (e->mask & (IN_CREATE | IN_ATTRIB))
openJoystickDevice(path);
else if (e->mask & IN_DELETE)
{
for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{
if (strcmp(_glfw.joysticks[jid].linjs.path, path) == 0)
{
closeJoystick(_glfw.joysticks + jid);
break;
}
}
}
}
}
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
bool _glfwPlatformInitJoysticks(void) bool _glfwPlatformInitJoysticks(void)
{ {
const char* dirname = "/dev/input"; const char* dirname = "/dev/input";
@ -320,8 +361,6 @@ bool _glfwPlatformInitJoysticks(void)
return true; return true;
} }
// Close all opened joystick handles
//
void _glfwPlatformTerminateJoysticks(void) void _glfwPlatformTerminateJoysticks(void)
{ {
int jid; int jid;
@ -343,50 +382,6 @@ void _glfwPlatformTerminateJoysticks(void)
} }
} }
void _glfwDetectJoystickConnectionLinux(void)
{
if (_glfw.linjs.inotify <= 0)
return;
ssize_t offset = 0;
char buffer[16384];
const ssize_t size = read(_glfw.linjs.inotify, buffer, sizeof(buffer));
while (size > offset)
{
regmatch_t match;
const struct inotify_event* e = (struct inotify_event*) (buffer + offset);
offset += sizeof(struct inotify_event) + e->len;
if (regexec(&_glfw.linjs.regex, e->name, 1, &match, 0) != 0)
continue;
char path[PATH_MAX];
snprintf(path, sizeof(path), "/dev/input/%s", e->name);
if (e->mask & (IN_CREATE | IN_ATTRIB))
openJoystickDevice(path);
else if (e->mask & IN_DELETE)
{
for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{
if (strcmp(_glfw.joysticks[jid].linjs.path, path) == 0)
{
closeJoystick(_glfw.joysticks + jid);
break;
}
}
}
}
}
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode UNUSED) int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode UNUSED)
{ {
// Read all queued events (non-blocking) // Read all queued events (non-blocking)