diff --git a/app/dockcorona.cpp b/app/dockcorona.cpp index 922e240b6..c6fb0548b 100644 --- a/app/dockcorona.cpp +++ b/app/dockcorona.cpp @@ -382,8 +382,26 @@ void DockCorona::addDock(Plasma::Containment *containment) return; } + QScreen *nextScreen{qGuiApp->primaryScreen()}; + + if (containment->screen() >= 0) { + QString connector = m_screenPool->connector(containment->screen()); + bool found{false}; + foreach(auto scr, qGuiApp->screens()){ + if (scr && scr->name() == connector){ + found=true; + nextScreen = scr; + break; + } + } + + if (!found) + return; + } + qDebug() << "Adding dock for container..."; - auto dockView = new DockView(this); + qDebug() << "screen!!! :" << containment->screen() << " - "<connector(containment->screen()); + auto dockView = new DockView(this, nextScreen); dockView->init(); dockView->setContainment(containment); connect(containment, &QObject::destroyed, this, &DockCorona::dockContainmentDestroyed); diff --git a/app/dockview.cpp b/app/dockview.cpp index 6a6a167a4..d172d676d 100644 --- a/app/dockview.cpp +++ b/app/dockview.cpp @@ -59,9 +59,9 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen) | Qt::WindowDoesNotAcceptFocus); if (targetScreen) - adaptToScreen(targetScreen); + setScreenToFollow(targetScreen); else - adaptToScreen(qGuiApp->primaryScreen()); + setScreenToFollow(qGuiApp->primaryScreen()); connect(this, &DockView::containmentChanged , this, [&]() { @@ -112,7 +112,8 @@ DockView::~DockView() void DockView::init() { - //connect(this, &DockView::screenChanged, this, &DockView::syncGeometry); + connect(this, &QQuickWindow::screenChanged, this, &DockView::screenChanged); + connect(qGuiApp, &QGuiApplication::primaryScreenChanged, this, &DockView::syncGeometry, Qt::UniqueConnection); connect(this, &DockView::screenGeometryChanged, this, &DockView::syncGeometry); connect(this, &QQuickWindow::widthChanged, this, &DockView::widthChanged); @@ -139,7 +140,7 @@ void DockView::init() void DockView::adaptToScreen(QScreen *screen) { - if (!screen) { +/* if (!screen) { return; } @@ -150,12 +151,63 @@ void DockView::adaptToScreen(QScreen *screen) //FIXME:: This code in a multi-screen environment that //primary screen is not set to 0 it creates an endless //showing loop at startup (catch-up race) between screen:0 and primaryScreen + if (this->containment()) + this->containment()->reactToScreenChange(); + + syncGeometry(); */ +} + +void DockView::setCurrentScreen(const QString id) +{ + if (!m_screenToFollow || m_screenToFollow->name() == id){ + return; + } + + QScreen *nextScreen{nullptr}; + + foreach(auto scr, qGuiApp->screens()){ + if (scr && scr->name() == id){ + nextScreen = scr; + break; + } + } + + if (nextScreen) + setScreenToFollow(nextScreen); +} + +void DockView::setScreenToFollow(QScreen *screen) +{ + if (!screen || m_screenToFollow == screen) { + return; + } + + m_screenToFollow = screen; + + qDebug() << "adapting to screen..."; + + setScreen(screen); + if (this->containment()) this->containment()->reactToScreenChange(); syncGeometry(); } +void DockView::screenChanged(QScreen *scr) +{ + if (!scr || m_screenToFollow == scr) { + return; + } + + emit docksCountChanged(); + + //IMPORTAT!!! this code creates crashes when changing plasma + //layouts it needs inverstigation!!! + // setScreen(m_screenToFollow); + // syncGeometry(); +} + void DockView::addNewDock() { auto *dockCorona = qobject_cast(this->corona()); @@ -193,6 +245,14 @@ QScreen *DockView::atScreens(QQmlListProperty *property, int index) return qGuiApp->screens().at(index); } +QString DockView::currentScreen() const +{ + if (m_screenToFollow) + return m_screenToFollow->name(); + + return ""; +} + void DockView::showConfigurationInterface(Plasma::Applet *applet) { if (!applet || !applet->containment()) @@ -365,8 +425,11 @@ inline void DockView::syncGeometry() if (!(this->screen() && this->containment())) return; - if (qGuiApp->primaryScreen() && screen() != qGuiApp->primaryScreen()){ - setScreen(qGuiApp->primaryScreen()); + //if (qGuiApp->primaryScreen() && screen() != qGuiApp->primaryScreen()){ + // setScreen(qGuiApp->primaryScreen()); + //} + if (screen() != m_screenToFollow) { + setScreenToFollow(m_screenToFollow); } updateEnabledBorders(); diff --git a/app/dockview.h b/app/dockview.h index 5820f9800..113aa27de 100644 --- a/app/dockview.h +++ b/app/dockview.h @@ -53,6 +53,8 @@ class DockView : public PlasmaQuick::ContainmentView { Q_PROPERTY(int normalThickness READ normalThickness WRITE setNormalThickness NOTIFY normalThicknessChanged) Q_PROPERTY(int shadow READ shadow WRITE setShadow NOTIFY shadowChanged) + Q_PROPERTY(QString currentScreen READ currentScreen NOTIFY currentScreenChanged) + Q_PROPERTY(float maxLength READ maxLength WRITE setMaxLength NOTIFY maxLengthChanged) Q_PROPERTY(Plasma::FrameSvg::EnabledBorders enabledBorders READ enabledBorders NOTIFY enabledBordersChanged) @@ -68,6 +70,7 @@ public: void init(); void adaptToScreen(QScreen *screen); + void setScreenToFollow(QScreen *screen); void resizeWindow(); void syncGeometry(); @@ -102,6 +105,8 @@ public: Plasma::FrameSvg::EnabledBorders enabledBorders() const; + QString currentScreen() const; + VisibilityManager * visibility() const; QQmlListProperty screens(); @@ -115,6 +120,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 tasksPresent(); Q_INVOKABLE void updateEnabledBorders(); @@ -134,6 +140,7 @@ signals: void eventTriggered(QEvent *ev); void alignmentChanged(); + void currentScreenChanged(); void dockLocationChanged(); void docksCountChanged(); void drawShadowsChanged(); @@ -152,6 +159,7 @@ signals: private slots: void menuAboutToHide(); void statusChanged(Plasma::Types::ItemStatus); + void screenChanged(QScreen *screen); private: void addAppletActions(QMenu *desktopMenu, Plasma::Applet *applet, QEvent *event); @@ -175,6 +183,7 @@ private: QMenu *m_contextMenu; QPointer m_configView; QPointer m_visibility; + QPointer m_screenToFollow; //only for the mask, not to actually paint Plasma::FrameSvg::EnabledBorders m_enabledBorders = Plasma::FrameSvg::AllBorders; diff --git a/shell/contents/configuration/BehaviorConfig.qml b/shell/contents/configuration/BehaviorConfig.qml index 03f9d74e6..8ef740d8e 100644 --- a/shell/contents/configuration/BehaviorConfig.qml +++ b/shell/contents/configuration/BehaviorConfig.qml @@ -45,12 +45,58 @@ PlasmaComponents.Page { //! BEGIN: Location ColumnLayout { Layout.fillWidth: true - spacing: units.smallSpacing + spacing: units.largeSpacing Header { text: i18n("Location") } + RowLayout { + Layout.fillWidth: true + Layout.leftMargin: units.smallSpacing * 2 + Layout.rightMargin: units.smallSpacing * 2 + spacing: 1 + + Component.onCompleted: { + if (dock.screens.length > 1) + visible = true; + else + visible = false; + } + + PlasmaComponents.Label { + text: i18n("Screen:") + Layout.alignment: Qt.AlignRight + } + + PlasmaComponents.ComboBox { + id: screenCmb + Layout.fillWidth: true + Component.onCompleted: { + var screens = [] + + // screens.push(i18n("On Primary")); + + for (var i = 0; i < dock.screens.length; i++) { + screens.push(dock.screens[i].name) + } + + model = screens; + + currentIndex = find(dock.currentScreen); + console.log(dock.currentScreen); + } + + onCurrentIndexChanged: { + console.log("current index changed!!! :"+ currentIndex); + if (currentIndex !== find(dock.currentScreen)) { + console.log("screen must be changed..."); + dock.setCurrentScreen(currentText); + } + } + } + } + RowLayout { id: locationLayout Layout.fillWidth: true