From b88170caaa1aa64550ac542315e6754f10eb9028 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Mon, 27 Feb 2017 00:53:27 +0200 Subject: [PATCH] support always on primary case -- :) fantastic behavior from Latte... --- app/dockcorona.cpp | 47 +++------- app/dockview.cpp | 85 ++++++++++++++----- app/dockview.h | 10 ++- app/screenpool.cpp | 4 +- containment/contents/ui/DebugWindow.qml | 13 +++ .../contents/configuration/BehaviorConfig.qml | 14 ++- 6 files changed, 111 insertions(+), 62 deletions(-) diff --git a/app/dockcorona.cpp b/app/dockcorona.cpp index 0833744f0..7c05958f7 100644 --- a/app/dockcorona.cpp +++ b/app/dockcorona.cpp @@ -250,28 +250,14 @@ void DockCorona::addOutput(QScreen *screen) int newId = m_screenPool->firstAvailableId(); m_screenPool->insertScreenMapping(newId, screen->name()); } - - /* qDebug() << "screen added +++ "<name(); - foreach(auto scr, qGuiApp->screens()){ - qDebug() << "Found screen: "<name(); - }*/ - - /* foreach(auto cont, containments()) { - if (m_screenPool->connector(cont->screen()) == screen->name()) { - auto view = m_dockViews.take(cont); - if (!view) { - addDock(cont); - } - } - } */ } void DockCorona::primaryOutputChanged() { - qDebug() << "primary changed ### "<< qGuiApp->primaryScreen()->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) { @@ -283,21 +269,6 @@ void DockCorona::primaryOutputChanged() void DockCorona::screenRemoved(QScreen *screen) { Q_ASSERT(screen); - /* qDebug() << "screen removed --- "<name(); - foreach(auto scr, qGuiApp->screens()){ - qDebug() << "Found screen: "<name(); - }*/ - - /* if (m_dockViews.size() > 1) { - foreach(auto cont, containments()) { - if (m_screenPool->connector(cont->screen()) == screen->name()) { - auto view = m_dockViews.take(cont); - if (view) { - view->deleteLater(); - } - } - } - } */ } void DockCorona::screenCountChanged() @@ -321,15 +292,16 @@ void DockCorona::screenCountChangedTimer() id = cont->lastScreen(); } - if ((m_screenPool->connector(id) == scr->name()) && (!m_dockViews.contains(cont))) { + 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(); addDock(cont); } } } - qDebug() << "removing consideration...."; - + qDebug() << "removing consideration & updating screen for always on primary docks...."; foreach(auto view, m_dockViews){ bool found{false}; foreach(auto scr, qGuiApp->screens()){ @@ -345,7 +317,7 @@ void DockCorona::screenCountChangedTimer() } } - if (!found && (m_dockViews.size()>1) && m_dockViews.contains(view->containment())) { + if (!found && !view->onPrimary() && (m_dockViews.size()>1) && m_dockViews.contains(view->containment())) { qDebug() << "screen Count signal: view must be deleted... for:"<currentScreen(); auto viewToDelete = m_dockViews.take(view->containment()); viewToDelete->deleteLater(); @@ -490,6 +462,7 @@ void DockCorona::addDock(Plasma::Containment *containment) QScreen *nextScreen{qGuiApp->primaryScreen()}; + bool onPrimary = containment->config().readEntry("onPrimary", true); int id = containment->screen(); if (id == -1) { @@ -498,7 +471,7 @@ void DockCorona::addDock(Plasma::Containment *containment) qDebug() << "add dock - containment id : "<< id; - if (id >= 0) { + if (id >= 0 && !onPrimary) { QString connector = m_screenPool->connector(id); qDebug() << "add dock - connector : "<< connector; bool found{false}; @@ -515,7 +488,7 @@ void DockCorona::addDock(Plasma::Containment *containment) } qDebug() << "Adding dock for container..."; - qDebug() << "screen!!! :" << containment->screen() << " - "<connector(containment->screen()); + qDebug() << "onPrimary: " << onPrimary << "screen!!! :" << containment->screen() << " - "<connector(containment->screen()); auto dockView = new DockView(this, nextScreen); dockView->init(); dockView->setContainment(containment); diff --git a/app/dockview.cpp b/app/dockview.cpp index 053038863..33f59c452 100644 --- a/app/dockview.cpp +++ b/app/dockview.cpp @@ -47,16 +47,16 @@ namespace Latte { DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen) : PlasmaQuick::ContainmentView(corona), m_contextMenu(nullptr) -{ +{ setVisible(false); setTitle(corona->kPackage().metadata().name()); setIcon(QIcon::fromTheme(corona->kPackage().metadata().iconName())); setResizeMode(QuickViewSharedEngine::SizeRootObjectToView); setClearBeforeRendering(true); setFlags(Qt::FramelessWindowHint - | Qt::WindowStaysOnTopHint - | Qt::NoDropShadowWindowHint - | Qt::WindowDoesNotAcceptFocus); + | Qt::WindowStaysOnTopHint + | Qt::NoDropShadowWindowHint + | Qt::WindowDoesNotAcceptFocus); if (targetScreen) setScreenToFollow(targetScreen); @@ -65,10 +65,12 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen) connect(this, &DockView::containmentChanged , this, [&]() { - qDebug() << "entered creating step 1..."; + if (!this->containment()) return; - qDebug() << "entered creating step 2..."; + + restoreConfig(); + reconsiderScreen(); if (!m_visibility) { m_visibility = new VisibilityManager(this); @@ -136,6 +138,9 @@ void DockView::init() connect(this, &DockView::maxLengthChanged, this, &DockView::syncGeometry); connect(this, &DockView::alignmentChanged, this, &DockView::updateEnabledBorders); + connect(this, &DockView::onPrimaryChanged, this, &DockView::saveConfig); + connect(this, &DockView::onPrimaryChanged, this, &DockView::reconsiderScreen); + connect(this, &DockView::locationChanged, this, [&]() { updateFormFactor(); syncGeometry(); @@ -212,11 +217,17 @@ void DockView::reconsiderScreen() qDebug() << " D, found screen: "<name(); } - foreach(auto scr, qGuiApp->screens()){ - if (scr && scr->name() == m_screenToFollowId){ - connect(scr, &QScreen::geometryChanged, this, &DockView::screenGeometryChanged); - setScreenToFollow(scr); - syncGeometry(); + if (m_onPrimary && screen()!=qGuiApp->primaryScreen()) { + connect(qGuiApp->primaryScreen(), &QScreen::geometryChanged, this, &DockView::screenGeometryChanged); + setScreenToFollow(qGuiApp->primaryScreen()); + syncGeometry(); + } else { + foreach(auto scr, qGuiApp->screens()){ + if (scr && scr->name() == m_screenToFollowId){ + connect(scr, &QScreen::geometryChanged, this, &DockView::screenGeometryChanged); + setScreenToFollow(scr); + syncGeometry(); + } } } @@ -225,11 +236,11 @@ void DockView::reconsiderScreen() void DockView::screenChanged(QScreen *scr) { - // if (!scr || m_screenToFollow == scr) { + // if (!scr || m_screenToFollow == scr) { // return; - // } + // } - // qDebug() << "Screen inconsistency!!! :" << scr->name() << " - " <name(); + // qDebug() << "Screen inconsistency!!! :" << scr->name() << " - " <name(); m_screenSyncTimer.start(); //QTimer::singleShot(2500, this, &DockView::reconsiderScreen); @@ -250,7 +261,7 @@ void DockView::screenChanged(QScreen *scr) setScreen(m_screenToFollow); syncGeometry(); }*/ - // emit docksCountChanged(); + // emit docksCountChanged(); } @@ -474,19 +485,19 @@ inline void DockView::syncGeometry() bool found{false}; if (this->screen() != m_screenToFollow) { qDebug() << "Sync Geometry screens incosistent!!!!"; - foreach(auto scr, qGuiApp->screens()){ + /*foreach(auto scr, qGuiApp->screens()){ qDebug() << "Found screen: "<name(); if (scr && scr->name() == m_screenToFollowId){ qDebug() << " found ... "; //setScreenToFollow(scr); - // found=true; + // found=true; } - } + }*/ m_screenSyncTimer.start(); //QTimer::singleShot(2500, this, &DockView::reconsiderScreen); //if (found) - // setScreenToFollow(m_screenToFollow); + // setScreenToFollow(m_screenToFollow); } else { found = true; } @@ -591,6 +602,21 @@ void DockView::setDrawShadows(bool draw) emit drawShadowsChanged(); } +bool DockView::onPrimary() const +{ + return m_onPrimary; +} + +void DockView::setOnPrimary(bool flag) +{ + if (m_onPrimary == flag){ + return; + } + + m_onPrimary = flag; + emit onPrimaryChanged(); +} + float DockView::maxLength() const { return m_maxLength; @@ -1186,5 +1212,26 @@ void DockView::updateEnabledBorders() //!END draw panel shadows outside the dock window +//!BEGIN configuration functions +void DockView::saveConfig() +{ + if (!this->containment()) + return; + + auto config = this->containment()->config(); + config.writeEntry("onPrimary", m_onPrimary); + this->containment()->configNeedsSaving(); +} + +void DockView::restoreConfig() +{ + if (!this->containment()) + return; + + auto config = this->containment()->config(); + setOnPrimary(config.readEntry("onPrimary", true)); +} +//!END configuration functions + } //!END namespace diff --git a/app/dockview.h b/app/dockview.h index 215fb63ce..1fba11162 100644 --- a/app/dockview.h +++ b/app/dockview.h @@ -44,6 +44,7 @@ namespace Latte { class DockView : public PlasmaQuick::ContainmentView { Q_OBJECT Q_PROPERTY(bool drawShadows READ drawShadows WRITE setDrawShadows NOTIFY drawShadowsChanged) + Q_PROPERTY(bool onPrimary READ onPrimary WRITE setOnPrimary NOTIFY onPrimaryChanged) Q_PROPERTY(int alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) Q_PROPERTY(int docksCount READ docksCount NOTIFY docksCountChanged) @@ -67,7 +68,6 @@ class DockView : public PlasmaQuick::ContainmentView { Q_PROPERTY(QRect screenGeometry READ screenGeometry NOTIFY screenGeometryChanged) - public: DockView(Plasma::Corona *corona, QScreen *targetScreen = nullptr); virtual ~DockView(); @@ -80,6 +80,9 @@ public: void resizeWindow(); void syncGeometry(); + bool onPrimary() const; + void setOnPrimary(bool flag); + int currentThickness() const; int docksCount() const; @@ -158,6 +161,7 @@ signals: void maxLengthChanged(); void maxThicknessChanged(); void normalThicknessChanged(); + void onPrimaryChanged(); void visibilityChanged(); void maskAreaChanged(); void screenGeometryChanged(); @@ -172,6 +176,9 @@ private slots: void statusChanged(Plasma::Types::ItemStatus); void screenChanged(QScreen *screen); + void restoreConfig(); + void saveConfig(); + private: void addAppletActions(QMenu *desktopMenu, Plasma::Applet *applet, QEvent *event); void addContainmentActions(QMenu *desktopMenu, QEvent *event); @@ -182,6 +189,7 @@ private: Plasma::Containment *containmentById(uint id); bool m_drawShadows{false}; + bool m_onPrimary{true}; int m_maxThickness{24}; int m_normalThickness{24}; int m_shadow{0}; diff --git a/app/screenpool.cpp b/app/screenpool.cpp index d51225f53..c168c7041 100644 --- a/app/screenpool.cpp +++ b/app/screenpool.cpp @@ -106,14 +106,14 @@ void ScreenPool::setPrimaryConnector(const QString &primary) } Q_ASSERT(m_idForConnector.contains(primary)); - int oldIdForPrimary = m_idForConnector.value(primary); + /* int oldIdForPrimary = m_idForConnector.value(primary); m_idForConnector[primary] = 0; m_connectorForId[0] = primary; m_idForConnector[m_primaryConnector] = oldIdForPrimary; m_connectorForId[oldIdForPrimary] = m_primaryConnector; m_primaryConnector = primary; - +*/ save(); } diff --git a/containment/contents/ui/DebugWindow.qml b/containment/contents/ui/DebugWindow.qml index abd627d86..22325fcdf 100644 --- a/containment/contents/ui/DebugWindow.qml +++ b/containment/contents/ui/DebugWindow.qml @@ -60,6 +60,19 @@ Window{ text: dock.x + "," + dock.y + " "+dock.width+ "x"+dock.height } + Text{ + text: "On Primary"+space + } + + Text{ + text: { + if (dock.onPrimary) + return "Yes"; + else + return "No"; + } + } + Text{ text: " ----------- " } diff --git a/shell/contents/configuration/BehaviorConfig.qml b/shell/contents/configuration/BehaviorConfig.qml index 79fde3889..8235f033b 100644 --- a/shell/contents/configuration/BehaviorConfig.qml +++ b/shell/contents/configuration/BehaviorConfig.qml @@ -67,7 +67,7 @@ PlasmaComponents.Page { var screens = [] - // screens.push(i18n("On Primary")); + screens.push(i18n("On Primary")); for (var i = 0; i < dock.screens.length; i++) { screens.push(dock.screens[i].name) @@ -75,7 +75,12 @@ PlasmaComponents.Page { screenCmb.model = screens; - screenCmb.currentIndex = screenCmb.find(dock.currentScreen); + if (dock.onPrimary) { + screenCmb.currentIndex = 0; + } else { + screenCmb.currentIndex = screenCmb.find(dock.currentScreen); + } + console.log(dock.currentScreen); } @@ -95,9 +100,12 @@ PlasmaComponents.Page { Component.onCompleted: screenRow.updateScreens(); onActivated: { - if (index !== find(dock.currentScreen)) { + if (index === 0) { + dock.onPrimary = true; + } 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)); } }