Blob Blame History Raw
From 5dc180ef7308b44f19f61ffb39e1c2df507731e2 Mon Sep 17 00:00:00 2001
From: rcaridade145 <rcaridade145@gmail.com>
Date: Sat, 29 Feb 2020 13:01:36 +0000
Subject: [PATCH 2/4] compositor: fix possible crash closing/destroying window
 . Fixes to previous commit.

Partially restore call to destroy_win in compositor when calling
meta_window_free. This is needed to ensure that we never call
meta_window_get_frame_bounds while windows is destroying.

https://bugzilla.gnome.org/show_bug.cgi?id=751833

Based on commit https://gitlab.gnome.org/GNOME/metacity/-/commit/a9f28dbc26f5211ef08889109db3dc8c7ba76aca
---
 src/compositor/compositor-private.h |  3 +++
 src/compositor/compositor-xrender.c | 36 +++++++++++++++++++++--------
 src/compositor/compositor.c         |  4 ++++
 src/core/window-private.h           |  3 +++
 src/core/window.c                   | 11 +++++++++
 5 files changed, 48 insertions(+), 9 deletions(-)

diff --git a/src/compositor/compositor-private.h b/src/compositor/compositor-private.h
index fcb15187..1fa64695 100644
--- a/src/compositor/compositor-private.h
+++ b/src/compositor/compositor-private.h
@@ -50,6 +50,9 @@ struct _MetaCompositor
                              MetaScreen     *screen,
                              MetaWindow     *window);
 
+  void (*free_window) (MetaCompositor *compositor,
+                       MetaWindow     *window);
+
   void (*maximize_window)   (MetaCompositor *compositor,
                              MetaWindow     *window);
   void (*unmaximize_window) (MetaCompositor *compositor,
diff --git a/src/compositor/compositor-xrender.c b/src/compositor/compositor-xrender.c
index 4a05bc7a..43a76394 100644
--- a/src/compositor/compositor-xrender.c
+++ b/src/compositor/compositor-xrender.c
@@ -3045,22 +3045,39 @@ xrender_end_move (MetaCompositor *compositor,
 #endif
 }
 
+#endif /* 0 */
+
 static void
 xrender_free_window (MetaCompositor *compositor,
                      MetaWindow     *window)
 {
 #ifdef HAVE_COMPOSITE_EXTENSIONS
-  /* FIXME: When an undecorated window is hidden this is called,
-     but the window does not get readded if it is subsequentally shown again
-     See http://bugzilla.gnome.org/show_bug.cgi?id=504876
-
-     I don't *think* theres any need for this call anyway, leaving it out
-     does not seem to cause any side effects so far, but I should check with
-     someone who understands more. */
-  /* destroy_win (compositor->display, window->xwindow, FALSE); */
+  MetaCompositorXRender *xrc;
+  MetaFrame *frame;
+  Window xwindow;
+
+  xrc = (MetaCompositorXRender *) compositor;
+  frame = meta_window_get_frame (window);
+  xwindow = None;
+
+  if (frame)
+    {
+      xwindow = meta_frame_get_xwindow (frame);
+    }
+  else
+    {
+      /* FIXME: When an undecorated window is hidden this is called, but the
+       * window does not get readded if it is subsequentally shown again. See:
+       * http://bugzilla.gnome.org/show_bug.cgi?id=504876
+       */
+      /* xwindow = meta_window_get_xwindow (window); */
+    }
+
+  if (xwindow != None)
+    destroy_win (xrc->display, xwindow, FALSE);
 #endif
 }
-#endif /* 0 */
+
 
 static void
 xrender_process_event (MetaCompositor *compositor,
@@ -3364,6 +3381,7 @@ static MetaCompositor comp_info = {
   xrender_process_event,
   xrender_get_window_surface,
   xrender_set_active_window,
+  xrender_free_window,
   xrender_maximize_window,
   xrender_unmaximize_window,
 };
diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c
index 7e3c79c2..68f54d92 100644
--- a/src/compositor/compositor.c
+++ b/src/compositor/compositor.c
@@ -156,6 +156,10 @@ void meta_compositor_end_move (MetaCompositor *compositor,
 void meta_compositor_free_window (MetaCompositor *compositor,
                                   MetaWindow     *window)
 {
+  #ifdef HAVE_COMPOSITE_EXTENSIONS
+  if (compositor && compositor->free_window)
+    compositor->free_window (compositor, window);
+  #endif
 }
 
 void
diff --git a/src/core/window-private.h b/src/core/window-private.h
index 5abef1e1..ca631966 100644
--- a/src/core/window-private.h
+++ b/src/core/window-private.h
@@ -618,6 +618,9 @@ void meta_window_set_gravity (MetaWindow *window,
 void meta_window_handle_mouse_grab_op_event (MetaWindow *window,
                                              XEvent     *event);
 
+MetaWorkspace *
+meta_window_get_workspace (MetaWindow *window);
+
 GList* meta_window_get_workspaces (MetaWindow *window);
 
 gboolean meta_window_located_on_workspace (MetaWindow    *window,
diff --git a/src/core/window.c b/src/core/window.c
index 21d605e2..603bedf3 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -6214,6 +6214,17 @@ idle_update_icon (gpointer data)
   return FALSE;
 }
 
+
+MetaWorkspace *
+meta_window_get_workspace (MetaWindow *window)
+{
+  if (window->on_all_workspaces)
+    return window->screen->active_workspace;
+  else
+    return window->workspace;
+}
+
+
 GList*
 meta_window_get_workspaces (MetaWindow *window)
 {
-- 
2.21.1