SDL: wayland: Ignore content sizes from libdecor when hiding a window

From 07aea476bacbf9f4ab557d83b535a38ba0868927 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Sat, 3 Sep 2022 13:30:49 -0400
Subject: [PATCH] wayland: Ignore content sizes from libdecor when hiding a
 window

When hiding a window, libdecor can report bogus content region sizes that are +/- the height of the title bar. Ignore any size values from libdecor when hiding a window, or the size may be incorrect when restored.
---
 src/video/wayland/SDL_waylandwindow.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index c297de1591f..dee65206903 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -897,8 +897,15 @@ decoration_frame_configure(struct libdecor_frame *frame,
         height = window->windowed.h;
         wind->floating_resize_pending = SDL_FALSE;
     } else {
+        /*
+         * XXX: When hiding a floating window, libdecor can send bogus content sizes that
+         *      are +/- the height of the title bar, which distorts the window size.
+         *      Ignore any values from libdecor when hiding a floating window.
+         */
+        const SDL_bool use_cached_size = (window->is_hiding || !!(window->flags & SDL_WINDOW_HIDDEN));
+
         /* This will never set 0 for width/height unless the function returns false */
-        if (!libdecor_configuration_get_content_size(configuration, frame, &width, &height)) {
+        if (use_cached_size || !libdecor_configuration_get_content_size(configuration, frame, &width, &height)) {
             if (floating) {
                 /* This usually happens when we're being restored from a
                  * non-floating state, so use the cached floating size here.