Blob Blame History Raw
From 69c857ee465bf318cf28b549215136f23eb0b4ce Mon Sep 17 00:00:00 2001
From: Carlos Garnacho <carlosg@gnome.org>
Date: Thu, 6 Sep 2018 21:50:21 +0200
Subject: [PATCH] windowManager: listen actively to windows being destroyed
 during WS switch

Prevents gjs from dealing with already dispose()d objects.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/issues/539

(cherry-picked from b087752b5539a8cbb1d61979cb069aef8a3475be)
---
 js/ui/windowManager.js | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/js/ui/windowManager.js b/js/ui/windowManager.js
index 17576a07e..2069d84e1 100644
--- a/js/ui/windowManager.js
+++ b/js/ui/windowManager.js
@@ -1754,6 +1754,14 @@ var WindowManager = new Lang.Class({
             }
         }
 
+        for (let i = 0; i < switchData.windows.length; i++) {
+            let w = switchData.windows[i];
+
+            w.windowDestroyId = w.window.connect('destroy', () => {
+                switchData.windows.splice(switchData.windows.indexOf(w), 1);
+            });
+        }
+
         switchData.inGroup.set_position(-xDest, -yDest);
         switchData.inGroup.raise_top();
 
@@ -1784,8 +1792,8 @@ var WindowManager = new Lang.Class({
 
         for (let i = 0; i < switchData.windows.length; i++) {
                 let w = switchData.windows[i];
-                if (w.window.is_destroyed()) // Window gone
-                    continue;
+                w.window.disconnect(w.windowDestroyId);
+
                 if (w.window.get_parent() == switchData.outGroup) {
                     w.window.reparent(w.parent);
                     w.window.hide();
-- 
2.21.0