From 6d26adc612acdf1910479a3fd12ad84ad3fbc930 Mon Sep 17 00:00:00 2001 From: Doug Binks Date: Wed, 26 Nov 2025 11:57:29 +0000 Subject: [PATCH 1/7] Ensure we read other events even if we cannot read wayland ones --- src/wl_window.c | 96 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 31 deletions(-) diff --git a/src/wl_window.c b/src/wl_window.c index 4220d17e0..f1d5dbe6c 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1356,6 +1356,7 @@ static void handleEvents(double* timeout) #endif GLFWbool event = GLFW_FALSE; + GLFWbool wlcanread = GLFW_FALSE; enum { DISPLAY_FD, KEYREPEAT_FD, CURSOR_FD, LIBDECOR_FD }; struct pollfd fds[] = { @@ -1370,42 +1371,75 @@ static void handleEvents(double* timeout) while (!event) { - while (wl_display_prepare_read(_glfw.wl.display) != 0) + while (!wlcanread && !event) { - if (wl_display_dispatch_pending(_glfw.wl.display) > 0) - return; + if (wl_display_prepare_read(_glfw.wl.display) == 0) + { + wlcanread = GLFW_TRUE; + } + else if (wl_display_dispatch_pending(_glfw.wl.display) > 0) + { + event = GLFW_TRUE; + break; + } } - // If an error other than EAGAIN happens, we have likely been disconnected - // from the Wayland session; try to handle that the best we can. - if (!flushDisplay()) - { - wl_display_cancel_read(_glfw.wl.display); + if (wlcanread) + { + // If an error other than EAGAIN happens, we have likely been disconnected + // from the Wayland session; try to handle that the best we can. + if (!flushDisplay()) + { + wl_display_cancel_read(_glfw.wl.display); - _GLFWwindow* window = _glfw.windowListHead; - while (window) - { - _glfwInputWindowCloseRequest(window); - window = window->next; - } + _GLFWwindow* window = _glfw.windowListHead; + while (window) + { + _glfwInputWindowCloseRequest(window); + window = window->next; + } - return; - } + return; + } - if (!_glfwPollPOSIX(fds, sizeof(fds) / sizeof(fds[0]), timeout)) - { - wl_display_cancel_read(_glfw.wl.display); - return; - } + if (!_glfwPollPOSIX(fds, sizeof(fds) / sizeof(fds[0]), timeout)) + { + wl_display_cancel_read(_glfw.wl.display); + return; + } - if (fds[DISPLAY_FD].revents & POLLIN) - { - wl_display_read_events(_glfw.wl.display); - if (wl_display_dispatch_pending(_glfw.wl.display) > 0) - event = GLFW_TRUE; - } - else - wl_display_cancel_read(_glfw.wl.display); + if (fds[DISPLAY_FD].revents & POLLIN) + { + wl_display_read_events(_glfw.wl.display); + if (wl_display_dispatch_pending(_glfw.wl.display) > 0) + event = GLFW_TRUE; + } + else + wl_display_cancel_read(_glfw.wl.display); + } + else + { + if (!flushDisplay()) + { + _GLFWwindow* window = _glfw.windowListHead; + while (window) + { + _glfwInputWindowCloseRequest(window); + window = window->next; + } + + return; + } + + fds[DISPLAY_FD].fd = -1; // ignore wl events + fds[LIBDECOR_FD].fd = -1; + //fds[CURSOR_FD].fd = -1; + double notimeout = 0.0; + if (!_glfwPollPOSIX(fds, sizeof(fds) / sizeof(fds[0]), ¬imeout)) + { + return; + } + } if (fds[KEYREPEAT_FD].revents & POLLIN) { @@ -1431,7 +1465,7 @@ static void handleEvents(double* timeout) } } - if (fds[CURSOR_FD].revents & POLLIN) + if ((fds[CURSOR_FD].fd > 0 ) && (fds[CURSOR_FD].revents & POLLIN)) { uint64_t repeats; @@ -1439,7 +1473,7 @@ static void handleEvents(double* timeout) incrementCursorImage(_glfw.wl.pointerFocus); } - if (fds[LIBDECOR_FD].revents & POLLIN) + if ((fds[LIBDECOR_FD].fd > 0 ) && (fds[LIBDECOR_FD].revents & POLLIN)) { if (libdecor_dispatch(_glfw.wl.libdecor.context, 0) > 0) event = GLFW_TRUE; From eae0dab99f25a8659892ed6890cb9c3c59d680b0 Mon Sep 17 00:00:00 2001 From: Doug Binks Date: Wed, 26 Nov 2025 12:58:52 +0000 Subject: [PATCH 2/7] Fix for wlcanread not being reset --- src/wl_window.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wl_window.c b/src/wl_window.c index f1d5dbe6c..21caeb068 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1371,6 +1371,7 @@ static void handleEvents(double* timeout) while (!event) { + wlcanread = GLFW_FALSE; while (!wlcanread && !event) { if (wl_display_prepare_read(_glfw.wl.display) == 0) From 8a213dcdf1ad7a263b0cd81956ef1ca7139c22f5 Mon Sep 17 00:00:00 2001 From: Doug Binks Date: Wed, 26 Nov 2025 12:59:12 +0000 Subject: [PATCH 3/7] Remove redundant break --- src/wl_window.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wl_window.c b/src/wl_window.c index 21caeb068..6eea54625 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1381,7 +1381,6 @@ static void handleEvents(double* timeout) else if (wl_display_dispatch_pending(_glfw.wl.display) > 0) { event = GLFW_TRUE; - break; } } From 78c2e851b08a4fac7ffdf4723e3756dcd8d418de Mon Sep 17 00:00:00 2001 From: Doug Binks Date: Wed, 26 Nov 2025 13:00:18 +0000 Subject: [PATCH 4/7] Remove flush --- src/wl_window.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/wl_window.c b/src/wl_window.c index 6eea54625..c0ab5d8d6 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1419,18 +1419,6 @@ static void handleEvents(double* timeout) } else { - if (!flushDisplay()) - { - _GLFWwindow* window = _glfw.windowListHead; - while (window) - { - _glfwInputWindowCloseRequest(window); - window = window->next; - } - - return; - } - fds[DISPLAY_FD].fd = -1; // ignore wl events fds[LIBDECOR_FD].fd = -1; //fds[CURSOR_FD].fd = -1; From e917b7753983f8ad9632ef8757b45e38c23a5274 Mon Sep 17 00:00:00 2001 From: Doug Binks Date: Wed, 26 Nov 2025 14:14:01 +0000 Subject: [PATCH 5/7] Ensure we attempt to read wl_display each frame Somewhat convoluted code needs reworking --- src/wl_window.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/wl_window.c b/src/wl_window.c index c0ab5d8d6..0e6394fe2 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1381,6 +1381,10 @@ static void handleEvents(double* timeout) else if (wl_display_dispatch_pending(_glfw.wl.display) > 0) { event = GLFW_TRUE; + if (wl_display_prepare_read(_glfw.wl.display) == 0) + { + wlcanread = GLFW_TRUE; + } } } @@ -1402,7 +1406,16 @@ static void handleEvents(double* timeout) return; } - if (!_glfwPollPOSIX(fds, sizeof(fds) / sizeof(fds[0]), timeout)) + if(event) + { + double notimeout = 0.0; + if (!_glfwPollPOSIX(fds, sizeof(fds) / sizeof(fds[0]), ¬imeout)) + { + wl_display_cancel_read(_glfw.wl.display); + return; + } + } + else if (!_glfwPollPOSIX(fds, sizeof(fds) / sizeof(fds[0]), timeout)) { wl_display_cancel_read(_glfw.wl.display); return; @@ -1420,7 +1433,7 @@ static void handleEvents(double* timeout) else { fds[DISPLAY_FD].fd = -1; // ignore wl events - fds[LIBDECOR_FD].fd = -1; + //fds[LIBDECOR_FD].fd = -1; //fds[CURSOR_FD].fd = -1; double notimeout = 0.0; if (!_glfwPollPOSIX(fds, sizeof(fds) / sizeof(fds[0]), ¬imeout)) From 6cdfa97ca57b0ab92a2409406b47df954394aa23 Mon Sep 17 00:00:00 2001 From: Doug Binks Date: Fri, 28 Nov 2025 09:47:42 +0000 Subject: [PATCH 6/7] Code cleanup and simplification --- src/wl_window.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/wl_window.c b/src/wl_window.c index 0e6394fe2..6fd2cae62 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -1406,16 +1406,12 @@ static void handleEvents(double* timeout) return; } - if(event) - { - double notimeout = 0.0; - if (!_glfwPollPOSIX(fds, sizeof(fds) / sizeof(fds[0]), ¬imeout)) - { - wl_display_cancel_read(_glfw.wl.display); - return; - } - } - else if (!_glfwPollPOSIX(fds, sizeof(fds) / sizeof(fds[0]), timeout)) + double* ptimeout = timeout; + double notimeout = 0.0; + if (event) + ptimeout = ¬imeout; // do not wait if we already have an event + + if (!_glfwPollPOSIX(fds, sizeof(fds) / sizeof(fds[0]), ptimeout)) { wl_display_cancel_read(_glfw.wl.display); return; @@ -1433,8 +1429,6 @@ static void handleEvents(double* timeout) else { fds[DISPLAY_FD].fd = -1; // ignore wl events - //fds[LIBDECOR_FD].fd = -1; - //fds[CURSOR_FD].fd = -1; double notimeout = 0.0; if (!_glfwPollPOSIX(fds, sizeof(fds) / sizeof(fds[0]), ¬imeout)) { @@ -1462,7 +1456,6 @@ static void handleEvents(double* timeout) event = GLFW_TRUE; } - } } From 680cef6aaf47dba74ea1ff9f9ca5fa20e460d41f Mon Sep 17 00:00:00 2001 From: Doug Binks Date: Fri, 28 Nov 2025 09:53:27 +0000 Subject: [PATCH 7/7] Added bugfix to readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9bad25a0f..e73d30a2b 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,8 @@ information on what to include when reporting a bug. from a modal to the content area - [Wayland] Bugfix: free modules at end of terminate function to resolve potential segmentation fault (#2744) + - [Wayland] Bugfix: Events being lost due to some drivers moving events + to the default event queue during buffer swapping (#2793) - [X11] Bugfix: Running without a WM could trigger an assert (#2593,#2601,#2631) - [X11] Bugfix: Occasional crash when an idle display awakes (#2766) - [X11] Bugfix: Prevent BadWindow when creating small windows with a content scale