|
|
|
@ -264,8 +264,49 @@ static int compareJoysticks(const void* fp, const void* sp) |
|
|
|
|
////// 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 //////
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
GLFWbool _glfwPlatformInitJoysticks(void) |
|
|
|
|
{ |
|
|
|
|
const char* dirname = "/dev/input"; |
|
|
|
@ -320,8 +361,6 @@ GLFWbool _glfwPlatformInitJoysticks(void) |
|
|
|
|
return GLFW_TRUE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Close all opened joystick handles
|
|
|
|
|
//
|
|
|
|
|
void _glfwPlatformTerminateJoysticks(void) |
|
|
|
|
{ |
|
|
|
|
int jid; |
|
|
|
@ -343,49 +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) |
|
|
|
|
{ |
|
|
|
|
// Read all queued events (non-blocking)
|
|
|
|
|