From f3e32cae5164841a3dd2858c956dd78b6017f272 Mon Sep 17 00:00:00 2001
From: Olivier Fourdan <ofourdan@redhat.com>
Date: Thu, 12 May 2022 15:24:49 +0200
Subject: [PATCH] xwayland: keep the xdg_toplevel around

The xdg_toplevel object was used solely when creating the window
surface, and the value of the object discarded.

To be able to make the surface fullscreen using the xdg_toplevel
protocol, we need to have access that object, so keep it around along
with the xwl_window.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
---
 hw/xwayland/xwayland-window.c | 11 +++++++++--
 hw/xwayland/xwayland-window.h |  1 +
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/hw/xwayland/xwayland-window.c b/hw/xwayland/xwayland-window.c
index 919c0a0ca9..2c6b74fce6 100644
--- a/hw/xwayland/xwayland-window.c
+++ b/hw/xwayland/xwayland-window.c
@@ -483,14 +483,19 @@ ensure_surface_for_window(WindowPtr window)
             goto err_surf;
         }
 
+        xwl_window->xdg_toplevel =
+            xdg_surface_get_toplevel(xwl_window->xdg_surface);
+        if (xwl_window->xdg_surface == NULL) {
+            ErrorF("Failed creating xdg_toplevel\n");
+            goto err_surf;
+        }
+
         wl_surface_add_listener(xwl_window->surface,
                                 &surface_listener, xwl_window);
 
         xdg_surface_add_listener(xwl_window->xdg_surface,
                                  &xdg_surface_listener, xwl_window);
 
-        xdg_surface_get_toplevel(xwl_window->xdg_surface);
-
         wl_surface_commit(xwl_window->surface);
 
         region = wl_compositor_create_region(xwl_screen->compositor);
@@ -540,6 +545,8 @@ ensure_surface_for_window(WindowPtr window)
     return TRUE;
 
 err_surf:
+    if (xwl_window->xdg_toplevel)
+        xdg_toplevel_destroy(xwl_window->xdg_toplevel);
     if (xwl_window->xdg_surface)
         xdg_surface_destroy(xwl_window->xdg_surface);
     wl_surface_destroy(xwl_window->surface);
diff --git a/hw/xwayland/xwayland-window.h b/hw/xwayland/xwayland-window.h
index 9739af17c5..1975b749c0 100644
--- a/hw/xwayland/xwayland-window.h
+++ b/hw/xwayland/xwayland-window.h
@@ -43,6 +43,7 @@ struct xwl_window {
     struct wp_viewport *viewport;
     float scale_x, scale_y;
     struct xdg_surface *xdg_surface;
+    struct xdg_toplevel *xdg_toplevel;
     WindowPtr window;
     struct xorg_list link_damage;
     struct xorg_list link_window;
-- 
GitLab