diff --git a/app/dock/dockview.cpp b/app/dock/dockview.cpp index 1bd06dad6..45c2f5fe1 100644 --- a/app/dock/dockview.cpp +++ b/app/dock/dockview.cpp @@ -979,23 +979,6 @@ bool DockView::event(QEvent *e) return ContainmentView::event(e);; } -QList DockView::freeEdges() const -{ - if (!m_managedLayout) { - const QList emptyEdges; - return emptyEdges; - } - - const auto edges = m_managedLayout->freeEdges(screen()); - QList edgesInt; - - foreach (Plasma::Types::Location edge, edges) { - edgesInt.append(static_cast(edge)); - } - - return edgesInt; -} - void DockView::deactivateApplets() { if (!containment()) { diff --git a/app/dock/dockview.h b/app/dock/dockview.h index 3b03e0a5f..3f703bb3a 100644 --- a/app/dock/dockview.h +++ b/app/dock/dockview.h @@ -174,7 +174,6 @@ public slots: Q_INVOKABLE void removeDock(); Q_INVOKABLE void copyDock(); - Q_INVOKABLE QList freeEdges() const; Q_INVOKABLE QVariantList containmentActions(); Q_INVOKABLE void deactivateApplets(); diff --git a/app/dock/positioner.cpp b/app/dock/positioner.cpp index 7d533076d..17002c8e3 100644 --- a/app/dock/positioner.cpp +++ b/app/dock/positioner.cpp @@ -89,6 +89,7 @@ void Positioner::init() connect(m_view, &QQuickWindow::yChanged, this, &Positioner::validateDockGeometry); connect(m_view, &QQuickWindow::widthChanged, this, &Positioner::validateDockGeometry); connect(m_view, &QQuickWindow::heightChanged, this, &Positioner::validateDockGeometry); + connect(m_view, &QQuickWindow::screenChanged, this, &Positioner::currentScreenChanged); connect(m_view, &QQuickWindow::screenChanged, this, &Positioner::screenChanged); connect(m_view, &Latte::DockView::absGeometryChanged, this, &Positioner::syncGeometry); @@ -126,6 +127,17 @@ void Positioner::init() initSignalingForLocationChangeSliding(); } +int Positioner::currentScreenId() const +{ + auto *dockCorona = qobject_cast(m_view->corona()); + + if (dockCorona) { + return dockCorona->screenPool()->id(m_screenToFollowId); + } + + return -1; +} + QString Positioner::currentScreenName() const { return m_screenToFollowId; diff --git a/app/dock/positioner.h b/app/dock/positioner.h index fccaa16e6..ccfe33408 100644 --- a/app/dock/positioner.h +++ b/app/dock/positioner.h @@ -42,18 +42,20 @@ class Positioner: public QObject { Q_OBJECT + Q_PROPERTY(int currentScreenId READ currentScreenId NOTIFY currentScreenChanged) Q_PROPERTY(QString currentScreenName READ currentScreenName NOTIFY currentScreenChanged) public: Positioner(DockView *parent); virtual ~Positioner(); - void reconsiderScreen(); + int currentScreenId() const; + QString currentScreenName() const; bool inLocationChangeAnimation(); void setScreenToFollow(QScreen *scr, bool updateScreenId = true); - QString currentScreenName() const; + void reconsiderScreen(); public slots: Q_INVOKABLE void hideDockDuringLocationChange(int goToLocation); diff --git a/app/layout.cpp b/app/layout.cpp index ea85d071d..6dc04a11c 100644 --- a/app/layout.cpp +++ b/app/layout.cpp @@ -1791,6 +1791,23 @@ QList Layout::availableEdgesForView(QScreen *scr, DockV return edges; } +QList Layout::qmlFreeEdges(int screen) const +{ + if (!m_corona) { + const QList emptyEdges; + return emptyEdges; + } + + const auto edges = freeEdges(screen); + QList edgesInt; + + foreach (Plasma::Types::Location edge, edges) { + edgesInt.append(static_cast(edge)); + } + + return edgesInt; +} + QList Layout::freeEdges(QScreen *scr) const { using Plasma::Types; diff --git a/app/layout.h b/app/layout.h index 83b1eae99..be833c9c2 100644 --- a/app/layout.h +++ b/app/layout.h @@ -154,6 +154,10 @@ public: int docksCount(int screen) const; int docksCount(QScreen *screen) const; +public slots: + //change to types + Q_INVOKABLE QList qmlFreeEdges(int screen) const; + signals: void activitiesChanged(); void backgroundChanged(); diff --git a/shell/package/contents/configuration/BehaviorConfig.qml b/shell/package/contents/configuration/BehaviorConfig.qml index 1e462890d..a0b75a70a 100644 --- a/shell/package/contents/configuration/BehaviorConfig.qml +++ b/shell/package/contents/configuration/BehaviorConfig.qml @@ -189,6 +189,8 @@ PlasmaComponents.Page { onDocksCountChanged: locationLayout.lockReservedEdges(); } + Component.onCompleted: lockReservedEdges() + ExclusiveGroup { id: locationGroup property bool inStartup: true @@ -202,64 +204,64 @@ PlasmaComponents.Page { } function lockReservedEdges() { - var buttons = visibleChildren - var edges = dock.freeEdges() + var edges = dock.managedLayout.qmlFreeEdges(dock.positioner.currentScreenId); - for (var i = 0; i < buttons.length; i++) { - buttons[i].enabled = buttons[i].checked || freeEdge(buttons[i].edge, edges) - } - } - - function freeEdge(edge, edges) { - for (var i = 0; i < edges.length; i++) { - if (edges[i] === edge) - return true - } - return false + bottomEdgeBtn.edgeIsFree = (edges.indexOf(bottomEdgeBtn.edge)>=0); + topEdgeBtn.edgeIsFree = (edges.indexOf(topEdgeBtn.edge)>=0); + leftEdgeBtn.edgeIsFree = (edges.indexOf(leftEdgeBtn.edge)>=0); + rightEdgeBtn.edgeIsFree = (edges.indexOf(rightEdgeBtn.edge)>=0); } PlasmaComponents.Button { + id: bottomEdgeBtn Layout.fillWidth: true text: i18nc("bottom location", "Bottom") iconSource: "arrow-down" checked: dock.location === edge checkable: true - enabled: checked || locationLayout.freeEdge(edge, dock.freeEdges()) + enabled: checked || edgeIsFree exclusiveGroup: locationGroup + property bool edgeIsFree: true readonly property int edge: PlasmaCore.Types.BottomEdge } PlasmaComponents.Button { + id: leftEdgeBtn Layout.fillWidth: true text: i18nc("left location", "Left") iconSource: "arrow-left" checked: dock.location === edge checkable: true - enabled: checked || locationLayout.freeEdge(edge, dock.freeEdges()) + enabled: checked || edgeIsFree exclusiveGroup: locationGroup + property bool edgeIsFree: true readonly property int edge: PlasmaCore.Types.LeftEdge } PlasmaComponents.Button { + id: topEdgeBtn Layout.fillWidth: true text: i18nc("top location", "Top") iconSource: "arrow-up" checked: dock.location === edge checkable: true - enabled: checked || locationLayout.freeEdge(edge, dock.freeEdges()) + enabled: checked || edgeIsFree exclusiveGroup: locationGroup + property bool edgeIsFree: true readonly property int edge: PlasmaCore.Types.TopEdge } PlasmaComponents.Button { + id: rightEdgeBtn Layout.fillWidth: true text: i18nc("right location", "Right") iconSource: "arrow-right" checked: dock.location === edge checkable: true - enabled: checked || locationLayout.freeEdge(edge, dock.freeEdges()) + enabled: checked || edgeIsFree exclusiveGroup: locationGroup + property bool edgeIsFree: true readonly property int edge: PlasmaCore.Types.RightEdge } } diff --git a/shell/package/contents/configuration/LatteDockConfiguration.qml b/shell/package/contents/configuration/LatteDockConfiguration.qml index 2af17ccb0..3ebf83767 100644 --- a/shell/package/contents/configuration/LatteDockConfiguration.qml +++ b/shell/package/contents/configuration/LatteDockConfiguration.qml @@ -490,7 +490,8 @@ FocusScope { } function updateEnabled() { - addDock.enabled = dock.docksCount < 4 && dock.freeEdges().length > 0 + var screenFreeEdges = dock.managedLayout.qmlFreeEdges(dock.positioner.currentScreenId); + addDock.enabled = dock.docksCount < 4 && screenFreeEdges.length > 0 removeDock.enabled = dock.docksCount>1 && !(dock.docksWithTasks()===1 && dock.tasksPresent()) } @@ -574,7 +575,8 @@ FocusScope { onClicked: dock.addNewDock() Component.onCompleted: { - enabled = dock.freeEdges().length > 0 + var screenFreeEdges = dock.managedLayout.qmlFreeEdges(dock.positioner.currentScreenId); + enabled = screenFreeEdges.length > 0 } } }