From 77ced84e9ce12d7cb4522e134044a1a4582f4dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 22 Jan 2024 21:19:02 +0100 Subject: [PATCH] Use C99 instead of hard-coded indices --- src/wl_window.c | 21 +++++++++++---------- src/x11_window.c | 15 ++++++++------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/wl_window.c b/src/wl_window.c index 13879a12..06b0256f 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1125,16 +1125,17 @@ static void handleEvents(double* timeout) #endif 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 }, - { _glfw.wl.keyRepeatTimerfd, POLLIN }, - { _glfw.wl.cursorTimerfd, POLLIN }, - { -1, POLLIN } + [DISPLAY_FD] = { wl_display_get_fd(_glfw.wl.display), POLLIN }, + [KEYREPEAT_FD] = { _glfw.wl.keyRepeatTimerfd, POLLIN }, + [CURSOR_FD] = { _glfw.wl.cursorTimerfd, POLLIN }, + [LIBDECOR_FD] = { -1, POLLIN } }; 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) { @@ -1166,7 +1167,7 @@ static void handleEvents(double* timeout) return; } - if (fds[0].revents & POLLIN) + if (fds[DISPLAY_FD].revents & POLLIN) { wl_display_read_events(_glfw.wl.display); if (wl_display_dispatch_pending(_glfw.wl.display) > 0) @@ -1175,7 +1176,7 @@ static void handleEvents(double* timeout) else wl_display_cancel_read(_glfw.wl.display); - if (fds[1].revents & POLLIN) + if (fds[KEYREPEAT_FD].revents & POLLIN) { 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; @@ -1203,7 +1204,7 @@ static void handleEvents(double* timeout) incrementCursorImage(_glfw.wl.pointerFocus); } - if (fds[3].revents & POLLIN) + if (fds[LIBDECOR_FD].revents & POLLIN) { if (libdecor_dispatch(_glfw.wl.libdecor.context, 0) > 0) event = GLFW_TRUE; diff --git a/src/x11_window.c b/src/x11_window.c index c2541b9f..a94978cf 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -79,24 +79,25 @@ static GLFWbool waitForX11Event(double* timeout) // static GLFWbool waitForAnyEvent(double* timeout) { - nfds_t count = 2; - struct pollfd fds[3] = + enum { XLIB_FD, PIPE_FD, INOTIFY_FD }; + struct pollfd fds[] = { - { ConnectionNumber(_glfw.x11.display), POLLIN }, - { _glfw.x11.emptyEventPipe[0], POLLIN } + [XLIB_FD] = { ConnectionNumber(_glfw.x11.display), POLLIN }, + [PIPE_FD] = { _glfw.x11.emptyEventPipe[0], POLLIN }, + [INOTIFY_FD] = { -1, POLLIN } }; #if defined(GLFW_BUILD_LINUX_JOYSTICK) if (_glfw.joysticksInitialized) - fds[count++] = (struct pollfd) { _glfw.linjs.inotify, POLLIN }; + fds[INOTIFY_FD].fd = _glfw.linjs.inotify; #endif while (!XPending(_glfw.x11.display)) { - if (!_glfwPollPOSIX(fds, count, timeout)) + if (!_glfwPollPOSIX(fds, sizeof(fds) / sizeof(fds[0]), timeout)) 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) return GLFW_TRUE;