From 64d9de750eef5e9bac4a20a5b113089b58faa312 Mon Sep 17 00:00:00 2001
From: Alexander Tuxen <tuxen@silpion.de>
Date: Thu, 24 Nov 2022 02:46:08 +0100
Subject: [PATCH] disabled internal window visibility manipulation and
 implemented moving of non-existing surfaces, based on the frozen IVI-ID.

---
 multiscreen-compositor/qml/main.qml | 36 ++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 8 deletions(-)

diff --git a/multiscreen-compositor/qml/main.qml b/multiscreen-compositor/qml/main.qml
index 2944357..ddecf05 100644
--- a/multiscreen-compositor/qml/main.qml
+++ b/multiscreen-compositor/qml/main.qml
@@ -271,8 +271,10 @@ WaylandCompositor {
 
     // =============================================
     // Remove destroyed surface from the suface list
+    // ----------!!!! HEADS UP !!!!------------
+    // Evil hook! Do not use this hook! Just don't!
     // =============================================
-    onSurfaceAboutToBeDestroyed: {
+    //onSurfaceAboutToBeDestroyed: {
         //
         // ----------!!!! HEADS UP !!!!------------
         //
@@ -286,8 +288,16 @@ WaylandCompositor {
         //
         // ----------!!!! HEADS UP !!!!------------
         //
-        cleanUpApplist();
-    }
+        // It gets worse:
+        //
+        // With the new way of hiding surfaces (via QWidget's hide() and
+        // show() methods) any delay AT ALL at this point will crash the
+        // compositor! So even cleaning up the app list is off the table.
+        //
+        // ----------!!!! HEADS UP !!!!------------
+        //
+        //cleanUpApplist();
+    //}
 
     onSurfaceCreated: {
         console.log("surface created: ", surface);
@@ -403,7 +413,7 @@ WaylandCompositor {
             }
 
             var affectedSurfaces = getActiveSurfaces(getPidFromIviId(windowid));
-            if (affectedSurfaces.length === 0)
+            if ((affectedSurfaces.length === 0) && (getScreenFromIviId(windowid) < 0))
             {
                 console.log("no screens found for IVI ID", windowid);
                 server.returnStatus(-1);
@@ -417,14 +427,18 @@ WaylandCompositor {
                 {
                     console.log("Move", surface, "to screen", screenid)
                     surface.parent = screens.objectAt(screenid).surfaceArea;
-                    updateScreenAssignment(getPidFromIviId(windowid), screenid);
+                    //updateScreenAssignment(getPidFromIviId(windowid), screenid);
                 }
             }
+            updateScreenAssignment(getPidFromIviId(windowid), screenid);
+
             server.returnStatus(0);
             server.sendMessage("Move", windowid, screenid);
         }
 
-        function windowVisibility(windowid, show){
+        function windowVisibility(windowid, show)
+            // window visibility is now handled by the app via QWidget's hide() and show() methods.
+            /*
             var ret = 0;
             var affectedSurfaces = getActiveSurfaces(getPidFromIviId(windowid));
             if (affectedSurfaces.length === 0)
@@ -444,9 +458,10 @@ WaylandCompositor {
                     ret++;
                 }
             }
-
-            server.returnStatus(ret);
+            */
+            server.returnStatus(0);
             server.sendMessage(show ? "Show" : "Hide", windowid, getScreenFromIviId(windowid));
+            //server.sendMessage(show ? "Show" : "Hide", windowid, 0);
         }
 
         function onHideWindow(windowid){
@@ -490,6 +505,11 @@ WaylandCompositor {
             {
                 console.log("setting active screen", screenId);
                 active_screen = screenId;
+                server.returnStatus(0);
+            }
+            else
+            {
+                server.returnStatus(-1);
             }
         }
     }
-- 
GitLab