From f31f059934ceb88c231f1f467349ed462dacc9e3 Mon Sep 17 00:00:00 2001
From: Olivier Fourdan <ofourdan@redhat.com>
Date: Fri, 29 Apr 2022 10:45:01 +0200
Subject: [PATCH] xwayland: add xdg-toplevel listener

So that when running rootful, the compositor can close the Xwayland
window using the xdg-toplevel protocol.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
---
 hw/xwayland/xwayland-window.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/hw/xwayland/xwayland-window.c b/hw/xwayland/xwayland-window.c
index 6a56ac4240..a8dce8d45a 100644
--- a/hw/xwayland/xwayland-window.c
+++ b/hw/xwayland/xwayland-window.c
@@ -540,6 +540,28 @@ static const struct wl_surface_listener surface_listener = {
     xwl_window_surface_leave
 };
 
+static void
+xdg_toplevel_handle_configure(void *data,
+                              struct xdg_toplevel *xdg_toplevel,
+                              int32_t width,
+                              int32_t height,
+                              struct wl_array *states)
+{
+}
+
+static void
+xdg_toplevel_handle_close(void *data,
+                          struct xdg_toplevel *xdg_toplevel)
+{
+    DebugF("Terminating on compositor request");
+    GiveUp(0);
+}
+
+static const struct xdg_toplevel_listener xdg_toplevel_listener = {
+    xdg_toplevel_handle_configure,
+    xdg_toplevel_handle_close,
+};
+
 static Bool
 xwl_create_root_surface(struct xwl_window *xwl_window)
 {
@@ -567,6 +589,10 @@ xwl_create_root_surface(struct xwl_window *xwl_window)
     xdg_surface_add_listener(xwl_window->xdg_surface,
                              &xdg_surface_listener, xwl_window);
 
+    xdg_toplevel_add_listener(xwl_window->xdg_toplevel,
+                              &xdg_toplevel_listener,
+                              NULL);
+
     xwl_window_rootful_update_title(xwl_window);
 
     wl_surface_commit(xwl_window->surface);
-- 
GitLab