SDL: wayland: Use the implicit grab serial when clearing the clipboard (bfe3a)

From bfe3abdc26f5f543f2352732ee837a3dd65d9b33 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Mon, 22 Dec 2025 09:01:01 -0500
Subject: [PATCH] wayland: Use the implicit grab serial when clearing the
 clipboard

Some compositors won't clear the selection without a valid serial.

(cherry picked from commit 9094395b13cc20b6f2d80ad10717bd74410aa9a5)
---
 src/video/wayland/SDL_waylanddatamanager.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/video/wayland/SDL_waylanddatamanager.c b/src/video/wayland/SDL_waylanddatamanager.c
index 767d1f030dfa3..c51f042ed1c48 100644
--- a/src/video/wayland/SDL_waylanddatamanager.c
+++ b/src/video/wayland/SDL_waylanddatamanager.c
@@ -34,6 +34,8 @@
 
 #include "SDL_waylandvideo.h"
 #include "SDL_waylanddatamanager.h"
+
+#include "SDL_waylandevents_c.h"
 #include "primary-selection-unstable-v1-client-protocol.h"
 
 /* FIXME: This is arbitrary, but we want this to be less than a frame because
@@ -524,7 +526,7 @@ bool Wayland_data_device_clear_selection(SDL_WaylandDataDevice *data_device)
     if (!data_device || !data_device->data_device) {
         result = SDL_SetError("Invalid Data Device");
     } else if (data_device->selection_source) {
-        wl_data_device_set_selection(data_device->data_device, NULL, 0);
+        wl_data_device_set_selection(data_device->data_device, NULL, data_device->video_data->input->last_implicit_grab_serial);
         Wayland_data_source_destroy(data_device->selection_source);
         data_device->selection_source = NULL;
     }
@@ -539,7 +541,7 @@ bool Wayland_primary_selection_device_clear_selection(SDL_WaylandPrimarySelectio
         result = SDL_SetError("Invalid Primary Selection Device");
     } else if (primary_selection_device->selection_source) {
         zwp_primary_selection_device_v1_set_selection(primary_selection_device->primary_selection_device,
-                                                      NULL, 0);
+                                                      NULL, primary_selection_device->video_data->input->last_implicit_grab_serial);
         Wayland_primary_selection_source_destroy(primary_selection_device->selection_source);
         primary_selection_device->selection_source = NULL;
     }