SDL: wayland: Silence a warning if the event thread exits abnormally

From 64bf432beb399f03df543ac2104158f7313aef65 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Tue, 18 Nov 2025 12:24:27 -0500
Subject: [PATCH] wayland: Silence a warning if the event thread exits
 abnormally

Clean up the termination callback if the flush returns with an unrecoverable error to avoid a "queue destroyed while proxies still attached" warning.
---
 src/video/wayland/SDL_waylandmouse.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/video/wayland/SDL_waylandmouse.c b/src/video/wayland/SDL_waylandmouse.c
index 082ebe1eb9ccc..82529adf63557 100644
--- a/src/video/wayland/SDL_waylandmouse.c
+++ b/src/video/wayland/SDL_waylandmouse.c
@@ -463,19 +463,22 @@ static void Wayland_DestroyCursorThread(SDL_VideoData *data)
         WAYLAND_wl_proxy_wrapper_destroy(display_wrapper);
 
         int ret = WAYLAND_wl_display_flush(data->display);
-        if (ret == -1 && errno == EAGAIN) {
-            // The timeout is long, but shutting down the thread requires a successful flush.
-            ret = SDL_IOReady(WAYLAND_wl_display_get_fd(data->display), SDL_IOR_WRITE, SDL_MS_TO_NS(1000));
+        while (ret == -1 && errno == EAGAIN) {
+            // Shutting down the thread requires a successful flush.
+            ret = SDL_IOReady(WAYLAND_wl_display_get_fd(data->display), SDL_IOR_WRITE, -1);
             if (ret >= 0) {
                 ret = WAYLAND_wl_display_flush(data->display);
             }
         }
 
-        // Wait for the thread to return. Don't wait if the flush failed, or this can hang.
-        if (ret >= 0) {
-            SDL_WaitThread(cursor_thread_context.thread, NULL);
+        // Avoid a warning if the flush failed due to a broken connection.
+        if (ret < 0) {
+            wl_callback_destroy(cb);
         }
 
+        // Wait for the thread to return; it will exit automatically on a broken connection.
+        SDL_WaitThread(cursor_thread_context.thread, NULL);
+
         WAYLAND_wl_proxy_wrapper_destroy(cursor_thread_context.compositor_wrapper);
         WAYLAND_wl_event_queue_destroy(cursor_thread_context.queue);
         SDL_DestroyMutex(cursor_thread_context.lock);