Use C99 instead of hard-coded indices

This commit is contained in:
Camilla Löwy 2024-01-22 21:19:02 +01:00
parent 8946f5314d
commit 77ced84e9c
2 changed files with 19 additions and 17 deletions

View File

@ -1125,16 +1125,17 @@ static void handleEvents(double* timeout)
#endif #endif
GLFWbool event = GLFW_FALSE; GLFWbool event = GLFW_FALSE;
struct pollfd fds[4] = enum { DISPLAY_FD, KEYREPEAT_FD, CURSOR_FD, LIBDECOR_FD };
struct pollfd fds[] =
{ {
{ wl_display_get_fd(_glfw.wl.display), POLLIN }, [DISPLAY_FD] = { wl_display_get_fd(_glfw.wl.display), POLLIN },
{ _glfw.wl.keyRepeatTimerfd, POLLIN }, [KEYREPEAT_FD] = { _glfw.wl.keyRepeatTimerfd, POLLIN },
{ _glfw.wl.cursorTimerfd, POLLIN }, [CURSOR_FD] = { _glfw.wl.cursorTimerfd, POLLIN },
{ -1, POLLIN } [LIBDECOR_FD] = { -1, POLLIN }
}; };
if (_glfw.wl.libdecor.context) if (_glfw.wl.libdecor.context)
fds[3].fd = libdecor_get_fd(_glfw.wl.libdecor.context); fds[LIBDECOR_FD].fd = libdecor_get_fd(_glfw.wl.libdecor.context);
while (!event) while (!event)
{ {
@ -1166,7 +1167,7 @@ static void handleEvents(double* timeout)
return; return;
} }
if (fds[0].revents & POLLIN) if (fds[DISPLAY_FD].revents & POLLIN)
{ {
wl_display_read_events(_glfw.wl.display); wl_display_read_events(_glfw.wl.display);
if (wl_display_dispatch_pending(_glfw.wl.display) > 0) if (wl_display_dispatch_pending(_glfw.wl.display) > 0)
@ -1175,7 +1176,7 @@ static void handleEvents(double* timeout)
else else
wl_display_cancel_read(_glfw.wl.display); wl_display_cancel_read(_glfw.wl.display);
if (fds[1].revents & POLLIN) if (fds[KEYREPEAT_FD].revents & POLLIN)
{ {
uint64_t repeats; uint64_t repeats;
@ -1195,7 +1196,7 @@ static void handleEvents(double* timeout)
} }
} }
if (fds[2].revents & POLLIN) if (fds[CURSOR_FD].revents & POLLIN)
{ {
uint64_t repeats; uint64_t repeats;
@ -1203,7 +1204,7 @@ static void handleEvents(double* timeout)
incrementCursorImage(_glfw.wl.pointerFocus); incrementCursorImage(_glfw.wl.pointerFocus);
} }
if (fds[3].revents & POLLIN) if (fds[LIBDECOR_FD].revents & POLLIN)
{ {
if (libdecor_dispatch(_glfw.wl.libdecor.context, 0) > 0) if (libdecor_dispatch(_glfw.wl.libdecor.context, 0) > 0)
event = GLFW_TRUE; event = GLFW_TRUE;

View File

@ -79,24 +79,25 @@ static GLFWbool waitForX11Event(double* timeout)
// //
static GLFWbool waitForAnyEvent(double* timeout) static GLFWbool waitForAnyEvent(double* timeout)
{ {
nfds_t count = 2; enum { XLIB_FD, PIPE_FD, INOTIFY_FD };
struct pollfd fds[3] = struct pollfd fds[] =
{ {
{ ConnectionNumber(_glfw.x11.display), POLLIN }, [XLIB_FD] = { ConnectionNumber(_glfw.x11.display), POLLIN },
{ _glfw.x11.emptyEventPipe[0], POLLIN } [PIPE_FD] = { _glfw.x11.emptyEventPipe[0], POLLIN },
[INOTIFY_FD] = { -1, POLLIN }
}; };
#if defined(GLFW_BUILD_LINUX_JOYSTICK) #if defined(GLFW_BUILD_LINUX_JOYSTICK)
if (_glfw.joysticksInitialized) if (_glfw.joysticksInitialized)
fds[count++] = (struct pollfd) { _glfw.linjs.inotify, POLLIN }; fds[INOTIFY_FD].fd = _glfw.linjs.inotify;
#endif #endif
while (!XPending(_glfw.x11.display)) while (!XPending(_glfw.x11.display))
{ {
if (!_glfwPollPOSIX(fds, count, timeout)) if (!_glfwPollPOSIX(fds, sizeof(fds) / sizeof(fds[0]), timeout))
return GLFW_FALSE; return GLFW_FALSE;
for (int i = 1; i < count; i++) for (int i = 1; i < sizeof(fds) / sizeof(fds[0]); i++)
{ {
if (fds[i].revents & POLLIN) if (fds[i].revents & POLLIN)
return GLFW_TRUE; return GLFW_TRUE;