SDL: wayland: Only check data offer origin data if a source is present

From 7fec6014a85999da3202b5f7feb3c835334c760d Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Sat, 31 Oct 2026 10:41:45 -0400
Subject: [PATCH] wayland: Only check data offer origin data if a source is
 present

Some clipboard managers will copy the entire contents of the clipboard, including the origin metadata, and offer it when the source is cancelled. The origin should only be checked if there is currently an active source to avoid discarding valid offers that may have origin metadata.
---
 src/video/wayland/SDL_waylanddatamanager.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/video/wayland/SDL_waylanddatamanager.c b/src/video/wayland/SDL_waylanddatamanager.c
index 116d6e04e80af..7c2412d49a96e 100644
--- a/src/video/wayland/SDL_waylanddatamanager.c
+++ b/src/video/wayland/SDL_waylanddatamanager.c
@@ -648,14 +648,14 @@ static void SelectionOfferNotifyFromMIMEs(Wayland_DataDevice *data_device, bool
     SDL_SendClipboardUpdate(false, new_mime_types, num_formats);
 }
 
-static void DataDeviceSetOffer(Wayland_DataDevice *data_device, Wayland_DataOffer *offer)
+static void SetSelectionOffer(Wayland_DataDevice *data_device, Wayland_DataOffer *offer)
 {
     // Don't notify when clearing the old selection offer if doing so will inadvertently clear the selection source.
     const bool notify = offer || (!offer && data_device->selection_offer && (!data_device->selection_offer->callback || !data_device->selection_source));
     DestroyDataOffer(data_device->selection_offer);
     data_device->selection_offer = offer;
     if (notify) {
-        SelectionOfferNotifyFromMIMEs(data_device, true);
+        SelectionOfferNotifyFromMIMEs(data_device, data_device->selection_source != NULL);
     }
 }
 
@@ -1095,7 +1095,7 @@ static void data_device_handle_selection(void *data, struct wl_data_device *wl_d
                  ". In data_device_listener . data_device_handle_selection on data_offer 0x%08x",
                  (id ? WAYLAND_wl_proxy_get_id((struct wl_proxy *)id) : -1));
 
-    DataDeviceSetOffer(data_device, offer);
+    SetSelectionOffer(data_device, offer);
 }
 
 static const struct wl_data_device_listener data_device_listener = {
@@ -1276,7 +1276,7 @@ void Wayland_DataDeviceDestroySelectionOffer(Wayland_DataDevice *data_device, bo
 {
     if (data_device) {
         if (clear) {
-            DataDeviceSetOffer(data_device, NULL);
+            SetSelectionOffer(data_device, NULL);
         } else {
             DestroyDataOffer(data_device->selection_offer);
             data_device->selection_offer = NULL;