File 0002-make-sure-all-outputs-are-known.patch of Package plasma5-workspace.openSUSE_Leap_42.2_Update

From c89560cb534692ac9344533a207216e219de60d1 Mon Sep 17 00:00:00 2001
From: Marco Martin <notmart@gmail.com>
Date: Wed, 9 Nov 2016 15:54:42 +0100
Subject: [PATCH 2/5] make sure all outputs are known

at startup, if a screen id is missing from the screenpool mapping
containment::screen() will return -1 for a moment in the startup
phase even if it has a valid lastScreen

populate mappings of eventual missing stuff at screenpool ctor

make sure destroyed containments don't get assigned a view

reviewed-by: David Edmundson

CCBUG:372099
CCBUG:371858
CCBUG:371991
CCBUG:371819
CCBUG:371734
---
 shell/screenpool.cpp  | 11 +++++++++++
 shell/shellcorona.cpp |  8 +++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/shell/screenpool.cpp b/shell/screenpool.cpp
index 89868e8..011300d 100644
--- a/shell/screenpool.cpp
+++ b/shell/screenpool.cpp
@@ -51,6 +51,17 @@ ScreenPool::ScreenPool(KSharedConfig::Ptr config, QObject *parent)
             m_configGroup.deleteEntry(key);
         }
     }
+
+    // if there are already connected unknown screens, map those
+    // all needs to be populated as soon as possible, otherwise
+    // containment->screen() will return an incorrect -1
+    // at startup, if it' asked before corona::addOutput()
+    // is performed, driving to the creation of a new containment
+    for (QScreen* screen : qGuiApp->screens()) {
+        if (!m_idForConnector.contains(screen->name())) {
+            insertScreenMapping(firstAvailableId(), screen->name());
+        }
+    }
 }
 
 ScreenPool::~ScreenPool()
diff --git a/shell/shellcorona.cpp b/shell/shellcorona.cpp
index 33259da..8189eed 100644
--- a/shell/shellcorona.cpp
+++ b/shell/shellcorona.cpp
@@ -1154,7 +1154,12 @@ Plasma::Containment *ShellCorona::createContainmentForActivity(const QString& ac
 {
     if (m_desktopContainments.contains(activity)) {
         for (Plasma::Containment *cont : m_desktopContainments.value(activity)) {
-            if (cont->screen() == screenNum && cont->activity() == activity) {
+            //in the case of a corrupt config file
+            //with multiple containments with same lastScreen
+            //it can happen two insertContainment happen for
+            //the same screen, leading to the old containment 
+            //to be destroyed
+            if (!cont->destroyed() && cont->screen() == screenNum && cont->activity() == activity) {
                 return cont;
             }
         }
@@ -1808,6 +1813,7 @@ int ShellCorona::screenForContainment(const Plasma::Containment *containment) co
 //     qDebug() << "ShellCorona screenForContainment: " << containment << " Last screen is " << containment->lastScreen();
 
     for (auto screen : qGuiApp->screens()) {
+        // containment->lastScreen() == m_screenPool->id(screen->name()) to check if the lastScreen refers to a screen that exists/it's known
         if (containment->lastScreen() == m_screenPool->id(screen->name()) &&
             (containment->activity() == m_activityController->currentActivity() ||
             containment->containmentType() == Plasma::Types::PanelContainment || containment->containmentType() == Plasma::Types::CustomPanelContainment)) {
-- 
2.10.1

openSUSE Build Service is sponsored by