From 18f57f51fdb9c6a787ea6ec517266510fec66cd9 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Mon, 27 Feb 2017 19:46:10 +0200 Subject: [PATCH] block screen change when edge is occupied --unfortunately this contains also white spaces fixes. Sorry for this but by implementing multi-screen the laptop wasnt correctly configured for astyle and whitespaces --- app/dockcorona.cpp | 100 +++++++++++------- app/dockcorona.h | 1 + app/dockview.cpp | 33 ++++-- app/dockview.h | 4 +- .../contents/configuration/BehaviorConfig.qml | 35 +++++- 5 files changed, 119 insertions(+), 54 deletions(-) diff --git a/app/dockcorona.cpp b/app/dockcorona.cpp index 7c05958f7..bfbe5254b 100644 --- a/app/dockcorona.cpp +++ b/app/dockcorona.cpp @@ -227,13 +227,13 @@ QRect DockCorona::availableScreenRect(int id) const // need calculate available space for top and bottom location, // because the left and right are those who dodge others docks switch (view->location()) { - case Plasma::Types::TopEdge: - available.setTopLeft({available.x(), dockRect.bottom()}); - break; + case Plasma::Types::TopEdge: + available.setTopLeft({available.x(), dockRect.bottom()}); + break; - case Plasma::Types::BottomEdge: - available.setBottomLeft({available.x(), dockRect.top()}); - break; + case Plasma::Types::BottomEdge: + available.setBottomLeft({available.x(), dockRect.top()}); + break; } } } @@ -246,7 +246,8 @@ void DockCorona::addOutput(QScreen *screen) Q_ASSERT(screen); int id = m_screenPool->id(screen->name()); - if (id==-1){ + + if (id == -1) { int newId = m_screenPool->firstAvailableId(); m_screenPool->insertScreenMapping(newId, screen->name()); } @@ -254,16 +255,16 @@ void DockCorona::addOutput(QScreen *screen) void DockCorona::primaryOutputChanged() { - /* qDebug() << "primary changed ### "<< qGuiApp->primaryScreen()->name(); - foreach(auto scr, qGuiApp->screens()){ - qDebug() << "Found screen: "<name(); - }*/ + /* qDebug() << "primary changed ### "<< qGuiApp->primaryScreen()->name(); + foreach(auto scr, qGuiApp->screens()){ + qDebug() << "Found screen: "<name(); + }*/ //if (m_dockViews.count()==1 && qGuiApp->screens().size()==1) { - // foreach(auto view, m_dockViews) { - // view->setScreenToFollow(qGuiApp->primaryScreen()); - // } - // } + // foreach(auto view, m_dockViews) { + // view->setScreenToFollow(qGuiApp->primaryScreen()); + // } + // } } void DockCorona::screenRemoved(QScreen *screen) @@ -278,47 +279,50 @@ void DockCorona::screenCountChanged() void DockCorona::screenCountChangedTimer() { - qDebug() << "screen count changed -+-+ "<< qGuiApp->screens().size(); + qDebug() << "screen count changed -+-+ " << qGuiApp->screens().size(); qDebug() << "adding consideration...."; qDebug() << "dock view running : " << m_dockViews.count(); - foreach(auto scr, qGuiApp->screens()){ - qDebug() << "Found screen: "<name(); - foreach(auto cont, containments()) { + foreach (auto scr, qGuiApp->screens()) { + qDebug() << "Found screen: " << scr->name(); + + foreach (auto cont, containments()) { int id = cont->screen(); - if (id == -1){ + if (id == -1) { id = cont->lastScreen(); } bool onPrimary = cont->config().readEntry("onPrimary", true); - if ( (onPrimary || (m_screenPool->connector(id) == scr->name())) && (!m_dockViews.contains(cont))) { - qDebug() << "screen Count signal: view must be added... for:"<< scr->name(); + if ((onPrimary || (m_screenPool->connector(id) == scr->name())) && (!m_dockViews.contains(cont))) { + qDebug() << "screen Count signal: view must be added... for:" << scr->name(); addDock(cont); } } } qDebug() << "removing consideration & updating screen for always on primary docks...."; - foreach(auto view, m_dockViews){ + + foreach (auto view, m_dockViews) { bool found{false}; - foreach(auto scr, qGuiApp->screens()){ + + foreach (auto scr, qGuiApp->screens()) { int id = view->containment()->screen(); - if (id == -1){ + if (id == -1) { id = view->containment()->lastScreen(); } - if(scr->name() == view->currentScreen()){ + if (scr->name() == view->currentScreen()) { found = true; break; } } - if (!found && !view->onPrimary() && (m_dockViews.size()>1) && m_dockViews.contains(view->containment())) { - qDebug() << "screen Count signal: view must be deleted... for:"<currentScreen(); + if (!found && !view->onPrimary() && (m_dockViews.size() > 1) && m_dockViews.contains(view->containment())) { + qDebug() << "screen Count signal: view must be deleted... for:" << view->currentScreen(); auto viewToDelete = m_dockViews.take(view->containment()); viewToDelete->deleteLater(); } else { @@ -346,8 +350,8 @@ int DockCorona::docksCount(int screen) const for (const auto &view : m_dockViews) { if (view && view->containment() - && view->containment()->screen() == screen - && !view->containment()->destroyed()) { + && view->containment()->screen() == screen + && !view->containment()->destroyed()) { ++docks; } } @@ -375,17 +379,32 @@ void DockCorona::aboutApplication() aboutDialog->show(); } +QList DockCorona::freeEdges(QScreen *screen) const +{ + using Plasma::Types; + QList edges{Types::BottomEdge, Types::LeftEdge, + Types::TopEdge, Types::RightEdge}; + + for (auto *view : m_dockViews) { + if (view && view->currentScreen() == screen->name()) { + edges.removeOne(view->location()); + } + } + + return edges; +} + QList DockCorona::freeEdges(int screen) const { using Plasma::Types; QList edges{Types::BottomEdge, Types::LeftEdge, - Types::TopEdge, Types::RightEdge}; + Types::TopEdge, Types::RightEdge}; //when screen=-1 is passed then the primaryScreenid is used int fixedScreen = (screen == -1) ? primaryScreenId() : screen; for (auto *view : m_dockViews) { if (view && view->containment() - && view->containment()->screen() == fixedScreen) { + && view->containment()->screen() == fixedScreen) { edges.removeOne(view->location()); } } @@ -432,8 +451,8 @@ int DockCorona::screenForContainment(const Plasma::Containment *containment) con 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_activityConsumer->currentActivity() || - containment->containmentType() == Plasma::Types::PanelContainment || containment->containmentType() == Plasma::Types::CustomPanelContainment)) { + (containment->activity() == m_activityConsumer->currentActivity() || + containment->containmentType() == Plasma::Types::PanelContainment || containment->containmentType() == Plasma::Types::CustomPanelContainment)) { return containment->lastScreen(); } } @@ -469,15 +488,16 @@ void DockCorona::addDock(Plasma::Containment *containment) id = containment->lastScreen(); } - qDebug() << "add dock - containment id : "<< id; + qDebug() << "add dock - containment id : " << id; if (id >= 0 && !onPrimary) { QString connector = m_screenPool->connector(id); - qDebug() << "add dock - connector : "<< connector; + qDebug() << "add dock - connector : " << connector; bool found{false}; - foreach(auto scr, qGuiApp->screens()){ - if (scr && scr->name() == connector){ - found=true; + + foreach (auto scr, qGuiApp->screens()) { + if (scr && scr->name() == connector) { + found = true; nextScreen = scr; break; } @@ -488,7 +508,7 @@ void DockCorona::addDock(Plasma::Containment *containment) } qDebug() << "Adding dock for container..."; - qDebug() << "onPrimary: " << onPrimary << "screen!!! :" << containment->screen() << " - "<connector(containment->screen()); + qDebug() << "onPrimary: " << onPrimary << "screen!!! :" << containment->screen() << " - " << m_screenPool->connector(containment->screen()); auto dockView = new DockView(this, nextScreen); dockView->init(); dockView->setContainment(containment); diff --git a/app/dockcorona.h b/app/dockcorona.h index 37a7651b6..e26c66cd5 100644 --- a/app/dockcorona.h +++ b/app/dockcorona.h @@ -55,6 +55,7 @@ public: QRect availableScreenRect(int id) const override; QList freeEdges(int screen) const; + QList freeEdges(QScreen *screen) const; int docksCount(int screen) const; int screenForContainment(const Plasma::Containment *containment) const override; diff --git a/app/dockview.cpp b/app/dockview.cpp index 9f93bb826..a0e83c90f 100644 --- a/app/dockview.cpp +++ b/app/dockview.cpp @@ -153,23 +153,38 @@ void DockView::init() qDebug() << "SOURCE:" << source(); } -void DockView::setCurrentScreen(const QString id) +bool DockView::setCurrentScreen(const QString id) { if (!m_screenToFollow || m_screenToFollow->name() == id) { - return; + return false; } - QScreen *nextScreen{nullptr}; + QScreen *nextScreen{qGuiApp->primaryScreen()}; - foreach (auto scr, qGuiApp->screens()) { - if (scr && scr->name() == id) { - nextScreen = scr; - break; + if (id != "primary") { + foreach (auto scr, qGuiApp->screens()) { + if (scr && scr->name() == id) { + nextScreen = scr; + break; + } } } - if (nextScreen) - setScreenToFollow(nextScreen); + if (nextScreen) { + auto *dockCorona = qobject_cast(this->corona()); + + if (dockCorona) { + auto freeEdges = dockCorona->freeEdges(nextScreen); + + if (!freeEdges.contains(location())) { + return false; + } else { + setScreenToFollow(nextScreen); + } + } + } + + return false; } void DockView::setScreenToFollow(QScreen *screen) diff --git a/app/dockview.h b/app/dockview.h index 6b46081aa..08fe1ae00 100644 --- a/app/dockview.h +++ b/app/dockview.h @@ -116,7 +116,7 @@ public: QString currentScreen() const; - VisibilityManager * visibility() const; + VisibilityManager *visibility() const; QQmlListProperty screens(); static int countScreens(QQmlListProperty *property); @@ -130,7 +130,7 @@ public slots: Q_INVOKABLE QList freeEdges() const; Q_INVOKABLE QVariantList containmentActions(); Q_INVOKABLE void setLocalDockGeometry(const QRect &geometry); - Q_INVOKABLE void setCurrentScreen(const QString id); + Q_INVOKABLE bool setCurrentScreen(const QString id); Q_INVOKABLE bool tasksPresent(); Q_INVOKABLE void updateEnabledBorders(); diff --git a/shell/contents/configuration/BehaviorConfig.qml b/shell/contents/configuration/BehaviorConfig.qml index 8235f033b..2a901197d 100644 --- a/shell/contents/configuration/BehaviorConfig.qml +++ b/shell/contents/configuration/BehaviorConfig.qml @@ -99,14 +99,43 @@ PlasmaComponents.Page { Layout.fillWidth: true Component.onCompleted: screenRow.updateScreens(); + //they are used to restore the index when the screen edge + //is occuppied + property bool acceptedIndex: true + property int previousIndex: -1 + + onCurrentIndexChanged: { + //it is used to restore the index when the screen edge + //is occuppied + if (!acceptedIndex) { + acceptedIndex = true; + currentIndex = previousIndex; + } + } + onActivated: { + previousIndex = currentIndex; if (index === 0) { - dock.onPrimary = true; + var succeed = dock.setCurrentScreen("primary"); + + if (succeed) { + dock.onPrimary = true; + } else { + console.log("the edge is already occupied!!!"); + acceptedIndex = false; + } } else if (index>0 && (index !== find(dock.currentScreen) || dock.onPrimary)) { console.log("current index changed!!! :"+ index); console.log("screen must be changed..."); - dock.onPrimary = false; - dock.setCurrentScreen(textAt(index)); + + var succeed = dock.setCurrentScreen(textAt(index)); + + if(succeed) { + dock.onPrimary = false; + } else { + console.log("the edge is already occupied!!!"); + acceptedIndex = false; + } } } }