From 30c90d2a419c8c367a7a2f3887b7a11bd4f8de6b Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Thu, 2 Aug 2018 12:58:54 +0300 Subject: [PATCH] More predictable copy function for multi-screen --Improve the series of events in order for CopyDock to work better in multi-screen environments. Copy Dock should create the same dock in the same free edge at different explicit screen when that edge is already occupied in the origin screen BUG: 397081 FIXED-IN: 0.8.1 --- app/layout.cpp | 39 ++++++++++++++++++++++++++++++++------- app/layout.h | 8 +++++++- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/app/layout.cpp b/app/layout.cpp index 58d18d6e6..7d8e92dc6 100644 --- a/app/layout.cpp +++ b/app/layout.cpp @@ -235,6 +235,20 @@ void Layout::setVersion(int ver) emit versionChanged(); } +bool Layout::blockAutomaticDockViewCreation() const +{ + return m_blockAutomaticDockViewCreation; +} + +void Layout::setBlockAutomaticDockViewCreation(bool block) +{ + if (m_blockAutomaticDockViewCreation == block) { + return; + } + + m_blockAutomaticDockViewCreation = block; +} + bool Layout::disableBordersForMaximizedWindows() const { return m_disableBordersForMaximizedWindows; @@ -707,7 +721,12 @@ void Layout::addContainment(Plasma::Containment *containment) } if (containmentInLayout) { - addDock(containment); + if (!blockAutomaticDockViewCreation()) { + addDock(containment); + } else { + qDebug() << "delaying DockView creation for containment :: " << containment->id(); + } + connect(containment, &QObject::destroyed, this, &Layout::containmentDestroyed); } } @@ -833,7 +852,7 @@ void Layout::containmentDestroyed(QObject *cont) } } -void Layout::addDock(Plasma::Containment *containment, bool forceLoading, int expDockScreen) +void Layout::addDock(Plasma::Containment *containment, bool forceOnPrimary, int expDockScreen) { qDebug() << "Layout :::: " << m_layoutName << " ::: addDock was called... m_containments :: " << m_containments.size(); @@ -871,9 +890,10 @@ void Layout::addDock(Plasma::Containment *containment, bool forceLoading, int ex id = expDockScreen; } - qDebug() << "add dock - containment id: " << containment->id() << " ,screen id : " << id << " ,onprimary:" << onPrimary << " ,forceDockLoad:" << forceLoading; + qDebug() << "add dock - containment id: " << containment->id() << " ,screen : " << id << " - " << m_corona->screenPool()->connector(id) + << " ,onprimary:" << onPrimary << " - " << qGuiApp->primaryScreen()->name() << " ,forceOnPrimary:" << forceOnPrimary; - if (id >= 0 && !onPrimary && !forceLoading) { + if (id >= 0 && !onPrimary && !forceOnPrimary) { QString connector = m_corona->screenPool()->connector(id); qDebug() << "add dock - connector : " << connector; bool found{false}; @@ -954,7 +974,7 @@ void Layout::addDock(Plasma::Containment *containment, bool forceLoading, int ex //! force this special dock case to become primary //! even though it isnt - if (forceLoading) { + if (forceOnPrimary) { dockView->setOnPrimary(true); } @@ -1052,6 +1072,9 @@ void Layout::copyDock(Plasma::Containment *containment) QString temp2File = newUniqueIdsLayoutFromFile(temp1File); + //! Dont create DockView when the containment is created because we must update + //! its screen settings first + setBlockAutomaticDockViewCreation(true); //! Finally import the configuration QList importedDocks = importLayoutFile(temp2File); @@ -1122,12 +1145,14 @@ void Layout::copyDock(Plasma::Containment *containment) if (setOnExplicitScreen && copyScrId > -1) { qDebug() << "Copy Dock in explicit screen ::: " << copyScrId; - addDock(newContainment, copyScrId); + addDock(newContainment, false, copyScrId); newContainment->reactToScreenChange(); } else { qDebug() << "Copy Dock in current screen..."; - addDock(newContainment, dockScrId); + addDock(newContainment, false, dockScrId); } + + setBlockAutomaticDockViewCreation(false); } void Layout::appletCreated(Plasma::Applet *applet) diff --git a/app/layout.h b/app/layout.h index 940c8c070..d5133c9db 100644 --- a/app/layout.h +++ b/app/layout.h @@ -116,7 +116,7 @@ public: QStringList unloadedContainmentsIds(); //! this function needs the layout to have first set the corona through initToCorona() function - void addDock(Plasma::Containment *containment, bool forceLoading = false, int expDockScreen = -1); + void addDock(Plasma::Containment *containment, bool forceOnPrimary = false, int expDockScreen = -1); void copyDock(Plasma::Containment *containment); void recreateDock(Plasma::Containment *containment); @@ -180,6 +180,11 @@ private: void setName(QString name); void setFile(QString file); + //! It can be used in order for DockViews to not be created automatically when + //! their corresponding containments are created e.g. copyDock functionality + bool blockAutomaticDockViewCreation() const; + void setBlockAutomaticDockViewCreation(bool block); + bool explicitDockOccupyEdge(int screen, Plasma::Types::Location location) const; bool primaryDockOccupyEdge(Plasma::Types::Location location) const; @@ -195,6 +200,7 @@ private: QList importLayoutFile(QString file); private: + bool m_blockAutomaticDockViewCreation{false}; bool m_disableBordersForMaximizedWindows{false}; bool m_showInMenu{false}; //if version doesnt exist it is and old layout file