diff --git a/README.md b/README.md index 23cc069a..fefaf500 100644 --- a/README.md +++ b/README.md @@ -271,6 +271,7 @@ information on what to include when reporting a bug. - [X11] Bugfix: Waiting for events would fail if file descriptor was too large (#2024) - [X11] Bugfix: Joystick events could lead to busy-waiting (#1872) + - [X11] Bugfix: `glfwWaitEvents*` did not continue for joystick events - [Wayland] Added dynamic loading of all Wayland libraries - [Wayland] Added support for key names via xkbcommon - [Wayland] Removed support for `wl_shell` (#1443) diff --git a/src/x11_window.c b/src/x11_window.c index 122db2ba..c42be084 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -98,7 +98,14 @@ static GLFWbool waitForData(struct pollfd* fds, nfds_t count, double* timeout) static GLFWbool waitForX11Event(double* timeout) { struct pollfd fd = { ConnectionNumber(_glfw.x11.display), POLLIN }; - return waitForData(&fd, 1, timeout); + + while (!XPending(_glfw.x11.display)) + { + if (!waitForData(&fd, 1, timeout)) + return GLFW_FALSE; + } + + return GLFW_TRUE; } // Wait for event data to arrive on any event file descriptor @@ -115,7 +122,19 @@ static GLFWbool waitForAnyEvent(double* timeout) fds[count++] = (struct pollfd) { _glfw.linjs.inotify, POLLIN }; #endif - return waitForData(fds, count, timeout); + while (!XPending(_glfw.x11.display)) + { + if (!waitForData(fds, count, timeout)) + return GLFW_FALSE; + + for (int i = 1; i < count; i++) + { + if (fds[i].revents & POLLIN) + return GLFW_TRUE; + } + } + + return GLFW_TRUE; } // Waits until a VisibilityNotify event arrives for the specified window or the @@ -2794,20 +2813,13 @@ void _glfwPollEventsX11(void) void _glfwWaitEventsX11(void) { - while (!XPending(_glfw.x11.display)) - waitForAnyEvent(NULL); - + waitForAnyEvent(NULL); _glfwPollEventsX11(); } void _glfwWaitEventsTimeoutX11(double timeout) { - while (!XPending(_glfw.x11.display)) - { - if (!waitForAnyEvent(&timeout)) - break; - } - + waitForAnyEvent(&timeout); _glfwPollEventsX11(); }