SDL: wayland: Data manager touch ups

From 52289a276a1ead29790c714618119f168f2659d0 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Sun, 25 Oct 2026 17:26:26 -0400
Subject: [PATCH] wayland: Data manager touch ups

---
 src/video/wayland/SDL_waylanddatamanager.c |  8 ++++----
 src/video/wayland/SDL_waylanddatamanager.h |  8 ++++----
 src/video/wayland/SDL_waylandevents.c      | 21 +++++++--------------
 3 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/src/video/wayland/SDL_waylanddatamanager.c b/src/video/wayland/SDL_waylanddatamanager.c
index 7d0b492e14d38..116d6e04e80af 100644
--- a/src/video/wayland/SDL_waylanddatamanager.c
+++ b/src/video/wayland/SDL_waylanddatamanager.c
@@ -1148,10 +1148,10 @@ static const struct zwp_primary_selection_device_v1_listener primary_selection_d
     primary_selection_device_handle_selection
 };
 
-static void Wayland_DataDeviceSetID(Wayland_DataDevice *data_device)
+static void DataDeviceSetID(Wayland_DataDevice *data_device)
 {
-    if (!data_device->id_str)
 #ifdef SDL_USE_LIBDBUS
+    if (!data_device->id_str)
     {
         SDL_DBusContext *dbus = SDL_DBus_GetContext();
         if (dbus) {
@@ -1161,8 +1161,8 @@ static void Wayland_DataDeviceSetID(Wayland_DataDevice *data_device)
             }
         }
     }
-    if (!data_device->id_str)
 #endif
+    if (!data_device->id_str)
     {
         char id[24];
         Uint64 pid = (Uint64)getpid();
@@ -1190,7 +1190,7 @@ bool Wayland_CreateDataDevice(SDL_WaylandSeat *seat)
         return false;
     }
 
-    Wayland_DataDeviceSetID(data_device);
+    DataDeviceSetID(data_device);
     WAYLAND_wl_list_init(&data_device->pending_drops);
     wl_data_device_set_user_data(data_device->data_device, data_device);
     wl_data_device_add_listener(data_device->data_device, &data_device_listener, data_device);
diff --git a/src/video/wayland/SDL_waylanddatamanager.h b/src/video/wayland/SDL_waylanddatamanager.h
index 275185f0938c7..5e148ea621f14 100644
--- a/src/video/wayland/SDL_waylanddatamanager.h
+++ b/src/video/wayland/SDL_waylanddatamanager.h
@@ -39,20 +39,20 @@ typedef struct Wayland_PrimarySelectionDevice Wayland_PrimarySelectionDevice;
 // Data device (clipboard and drag & drop)
 extern bool Wayland_CreateDataDevice(SDL_WaylandSeat *seat);
 extern void Wayland_DestroyDataDevice(Wayland_DataDevice *data_device);
+extern bool Wayland_DataDeviceHasSelectionSource(Wayland_DataDevice *data_device);
 extern bool Wayland_DataDeviceSetSelectionSource(Wayland_DataDevice *data_device, const char *const *mime_types, size_t mime_count,
                                                  SDL_ClipboardDataCallback data_callback, SDL_ClipboardCleanupCallback cleanup_callback, void *userdata, Uint32 sequence);
-extern void Wayland_DataDeviceDestroySelectionOffer(Wayland_DataDevice *data_device, bool clear);
 extern bool Wayland_DataDeviceSelectionOfferHasMIME(Wayland_DataDevice *data_device, const char *mime_type);
-extern bool Wayland_DataDeviceHasSelectionSource(Wayland_DataDevice *data_device);
 extern void *Wayland_DataDeviceReceiveSelectionOffer(Wayland_DataDevice *data_device, const char *mime_type, size_t *length);
+extern void Wayland_DataDeviceDestroySelectionOffer(Wayland_DataDevice *data_device, bool clear);
 extern void Wayland_DataDeviceRemoveWindowReferences(Wayland_DataDevice *data_device, SDL_Window *window);
 
 // Primary selection
 extern bool Wayland_CreatePrimarySelectionDevice(SDL_WaylandSeat *seat);
 extern void Wayland_DestroyPrimarySelectionDevice(Wayland_PrimarySelectionDevice *primary_selection_device);
-extern bool Wayland_PrimarySelectionDeviceSetText(Wayland_PrimarySelectionDevice *primary_selection_device, const char *text);
-extern char *Wayland_PrimarySelectionDeviceGetText(Wayland_PrimarySelectionDevice *primary_selection_device, size_t *length);
 extern bool Wayland_PrimarySelectionDeviceHasText(Wayland_PrimarySelectionDevice *primary_selection_device);
+extern char *Wayland_PrimarySelectionDeviceGetText(Wayland_PrimarySelectionDevice *primary_selection_device, size_t *length);
+extern bool Wayland_PrimarySelectionDeviceSetText(Wayland_PrimarySelectionDevice *primary_selection_device, const char *text);
 extern void Wayland_PrimarySelectionDeviceDestroyOffer(Wayland_PrimarySelectionDevice *primary_selection_device);
 
 #endif // SDL_waylanddatamanager_h_
diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c
index 8d6d9b657cebd..76b77c163126d 100644
--- a/src/video/wayland/SDL_waylandevents.c
+++ b/src/video/wayland/SDL_waylandevents.c
@@ -899,7 +899,7 @@ static void pointer_handle_leave(void *data, struct wl_pointer *pointer,
     }
 }
 
-static bool Wayland_ProcessHitTest(SDL_WaylandSeat *seat, Uint32 serial)
+static bool Wayland_ProcessHitTest(SDL_WaylandSeat *seat)
 {
     // Pointer is immobilized, do nothing.
     if (seat->pointer.locked_pointer) {
@@ -908,6 +908,7 @@ static bool Wayland_ProcessHitTest(SDL_WaylandSeat *seat, Uint32 serial)
 
     SDL_WindowData *window_data = seat->pointer.focus;
     SDL_Window *window = window_data->sdlwindow;
+    const Uint32 serial = seat->last_implicit_grab_serial;
 
     if (window->hit_test) {
         static const uint32_t directions[] = {
@@ -931,17 +932,13 @@ static bool Wayland_ProcessHitTest(SDL_WaylandSeat *seat, Uint32 serial)
 #ifdef HAVE_LIBDECOR_H
             if (window_data->shell_surface_type == WAYLAND_SHELL_SURFACE_TYPE_LIBDECOR) {
                 if (window_data->shell_surface.libdecor.frame) {
-                    libdecor_frame_move(window_data->shell_surface.libdecor.frame,
-                                        seat->wl_seat,
-                                        serial);
+                    libdecor_frame_move(window_data->shell_surface.libdecor.frame, seat->wl_seat, serial);
                 }
             } else
 #endif
                 if (window_data->shell_surface_type == WAYLAND_SHELL_SURFACE_TYPE_XDG_TOPLEVEL) {
                 if (window_data->shell_surface.xdg.toplevel.xdg_toplevel) {
-                    xdg_toplevel_move(window_data->shell_surface.xdg.toplevel.xdg_toplevel,
-                                      seat->wl_seat,
-                                      serial);
+                    xdg_toplevel_move(window_data->shell_surface.xdg.toplevel.xdg_toplevel, seat->wl_seat, serial);
                 }
             }
             return true;
@@ -957,18 +954,14 @@ static bool Wayland_ProcessHitTest(SDL_WaylandSeat *seat, Uint32 serial)
 #ifdef HAVE_LIBDECOR_H
             if (window_data->shell_surface_type == WAYLAND_SHELL_SURFACE_TYPE_LIBDECOR) {
                 if (window_data->shell_surface.libdecor.frame) {
-                    libdecor_frame_resize(window_data->shell_surface.libdecor.frame,
-                                          seat->wl_seat,
-                                          serial,
+                    libdecor_frame_resize(window_data->shell_surface.libdecor.frame, seat->wl_seat, serial,
                                           directions_libdecor[window_data->hit_test_result - SDL_HITTEST_RESIZE_TOPLEFT]);
                 }
             } else
 #endif
                 if (window_data->shell_surface_type == WAYLAND_SHELL_SURFACE_TYPE_XDG_TOPLEVEL) {
                 if (window_data->shell_surface.xdg.toplevel.xdg_toplevel) {
-                    xdg_toplevel_resize(window_data->shell_surface.xdg.toplevel.xdg_toplevel,
-                                        seat->wl_seat,
-                                        serial,
+                    xdg_toplevel_resize(window_data->shell_surface.xdg.toplevel.xdg_toplevel, seat->wl_seat, serial,
                                         directions[window_data->hit_test_result - SDL_HITTEST_RESIZE_TOPLEFT]);
                 }
             }
@@ -992,7 +985,7 @@ static void pointer_dispatch_button(SDL_WaylandSeat *seat, Uint8 sdl_button, boo
         if (down) {
             seat->pointer.buttons_pressed |= SDL_BUTTON_MASK(sdl_button);
 
-            if (sdl_button == SDL_BUTTON_LEFT && Wayland_ProcessHitTest(seat, seat->last_implicit_grab_serial)) {
+            if (sdl_button == SDL_BUTTON_LEFT && Wayland_ProcessHitTest(seat)) {
                 return; // don't pass this event on to app.
             }
         } else {