SDL: wayland: libdecor support for GetWindowWMInfo

From 93976ade3ba5cafcd2a410ab323645f53f5c28c2 Mon Sep 17 00:00:00 2001
From: Ethan Lee <[EMAIL REDACTED]>
Date: Wed, 28 Jul 2021 12:22:09 -0400
Subject: [PATCH] wayland: libdecor support for GetWindowWMInfo

---
 src/video/wayland/SDL_waylanddyn.h    |  1 +
 src/video/wayland/SDL_waylandsym.h    |  1 +
 src/video/wayland/SDL_waylandwindow.c | 12 +++++++++++-
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/video/wayland/SDL_waylanddyn.h b/src/video/wayland/SDL_waylanddyn.h
index 567c7bcea..62963a505 100644
--- a/src/video/wayland/SDL_waylanddyn.h
+++ b/src/video/wayland/SDL_waylanddyn.h
@@ -138,6 +138,7 @@ void SDL_WAYLAND_UnloadSymbols(void);
 #define libdecor_frame_set_visibility (*WAYLAND_libdecor_frame_set_visibility)
 #define libdecor_frame_is_visible (*WAYLAND_libdecor_frame_is_visible)
 #define libdecor_frame_is_floating (*WAYLAND_libdecor_frame_is_floating)
+#define libdecor_frame_get_xdg_surface (*WAYLAND_libdecor_frame_get_xdg_surface)
 #define libdecor_frame_map (*WAYLAND_libdecor_frame_map)
 #define libdecor_state_new (*WAYLAND_libdecor_state_new)
 #define libdecor_state_free (*WAYLAND_libdecor_state_free)
diff --git a/src/video/wayland/SDL_waylandsym.h b/src/video/wayland/SDL_waylandsym.h
index e14d33fdb..5e25e8973 100644
--- a/src/video/wayland/SDL_waylandsym.h
+++ b/src/video/wayland/SDL_waylandsym.h
@@ -179,6 +179,7 @@ SDL_WAYLAND_SYM(bool, libdecor_frame_has_capability, (struct libdecor_frame *, \
 SDL_WAYLAND_SYM(void, libdecor_frame_set_visibility, (struct libdecor_frame *, bool))
 SDL_WAYLAND_SYM(bool, libdecor_frame_is_visible, (struct libdecor_frame *))
 SDL_WAYLAND_SYM(bool, libdecor_frame_is_floating, (struct libdecor_frame *))
+SDL_WAYLAND_SYM(struct xdg_surface *, libdecor_frame_get_xdg_surface, (struct libdecor_frame *))
 SDL_WAYLAND_SYM(void, libdecor_frame_map, (struct libdecor_frame *))
 SDL_WAYLAND_SYM(struct libdecor_state *, libdecor_state_new, (int, int))
 SDL_WAYLAND_SYM(void, libdecor_state_free, (struct libdecor_state *))
diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index f4e4f5a4d..424a6a654 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -536,6 +536,7 @@ static const struct wl_surface_listener surface_listener = {
 SDL_bool
 Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
 {
+    SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata;
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     const Uint32 version = SDL_VERSIONNUM((Uint32)info->version.major,
                                           (Uint32)info->version.minor,
@@ -564,7 +565,16 @@ Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
     }
 
     info->info.wl.shell_surface = NULL;
-    info->info.wl.xdg_surface = data->shell_surface.xdg.surface;
+#ifdef HAVE_LIBDECOR_H
+    if (viddata->shell.libdecor && data->shell_surface.libdecor.frame != NULL) {
+        info->info.wl.xdg_surface = libdecor_frame_get_xdg_surface(data->shell_surface.libdecor.frame);
+    } else
+#endif
+    if (viddata->shell.xdg && data->shell_surface.xdg.surface != NULL) {
+        info->info.wl.xdg_surface = data->shell_surface.xdg.surface;
+    } else {
+        info->info.wl.xdg_surface = NULL;
+    }
 
 
     info->subsystem = SDL_SYSWM_WAYLAND;