Blame SOURCES/0005-wayland-xdg-shell-Handle-requests-after-toplevel-was.patch

776610
From 80f942773a29889094dbf83aece8d210bd22c73e Mon Sep 17 00:00:00 2001
776610
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
776610
Date: Wed, 25 Jul 2018 11:56:14 +0200
776610
Subject: [PATCH 5/8] wayland/xdg-shell: Handle requests after toplevel was
776610
 unmanaged
776610
776610
A window can be unmanaged without asking the client to do it, for
776610
example as a side effect of a parent window being unmanaged, if the
776610
child window was a attached dialog.
776610
776610
This means that the client might still make requests post updates to it
776610
after that it was unmapped. Handle this gracefully by NULL-checking the
776610
surface's MetaWindow pointer. We're not loosing any state due to this,
776610
as if the client wants to map the same surface again, it needs to either
776610
reassign it the toplevel role, or reset the xdg-toplevel, both resulting
776610
in all state being lost anyway.
776610
776610
https://gitlab.gnome.org/GNOME/mutter/issues/240
776610
(cherry picked from commit 5fd0f62a62a194ffd8e64d177f389912a582f8e1)
776610
---
776610
 src/wayland/meta-wayland-xdg-shell.c | 81 +++++++++++++++++++++++-----
776610
 1 file changed, 68 insertions(+), 13 deletions(-)
776610
776610
diff --git a/src/wayland/meta-wayland-xdg-shell.c b/src/wayland/meta-wayland-xdg-shell.c
776610
index 9e300df6b..bfd8163f7 100644
776610
--- a/src/wayland/meta-wayland-xdg-shell.c
776610
+++ b/src/wayland/meta-wayland-xdg-shell.c
776610
@@ -191,6 +191,11 @@ xdg_toplevel_set_parent (struct wl_client   *client,
776610
 {
776610
   MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource);
776610
   MetaWindow *transient_for = NULL;
776610
+  MetaWindow *window;
776610
+
776610
+  window = surface->window;
776610
+  if (!window)
776610
+    return;
776610
 
776610
   if (parent_resource)
776610
     {
776610
@@ -200,7 +205,7 @@ xdg_toplevel_set_parent (struct wl_client   *client,
776610
       transient_for = parent_surface->window;
776610
     }
776610
 
776610
-  meta_window_set_transient_for (surface->window, transient_for);
776610
+  meta_window_set_transient_for (window, transient_for);
776610
 }
776610
 
776610
 static void
776610
@@ -209,11 +214,16 @@ xdg_toplevel_set_title (struct wl_client   *client,
776610
                         const char         *title)
776610
 {
776610
   MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource);
776610
+  MetaWindow *window;
776610
+
776610
+  window = surface->window;
776610
+  if (!window)
776610
+    return;
776610
 
776610
   if (!g_utf8_validate (title, -1, NULL))
776610
     title = "";
776610
 
776610
-  meta_window_set_title (surface->window, title);
776610
+  meta_window_set_title (window, title);
776610
 }
776610
 
776610
 static void
776610
@@ -222,11 +232,16 @@ xdg_toplevel_set_app_id (struct wl_client   *client,
776610
                          const char         *app_id)
776610
 {
776610
   MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource);
776610
+  MetaWindow *window;
776610
+
776610
+  window = surface->window;
776610
+  if (!window)
776610
+    return;
776610
 
776610
   if (!g_utf8_validate (app_id, -1, NULL))
776610
     app_id = "";
776610
 
776610
-  meta_window_set_wm_class (surface->window, app_id, app_id);
776610
+  meta_window_set_wm_class (window, app_id, app_id);
776610
 }
776610
 
776610
 static void
776610
@@ -239,15 +254,20 @@ xdg_toplevel_show_window_menu (struct wl_client   *client,
776610
 {
776610
   MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
776610
   MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource);
776610
+  MetaWindow *window;
776610
   int monitor_scale;
776610
 
776610
+  window = surface->window;
776610
+  if (!window)
776610
+    return;
776610
+
776610
   if (!meta_wayland_seat_get_grab_info (seat, surface, serial, FALSE, NULL, NULL))
776610
     return;
776610
 
776610
-  monitor_scale = surface->window->monitor->scale;
776610
-  meta_window_show_menu (surface->window, META_WINDOW_MENU_WM,
776610
-                         surface->window->buffer_rect.x + (x * monitor_scale),
776610
-                         surface->window->buffer_rect.y + (y * monitor_scale));
776610
+  monitor_scale = window->monitor->scale;
776610
+  meta_window_show_menu (window, META_WINDOW_MENU_WM,
776610
+                         window->buffer_rect.x + (x * monitor_scale),
776610
+                         window->buffer_rect.y + (y * monitor_scale));
776610
 }
776610
 
776610
 static void
776610
@@ -258,8 +278,13 @@ xdg_toplevel_move (struct wl_client   *client,
776610
 {
776610
   MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
776610
   MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource);
776610
+  MetaWindow *window;
776610
   float x, y;
776610
 
776610
+  window = surface->window;
776610
+  if (!window)
776610
+    return;
776610
+
776610
   if (!meta_wayland_seat_get_grab_info (seat, surface, serial, TRUE, &x, &y))
776610
     return;
776610
 
776610
@@ -298,9 +323,14 @@ xdg_toplevel_resize (struct wl_client   *client,
776610
 {
776610
   MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource);
776610
   MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource);
776610
+  MetaWindow *window;
776610
   gfloat x, y;
776610
   MetaGrabOp grab_op;
776610
 
776610
+  window = surface->window;
776610
+  if (!window)
776610
+    return;
776610
+
776610
   if (!meta_wayland_seat_get_grab_info (seat, surface, serial, TRUE, &x, &y))
776610
     return;
776610
 
776610
@@ -357,7 +387,11 @@ xdg_toplevel_set_maximized (struct wl_client   *client,
776610
                             struct wl_resource *resource)
776610
 {
776610
   MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource);
776610
-  MetaWindow *window = surface->window;
776610
+  MetaWindow *window;
776610
+
776610
+  window = surface->window;
776610
+  if (!window)
776610
+    return;
776610
 
776610
   meta_window_force_placement (window, TRUE);
776610
   meta_window_maximize (window, META_MAXIMIZE_BOTH);
776610
@@ -368,8 +402,13 @@ xdg_toplevel_unset_maximized (struct wl_client   *client,
776610
                               struct wl_resource *resource)
776610
 {
776610
   MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource);
776610
+  MetaWindow *window;
776610
 
776610
-  meta_window_unmaximize (surface->window, META_MAXIMIZE_BOTH);
776610
+  window = surface->window;
776610
+  if (!window)
776610
+    return;
776610
+
776610
+  meta_window_unmaximize (window, META_MAXIMIZE_BOTH);
776610
 }
776610
 
776610
 static void
776610
@@ -378,6 +417,11 @@ xdg_toplevel_set_fullscreen (struct wl_client   *client,
776610
                              struct wl_resource *output_resource)
776610
 {
776610
   MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource);
776610
+  MetaWindow *window;
776610
+
776610
+  window = surface->window;
776610
+  if (!window)
776610
+    return;
776610
 
776610
   if (output_resource)
776610
     {
776610
@@ -385,12 +429,12 @@ xdg_toplevel_set_fullscreen (struct wl_client   *client,
776610
 
776610
       if (output)
776610
         {
776610
-          meta_window_move_to_monitor (surface->window,
776610
+          meta_window_move_to_monitor (window,
776610
                                        output->logical_monitor->number);
776610
         }
776610
     }
776610
 
776610
-  meta_window_make_fullscreen (surface->window);
776610
+  meta_window_make_fullscreen (window);
776610
 }
776610
 
776610
 static void
776610
@@ -398,8 +442,13 @@ xdg_toplevel_unset_fullscreen (struct wl_client   *client,
776610
                                struct wl_resource *resource)
776610
 {
776610
   MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource);
776610
+  MetaWindow *window;
776610
+
776610
+  window = surface->window;
776610
+  if (!window)
776610
+    return;
776610
 
776610
-  meta_window_unmake_fullscreen (surface->window);
776610
+  meta_window_unmake_fullscreen (window);
776610
 }
776610
 
776610
 static void
776610
@@ -407,8 +456,13 @@ xdg_toplevel_set_minimized (struct wl_client   *client,
776610
                             struct wl_resource *resource)
776610
 {
776610
   MetaWaylandSurface *surface = surface_from_xdg_toplevel_resource (resource);
776610
+  MetaWindow *window;
776610
 
776610
-  meta_window_minimize (surface->window);
776610
+  window = surface->window;
776610
+  if (!window)
776610
+    return;
776610
+
776610
+  meta_window_minimize (window);
776610
 }
776610
 
776610
 static const struct xdg_toplevel_interface meta_wayland_xdg_toplevel_interface = {
776610
@@ -639,6 +693,7 @@ meta_wayland_xdg_toplevel_commit (MetaWaylandSurfaceRole  *surface_role,
776610
       meta_wayland_xdg_surface_reset (xdg_surface);
776610
       meta_wayland_actor_surface_queue_frame_callbacks (actor_surface,
776610
                                                         pending);
776610
+
776610
       return;
776610
     }
776610
 
776610
-- 
776610
2.19.0
776610