From 7cfb84d6fdf091c2c28a60687567ca5d277d5efd Mon Sep 17 00:00:00 2001
From: Alexander Tuxen <tuxen@silpion.de>
Date: Tue, 18 Oct 2022 16:31:02 +0200
Subject: [PATCH] added cleanup for frozen id list

---
 multiscreen-compositor/qml/IviChrome.qml |  2 --
 multiscreen-compositor/qml/main.qml      | 30 ++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/multiscreen-compositor/qml/IviChrome.qml b/multiscreen-compositor/qml/IviChrome.qml
index d3aba36..3bc92f5 100644
--- a/multiscreen-compositor/qml/IviChrome.qml
+++ b/multiscreen-compositor/qml/IviChrome.qml
@@ -71,6 +71,4 @@ Item {
         shellSurface.sendConfigure(Qt.size(width, height));
     }
 
-
-
 }
diff --git a/multiscreen-compositor/qml/main.qml b/multiscreen-compositor/qml/main.qml
index d2d894f..273409b 100644
--- a/multiscreen-compositor/qml/main.qml
+++ b/multiscreen-compositor/qml/main.qml
@@ -109,6 +109,8 @@ WaylandCompositor {
 
     IviApplication {
         onIviSurfaceCreated: handleIviSurfaceCreated(iviSurface)
+        //onIviSurfaceRequested: handleIviSurfaceRequested(surface, iviId, resource)
+        onIviSurfaceRequested: console.log("IVI surface requested: surface", surface, "iviId", iviId, "resource", resource);
     }
 
     // =============================================
@@ -242,6 +244,12 @@ WaylandCompositor {
         var surfaceOnScreen = ({ 'surface': item, 'screen': screenId });
         activeSurfaces.push(surfaceOnScreen);
         freezeIviId(iviSurface.iviId, screenId);
+        cleanUpFreezer();
+    }
+
+    function handleIviSurfaceRequested(surface, iviId, resource)
+    {
+        console.log("IVI surface requested: surface", surface, "iviId", iviId, "resource", resource);
     }
 
     function freezeIviId(iviId, screen)
@@ -250,6 +258,27 @@ WaylandCompositor {
         frozenSurfaceIds.push(frozenSurface);
     }
 
+    function cleanUpFreezer()
+    {
+        for (var i=0; i < frozenSurfaceIds.length; i++)
+        {
+            var iviId = frozenSurfaceIds[i].id;
+            var surfaceFound = false;
+            console.log("inspecting frozen iviId", iviId);
+            for (var j=0; j < activeSurfaces.length; j++)
+            {
+                if (iviId === activeSurfaces[j].surface.shellSurface.iviId)
+                    surfaceFound = true;
+            }
+
+            if (!surfaceFound)
+            {
+                console.log("no surface found for iviId", iviId);
+                frozenSurfaceIds = Array.from(frozenSurfaceIds).filter((e, idx) => e.id !== iviId)
+            }
+        }
+    }
+
     function cleanUpApplist()
     {
         for (var i=0; i < activeSurfaces.length; i++) {
@@ -267,6 +296,7 @@ WaylandCompositor {
     // =============================================
     onSurfaceAboutToBeDestroyed: {
         cleanUpApplist();
+        //cleanUpFreezer();
     }
 
     // =============================================
-- 
GitLab