SDL: wayland: Simplify resize logic

From 37672f52da6407ba548a91166688b178cae49c21 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Thu, 23 May 2024 10:23:57 -0400
Subject: [PATCH] wayland: Simplify resize logic

Non-size configuration events are filtered out, so there is no need to enqueue an event when setting the size, as it won't be overwritten in the configure event when only changing state.
---
 src/video/wayland/SDL_waylandwindow.c | 58 +++++++--------------------
 src/video/wayland/SDL_waylandwindow.h |  8 ----
 2 files changed, 15 insertions(+), 51 deletions(-)

diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index 173f89e4df0de..c84cdd7c7945f 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -2430,58 +2430,30 @@ int Wayland_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
     return SDL_SetError("wayland cannot position non-popup windows");
 }
 
-static void size_event_handler(void *data, struct wl_callback *callback, uint32_t callback_data)
-{
-    /* Get the window from the ID as it may have been destroyed */
-    SDL_WindowID windowID = (SDL_WindowID)((uintptr_t)data);
-    SDL_Window *window = SDL_GetWindowFromID(windowID);
-
-    if (window && window->driverdata) {
-        SDL_WindowData *wind = window->driverdata;
-
-        /* Fullscreen windows do not get explicitly resized, and not strictly
-         * obeying the size of maximized windows is a protocol violation.
-         */
-        if (!(window->flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_MAXIMIZED))) {
-            wind->requested.width = wind->pending_size_event.width;
-            wind->requested.height = wind->pending_size_event.height;
-            if (wind->scale_to_display) {
-                wind->requested.logical_width = PixelToPoint(window, wind->pending_size_event.width);
-                wind->requested.logical_height = PixelToPoint(window, wind->pending_size_event.height);
-            }
-
-            ConfigureWindowGeometry(window);
-        }
-
-        /* Always commit, as this may be in response to a min/max limit change. */
-        CommitLibdecorFrame(window);
-    }
-
-    wl_callback_destroy(callback);
-}
-
-static struct wl_callback_listener size_event_listener = {
-    size_event_handler
-};
-
 void Wayland_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window)
 {
     SDL_WindowData *wind = window->driverdata;
 
-    if (wind->shell_surface_type != WAYLAND_SURFACE_CUSTOM) {
-        /* Queue an event to send the window size. */
-        struct wl_callback *cb = wl_display_sync(_this->driverdata->display);
-
-        wind->pending_size_event.width = window->floating.w;
-        wind->pending_size_event.height = window->floating.h;
-        wl_callback_add_listener(cb, &size_event_listener, (void *)((uintptr_t)window->id));
-    } else {
-        /* We are being informed of a size change on a custom surface, just configure. */
+    /* Fullscreen windows do not get explicitly resized, and not strictly
+     * obeying the size of maximized windows is a protocol violation.
+     *
+     * Calling this on a custom surface is informative, so the size must
+     * always be passed through.
+     */
+    if (!(window->flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_MAXIMIZED)) ||
+        wind->shell_surface_type == WAYLAND_SURFACE_CUSTOM) {
         wind->requested.width = window->floating.w;
         wind->requested.height = window->floating.h;
+        if (wind->scale_to_display) {
+            wind->requested.logical_width = PixelToPoint(window, window->floating.w);
+            wind->requested.logical_height = PixelToPoint(window, window->floating.h);
+        }
 
         ConfigureWindowGeometry(window);
     }
+
+    /* Always commit, as this may be in response to a min/max limit change. */
+    CommitLibdecorFrame(window);
 }
 
 void Wayland_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int *w, int *h)
diff --git a/src/video/wayland/SDL_waylandwindow.h b/src/video/wayland/SDL_waylandwindow.h
index b490aa206d43e..895c740a982d6 100644
--- a/src/video/wayland/SDL_waylandwindow.h
+++ b/src/video/wayland/SDL_waylandwindow.h
@@ -114,14 +114,6 @@ struct SDL_WindowData
         float y;
     } pointer_scale;
 
-    /* The current pending user requested resize event. */
-    struct
-    {
-        /* These units can represent points or pixels, depending on the scaling mode. */
-        int width;
-        int height;
-    } pending_size_event;
-
     /* The in-flight window size request. */
     struct
     {