SDL: wayland: Clear data offers when losing keyboard focus

From 6f79ebe6dd97626e2dfd3172404066093b21edfd Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Wed, 30 Sep 2026 14:54:06 -0400
Subject: [PATCH] wayland: Clear data offers when losing keyboard focus

The spec says that data offers are no longer valid when keyboard focus is lost, and not all compositors automatically send a nil offer when this occurs. In this state, the clipboard would report that data was still available, however, trying to receive it would always fail.
---
 src/video/wayland/SDL_waylandevents.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c
index 722aca62846ee..d2414233fa85c 100644
--- a/src/video/wayland/SDL_waylandevents.c
+++ b/src/video/wayland/SDL_waylandevents.c
@@ -2228,6 +2228,9 @@ static void keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
     if (SDL_GetMouseFocus() == window->sdlwindow && !window->pointer_focus_count && !window->active_touch_count) {
         SDL_SetMouseFocus(NULL);
     }
+
+    // The spec says that data offers are no longer valid when keyboard focus is lost.
+    Wayland_DataDeviceSetSelectionOffer(seat->data_device, NULL);
 }
 
 static bool keyboard_input_get_text(char text[8], const SDL_WaylandSeat *seat, uint32_t key, bool down, bool *handled_by_ime)