diff --git a/app/dockconfigview.cpp b/app/dockconfigview.cpp index bbb207b53..5a6acfb75 100644 --- a/app/dockconfigview.cpp +++ b/app/dockconfigview.cpp @@ -23,6 +23,7 @@ #include "dockcorona.h" #include "panelshadows_p.h" #include "abstractwindowinterface.h" +#include "../liblattedock/dock.h" #include #include @@ -214,7 +215,7 @@ void DockConfigView::hideEvent(QHideEvent *ev) QQuickWindow::hideEvent(ev); - if (m_dockView->visibility()->mode() != m_previousMode + if (m_dockView && m_dockView->visibility()->mode() != m_previousMode && ((m_dockView->visibility()->mode() == Dock::AlwaysVisible) || (m_previousMode == Dock::AlwaysVisible))) { @@ -304,5 +305,26 @@ void DockConfigView::setRaiseDocksTemporary(bool state) } } +Dock::SessionType DockConfigView::currentSession() const +{ + auto *dockCorona = qobject_cast(m_dockView->corona()); + + if (dockCorona) { + return dockCorona->currentSession(); + } + + return Dock::DefaultSession; +} + +void DockConfigView::setCurrentSession(Dock::SessionType session) +{ + auto *dockCorona = qobject_cast(m_dockView->corona()); + + if (dockCorona && dockCorona->currentSession() != session) { + dockCorona->switchToSession(session); + hide(); + } +} + } // kate: indent-mode cstyle; indent-width 4; replace-tabs on; diff --git a/app/dockconfigview.h b/app/dockconfigview.h index fc55b83a9..537c3c714 100644 --- a/app/dockconfigview.h +++ b/app/dockconfigview.h @@ -45,6 +45,7 @@ class DockConfigView : public PlasmaQuick::ConfigView { Q_OBJECT Q_PROPERTY(bool autostart READ autostart WRITE setAutostart NOTIFY autostartChanged) Q_PROPERTY(bool raiseDocksTemporary READ raiseDocksTemporary WRITE setRaiseDocksTemporary NOTIFY raiseDocksTemporaryChanged) + Q_PROPERTY(Latte::Dock::SessionType currentSession READ currentSession WRITE setCurrentSession NOTIFY currentSessionChanged) public: DockConfigView(Plasma::Containment *containment, DockView *dockView, QWindow *parent = nullptr); @@ -59,6 +60,9 @@ public: bool raiseDocksTemporary() const; void setRaiseDocksTemporary(bool state); + Latte::Dock::SessionType currentSession() const; + void setCurrentSession(Latte::Dock::SessionType session); + public slots: Q_INVOKABLE void addPanelSpacer(); Q_INVOKABLE void setSticker(bool blockFocusLost); @@ -66,6 +70,7 @@ public slots: signals: void autostartChanged(); + void currentSessionChanged(); void raiseDocksTemporaryChanged(); void showSignal(); diff --git a/app/dockcorona.cpp b/app/dockcorona.cpp index 4a1da32d8..a5bc21b7e 100644 --- a/app/dockcorona.cpp +++ b/app/dockcorona.cpp @@ -369,7 +369,7 @@ int DockCorona::noDocksWithTasks() const int result = 0; foreach (auto view, m_dockViews) { - if (view->tasksPresent()) { + if (view->tasksPresent() && view->session() == m_session) { result++; } } @@ -434,13 +434,14 @@ void DockCorona::syncDockViews() bool onPrimary = cont->config().readEntry("onPrimary", true); Plasma::Types::Location location = (Plasma::Types::Location)((int)cont->config().readEntry("location", (int)Plasma::Types::BottomEdge)); + Dock::SessionType session = (Dock::SessionType)((int)cont->config().readEntry("session", (int)Dock::DefaultSession)); //! two main situations that a dock must be added when it is not already running //! 1. when a dock is primary, not running and the edge for which is associated is free //! 2. when a dock in explicit, not running and the associated screen currently exists //! e.g. the screen has just been added if (((onPrimary && freeEdges(qGuiApp->primaryScreen()).contains(location)) || (!onPrimary && (m_screenPool->connector(id) == scr->name()))) - && (!m_dockViews.contains(cont))) { + && (!m_dockViews.contains(cont)) && session == currentSession()) { qDebug() << "screen Count signal: view must be added... for:" << scr->name(); addDock(cont); } @@ -505,9 +506,13 @@ void DockCorona::syncDockViews() } } - //! which explicit docks can be deleted - if (!found && !view->onPrimary() && (m_dockViews.size() > 1) && m_dockViews.contains(view->containment()) - && !(view->tasksPresent() && noDocksWithTasks() == 1)) { + if (view->session() != currentSession()) { + qDebug() << "deleting view that does not belong in this session..."; + auto viewToDelete = m_dockViews.take(view->containment()); + viewToDelete->deleteLater(); + //! which explicit docks can be deleted + } else if (!found && !view->onPrimary() && (m_dockViews.size() > 1) && m_dockViews.contains(view->containment()) + && !(view->tasksPresent() && noDocksWithTasks() == 1)) { //do not delete last dock containing tasks if (dockWithTasksWillBeShown || preserveContainmentId != view->containment()->id()) { qDebug() << "screen Count signal: view must be deleted... for:" << view->currentScreen(); @@ -615,7 +620,6 @@ bool DockCorona::autostart() const return autostartFile.exists(); } - bool DockCorona::raiseDocksTemporary() const { return m_raiseDocksTemporary; @@ -633,6 +637,50 @@ void DockCorona::setRaiseDocksTemporary(bool flag) emit raiseDocksTemporaryChanged(); } +Dock::SessionType DockCorona::currentSession() +{ + return m_session; +} + +void DockCorona::setCurrentSession(Dock::SessionType session) +{ + if (m_session == session) { + return; + } + + m_session = session; +} + +void DockCorona::switchToSession(Dock::SessionType session) +{ + if (currentSession() == session) { + return; + } + + setCurrentSession(session); + + if (noDocksForSession(session) == 0) { + m_waitingSessionDocksCreation = true; + loadDefaultLayout(); + } else { + m_waitingSessionDocksCreation = false; + syncDockViews(); + } +} + +int DockCorona::noDocksForSession(Dock::SessionType session) +{ + int count{0}; + + foreach (auto cont, containments()) { + Dock::SessionType ses = (Dock::SessionType)((int)cont->config().readEntry("session", (int)Dock::DefaultSession)); + + if (session == ses) + count++; + } + + return count; +} QList DockCorona::freeEdges(QScreen *screen) const { @@ -641,7 +689,7 @@ QList DockCorona::freeEdges(QScreen *screen) const Types::TopEdge, Types::RightEdge}; for (auto *view : m_dockViews) { - if (view && view->currentScreen() == screen->name()) { + if (view && view->currentScreen() == screen->name() && view->session() == m_session) { edges.removeOne(view->location()); } } @@ -659,7 +707,8 @@ QList DockCorona::freeEdges(int screen) const for (auto *view : m_dockViews) { if (view && view->containment() - && view->containment()->screen() == fixedScreen) { + && view->containment()->screen() == fixedScreen + && view->session() == m_session) { edges.removeOne(view->location()); } } @@ -727,6 +776,14 @@ void DockCorona::addDock(Plasma::Containment *containment) if (metadata.pluginId() != "org.kde.latte.containment") return; + + int session = containment->config().readEntry("session", (int)Dock::DefaultSession); + + //! when this containment does not belong to this session + if (session != currentSession() && !m_waitingSessionDocksCreation) { + return; + } + for (auto *dock : m_dockViews) { if (dock->containment() == containment) return; @@ -796,6 +853,8 @@ void DockCorona::addDock(Plasma::Containment *containment) dockView->setOnPrimary(true); } + dockView->setSession(currentSession()); + connect(containment, &QObject::destroyed, this, &DockCorona::dockContainmentDestroyed); connect(containment, &Plasma::Applet::destroyedChanged, this, &DockCorona::destroyedChanged); connect(containment, &Plasma::Applet::locationChanged, this, &DockCorona::dockLocationChanged); @@ -804,6 +863,15 @@ void DockCorona::addDock(Plasma::Containment *containment) dockView->show(); m_dockViews[containment] = dockView; + + if (m_waitingSessionDocksCreation) { + m_waitingSessionDocksCreation = false; + + if (noDocksForSession(currentSession()) == 1) { + syncDockViews(); + } + } + emit docksCountChanged(); } @@ -924,18 +992,22 @@ void DockCorona::loadDefaultLayout() defaultContainment->restore(config); QList edges = freeEdges(defaultContainment->screen()); - if (edges.count() > 0) { + if ((edges.count() > 0) && !m_waitingSessionDocksCreation) { defaultContainment->setLocation(edges.at(0)); } else { defaultContainment->setLocation(Plasma::Types::BottomEdge); } defaultContainment->updateConstraints(Plasma::Types::StartupCompletedConstraint); + defaultContainment->save(config); requestConfigSync(); + defaultContainment->flushPendingConstraintsEvents(); emit containmentAdded(defaultContainment); emit containmentCreated(defaultContainment); + + m_waitingSessionDocksCreation = true; addDock(defaultContainment); defaultContainment->createApplet(QStringLiteral("org.kde.latte.plasmoid")); defaultContainment->createApplet(QStringLiteral("org.kde.plasma.analogclock")); @@ -953,6 +1025,7 @@ bool DockCorona::heuresticForLoadingDockWithTasks() if (plugin == "org.kde.latte.containment") { bool onPrimary = containmentsEntries.group(cId).readEntry("onPrimary", true); int lastScreen = containmentsEntries.group(cId).readEntry("lastScreen", -1); + Dock::SessionType session = (Dock::SessionType)containmentsEntries.group(cId).readEntry("session", (int)Dock::DefaultSession); qDebug() << "containment values: " << onPrimary << " - " << lastScreen; @@ -967,7 +1040,7 @@ bool DockCorona::heuresticForLoadingDockWithTasks() } } - if (containsTasks) { + if (containsTasks && session == Dock::DefaultSession) { m_firstContainmentWithTasks = cId.toInt(); if (onPrimary) { diff --git a/app/dockcorona.h b/app/dockcorona.h index 69f4bbde5..6b47d6d65 100644 --- a/app/dockcorona.h +++ b/app/dockcorona.h @@ -22,6 +22,7 @@ #define DOCKCORONA_H #include "dockview.h" +#include "../liblattedock/dock.h" #include @@ -71,6 +72,10 @@ public: bool raiseDocksTemporary() const; void setRaiseDocksTemporary(bool flag); + Dock::SessionType currentSession(); + void setCurrentSession(Dock::SessionType session); + void switchToSession(Dock::SessionType session); + void aboutApplication(); void closeApplication(); @@ -108,9 +113,13 @@ private: bool containmentContainsTasks(Plasma::Containment *cont); bool containmentExists(uint id) const; bool heuresticForLoadingDockWithTasks(); + int noDocksForSession(Dock::SessionType session); int primaryScreenId() const; bool m_activitiesStarting{true}; + //! used to initialize the docks when changing sessions + bool m_waitingSessionDocksCreation{false}; + //! used to enable/disable raise on activity/desktop changed bool m_raiseDocksTemporary{false}; //! this is used to check if a dock with tasks in it will be loaded on startup bool m_tasksWillBeLoaded{false}; @@ -119,6 +128,8 @@ private: //! with tasks" will be loaded otherwise. Currently the older one dock wins int m_firstContainmentWithTasks{ -1}; + Dock::SessionType m_session{Dock::DefaultSession}; + QHash m_dockViews; QHash m_waitingDockViews; QList m_alternativesObjects; diff --git a/app/dockview.cpp b/app/dockview.cpp index 64552ce30..a5824686a 100644 --- a/app/dockview.cpp +++ b/app/dockview.cpp @@ -127,13 +127,13 @@ DockView::~DockView() this->disconnect(); qDebug() << "dock view connections deleted..."; - if (m_configView) { + /*if (m_configView) { m_configView->hide(); m_configView->deleteLater(); - } + }*/ if (m_visibility) { - delete m_visibility; + m_visibility->deleteLater(); } } @@ -164,6 +164,8 @@ void DockView::init() connect(this, &DockView::onPrimaryChanged, this, &DockView::saveConfig); connect(this, &DockView::onPrimaryChanged, this, &DockView::reconsiderScreen); + connect(this, &DockView::sessionChanged, this, &DockView::saveConfig); + connect(this, &DockView::locationChanged, this, [&]() { updateFormFactor(); syncGeometry(); @@ -777,6 +779,21 @@ void DockView::setOnPrimary(bool flag) emit onPrimaryChanged(); } +Dock::SessionType DockView::session() const +{ + return m_session; +} + +void DockView::setSession(Dock::SessionType type) +{ + if (m_session == type) { + return; + } + + m_session = type; + emit sessionChanged(); +} + float DockView::maxLength() const { return m_maxLength; @@ -1405,6 +1422,7 @@ void DockView::saveConfig() auto config = this->containment()->config(); config.writeEntry("onPrimary", m_onPrimary); + config.writeEntry("session", (int)m_session); this->containment()->configNeedsSaving(); } @@ -1415,6 +1433,7 @@ void DockView::restoreConfig() auto config = this->containment()->config(); setOnPrimary(config.readEntry("onPrimary", true)); + setSession((Dock::SessionType)config.readEntry("session", (int)Dock::DefaultSession)); } //!END configuration functions diff --git a/app/dockview.h b/app/dockview.h index a8c76ed44..d4b4065a5 100644 --- a/app/dockview.h +++ b/app/dockview.h @@ -121,6 +121,9 @@ public: QRect localGeometry() const; void setLocalGeometry(const QRect &geometry); + Dock::SessionType session() const; + void setSession(Dock::SessionType type); + VisibilityManager *visibility() const; QQmlListProperty screens(); @@ -172,6 +175,7 @@ signals: void visibilityChanged(); void maskAreaChanged(); void screenGeometryChanged(); + void sessionChanged(); void shadowChanged(); void xChanged(); void yChanged(); @@ -207,6 +211,7 @@ private: float m_maxLength{1}; Dock::Alignment m_alignment{Dock::Center}; + Dock::SessionType m_session{Dock::DefaultSession}; QRect m_localGeometry; QRect m_absGeometry; diff --git a/liblattedock/dock.h b/liblattedock/dock.h index 13ef1dd01..75900ccd1 100644 --- a/liblattedock/dock.h +++ b/liblattedock/dock.h @@ -54,6 +54,12 @@ public: }; Q_ENUM(Alignment) + enum SessionType { + DefaultSession = 0, + OnTheRoadSession + }; + Q_ENUM(SessionType) + }; }//end of namespace diff --git a/shell/contents/configuration/TweaksConfig.qml b/shell/contents/configuration/TweaksConfig.qml index b4debcc6d..c2eedb96f 100644 --- a/shell/contents/configuration/TweaksConfig.qml +++ b/shell/contents/configuration/TweaksConfig.qml @@ -40,7 +40,7 @@ PlasmaComponents.Page { anchors.centerIn: parent Layout.leftMargin: units.smallSpacing * 2 - //! BEGIN: Tasks Appearance + //! BEGIN: Behavior ColumnLayout { spacing: units.smallSpacing @@ -69,11 +69,37 @@ PlasmaComponents.Page { } } + //! BEGIN: Session + ColumnLayout { + spacing: units.smallSpacing + + Header { + text: i18n("Session") + } + + PlasmaComponents.Button { + Layout.fillWidth: true + text: i18n("On The Road") + checked: dockConfig.currentSession === Latte.Dock.OnTheRoadSession + checkable: true + onClicked: { + if (dockConfig.currentSession === Latte.Dock.DefaultSession){ + dockConfig.currentSession = Latte.Dock.OnTheRoadSession; + } else { + dockConfig.currentSession = Latte.Dock.DefaultSession; + } + } + + } + } + + //! BEGIN: Extra Actions ColumnLayout { spacing: units.smallSpacing Header { + text: i18n("Extra Actions") } @@ -97,7 +123,6 @@ PlasmaComponents.Page { PlasmaComponents.Label{} } - } } }