From c7a50db7ffaf0eb0c8b06c508ea86e65c86e7ef1 Mon Sep 17 00:00:00 2001
From: Olivier Fourdan <ofourdan@redhat.com>
Date: Thu, 12 May 2022 15:30:38 +0200
Subject: [PATCH] xwayland: keep track of the wl_output enter/leave

Keep track of the output the surface enters/leaves.

This is fairly basic tracking though, we do not keep a full list of
outputs a surface may be covering partially, we just keep the output
the surface entered last.

This is sufficient as a preparation work for fullscreen though.

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

diff --git a/hw/xwayland/xwayland-window.c b/hw/xwayland/xwayland-window.c
index 41061e3448..919c0a0ca9 100644
--- a/hw/xwayland/xwayland-window.c
+++ b/hw/xwayland/xwayland-window.c
@@ -413,6 +413,33 @@ static const struct xdg_surface_listener xdg_surface_listener = {
     xdg_surface_handle_configure,
 };
 
+static void
+xwl_window_surface_enter(void *data,
+                         struct wl_surface *wl_surface,
+                         struct wl_output *wl_output)
+{
+    struct xwl_window *xwl_window = data;
+
+    if (xwl_window->wl_output != wl_output)
+        xwl_window->wl_output = wl_output;
+}
+
+static void
+xwl_window_surface_leave(void *data,
+                         struct wl_surface *wl_surface,
+                         struct wl_output *wl_output)
+{
+    struct xwl_window *xwl_window = data;
+
+    if (xwl_window->wl_output == wl_output)
+        xwl_window->wl_output = NULL;
+}
+
+static const struct wl_surface_listener surface_listener = {
+    xwl_window_surface_enter,
+    xwl_window_surface_leave
+};
+
 static Bool
 ensure_surface_for_window(WindowPtr window)
 {
@@ -456,6 +483,9 @@ ensure_surface_for_window(WindowPtr window)
             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);
 
diff --git a/hw/xwayland/xwayland-window.h b/hw/xwayland/xwayland-window.h
index d94f072049..9739af17c5 100644
--- a/hw/xwayland/xwayland-window.h
+++ b/hw/xwayland/xwayland-window.h
@@ -51,6 +51,7 @@ struct xwl_window {
     struct xorg_list window_buffers_available;
     struct xorg_list window_buffers_unavailable;
     OsTimerPtr window_buffers_timer;
+    struct wl_output *wl_output;
 #ifdef GLAMOR_HAS_GBM
     struct xorg_list frame_callback_list;
     Bool present_flipped;
-- 
GitLab