diff --git a/app/dockcorona.cpp b/app/dockcorona.cpp index a13a27028..c5ad2c5e7 100644 --- a/app/dockcorona.cpp +++ b/app/dockcorona.cpp @@ -58,7 +58,6 @@ DockCorona::DockCorona(QObject *parent) qmlRegisterTypes(); connect(this, &Corona::containmentAdded, this, &DockCorona::addDock); - connect(m_activityConsumer, &KActivities::Consumer::serviceStatusChanged, this, &DockCorona::load); } @@ -145,9 +144,9 @@ int DockCorona::docksCount(int screen) const { if (screen == -1) return 0; - + int docks{0}; - + for (const auto &view : m_dockViews) { if (view && view->containment() && view->containment()->screen() == screen @@ -155,9 +154,9 @@ int DockCorona::docksCount(int screen) const ++docks; } } - + qDebug() << docks << "docks on screen:" << screen; - + return docks; } @@ -171,11 +170,11 @@ QList DockCorona::freeEdges(int screen) const using Plasma::Types; QList edges{Types::BottomEdge, Types::LeftEdge, Types::TopEdge, Types::RightEdge}; - + //when screen=-1 is passed then the primaryScreenid is used int fixedScreen = (screen == -1) ? primaryScreenId() : screen; - for (const auto &view : m_dockViews) { + for (auto *view : m_dockViews) { if (view && view->containment() && view->containment()->screen() == fixedScreen) { edges.removeOne(view->location()); @@ -203,18 +202,16 @@ void DockCorona::addDock(Plasma::Containment *containment) return; } + auto metadata = containment->kPackage().metadata(); + // the system tray is a containment that behaves as an applet // so a dockview shouldnt be created for it - KPluginMetaData metadata = containment->kPackage().metadata(); - - if (metadata.pluginId() == "org.kde.plasma.private.systemtray") { + if (metadata.pluginId() != "org.kde.latte.containment") return; - } - - foreach (DockView *dock, m_dockViews) { - if (dock->containment() == containment) { + + for (auto *dock : m_dockViews) { + if (dock->containment() == containment) return; - } } qDebug() << "Adding dock for container..."; @@ -229,32 +226,35 @@ void DockCorona::addDock(Plasma::Containment *containment) m_dockViews[containment] = dockView; - emit containmentsNoChanged(); + emit docksCountChanged(); } void DockCorona::destroyedChanged(bool destroyed) { Plasma::Containment *sender = qobject_cast(QObject::sender()); - + if (!sender) { return; } - + if (destroyed) { m_waitingDockViews[sender] = m_dockViews.take(static_cast(sender)); } else { m_dockViews[sender] = m_waitingDockViews.take(static_cast(sender)); } - - emit containmentsNoChanged(); + + emit docksCountChanged(); } void DockCorona::dockContainmentDestroyed(QObject *cont) { auto view = m_waitingDockViews.take(static_cast(cont)); - delete view; + + if (view) + view->destroy(); + //view->deleteLater(); - emit containmentsNoChanged(); + emit docksCountChanged(); } void DockCorona::loadDefaultLayout() @@ -300,13 +300,6 @@ void DockCorona::loadDefaultLayout() inline void DockCorona::qmlRegisterTypes() const { - constexpr auto uri = "org.kde.latte.shell"; - constexpr auto vMajor = 0; - constexpr auto vMinor = 2; - - // qmlRegisterUncreatableType(uri, vMajor, vMinor, "Dock", "class Dock uncreatable"); - // qmlRegisterUncreatableType(uri, vMajor, vMinor, "VisibilityManager", "class VisibilityManager uncreatable"); - // qmlRegisterUncreatableType(uri, vMajor, vMinor, "DockView", "class DockView uncreatable"); qmlRegisterType(); } diff --git a/app/dockcorona.h b/app/dockcorona.h index 3915ebfec..618728d61 100644 --- a/app/dockcorona.h +++ b/app/dockcorona.h @@ -53,7 +53,7 @@ public: int docksCount(int screen) const; int screenForContainment(const Plasma::Containment *containment) const override; - + void addDock(Plasma::Containment *containment); void closeApplication(); @@ -64,7 +64,7 @@ public slots: signals: void configurationShown(PlasmaQuick::ConfigView *configView); - void containmentsNoChanged(); + void docksCountChanged(); private slots: void destroyedChanged(bool destroyed); diff --git a/app/dockview.cpp b/app/dockview.cpp index f06eed535..485f19cb1 100644 --- a/app/dockview.cpp +++ b/app/dockview.cpp @@ -46,7 +46,6 @@ namespace Latte { DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen) : PlasmaQuick::ContainmentView(corona), - m_docksCount(0), m_contextMenu(nullptr) { setVisible(false); @@ -60,12 +59,12 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen) adaptToScreen(targetScreen); else adaptToScreen(qGuiApp->primaryScreen()); - + connect(this, &DockView::containmentChanged , this, [&]() { if (!containment()) return; - + if (!m_visibility) { m_visibility = new VisibilityManager(this); } @@ -83,15 +82,15 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen) QAction *addWidgetsAction = containment()->actions()->action("add widgets"); addWidgetsAction->setVisible(false); //containment()->actions()->removeAction(addWidgetsAction); - + connect(containment(), SIGNAL(statusChanged(Plasma::Types::ItemStatus)), SLOT(statusChanged(Plasma::Types::ItemStatus))); }, Qt::DirectConnection); - DockCorona *dcorona = qobject_cast(this->corona()); + auto *dockCorona = qobject_cast(this->corona()); - if (dcorona) { - connections << connect(dcorona, &DockCorona::containmentsNoChanged, this, &DockView::updateDocksCount); + if (dockCorona) { + connect(dockCorona, &DockCorona::docksCountChanged, this, &DockView::docksCountChanged); } } @@ -130,7 +129,6 @@ void DockView::init() setVisible(true); - updateDocksCount(); syncGeometry(); qDebug() << "SOURCE:" << source(); } @@ -143,27 +141,27 @@ void DockView::adaptToScreen(QScreen *screen) m_maxLength = screen->size().height(); else m_maxLength = screen->size().width(); - + if (containment()) containment()->reactToScreenChange(); - + syncGeometry(); } void DockView::addNewDock() { - DockCorona *corona = qobject_cast(this->corona()); + auto *dockCorona = qobject_cast(this->corona()); - if (corona) { - corona->loadDefaultLayout(); + if (dockCorona) { + dockCorona->loadDefaultLayout(); } } void DockView::removeDock() { - if (m_docksCount > 1) { + if (docksCount() > 1) { QAction *removeAct = containment()->actions()->action(QStringLiteral("remove")); - + if (removeAct) { removeAct->trigger(); } @@ -191,7 +189,7 @@ void DockView::showConfigurationInterface(Plasma::Applet *applet) { if (!applet || !applet->containment()) return; - + Plasma::Containment *c = qobject_cast(applet); if (m_configView && c && c->isContainment() && c == containment()) { @@ -199,7 +197,6 @@ void DockView::showConfigurationInterface(Plasma::Applet *applet) m_configView->hide(); } else { m_configView->show(); - //m_configView->requestActivate(); } return; @@ -267,7 +264,7 @@ void DockView::updateAbsDockGeometry() { if (!m_visibility) return; - + QRect absoluteGeometry {x() + m_localDockGeometry.x(), y() + m_localDockGeometry.y(), m_localDockGeometry.width(), m_localDockGeometry.height()}; m_visibility->updateDockGeometry(absoluteGeometry); } @@ -276,34 +273,33 @@ void DockView::updatePosition() { if (!containment()) return; - + const QRect screenGeometry = screen()->geometry(); QPoint position; position = {0, 0}; - m_maxLength = screenGeometry.width(); switch (location()) { case Plasma::Types::TopEdge: position = {screenGeometry.x(), screenGeometry.y()}; m_maxLength = screenGeometry.width(); break; - + case Plasma::Types::BottomEdge: position = {screenGeometry.x(), screenGeometry.y() + screenGeometry.height() - height()}; m_maxLength = screenGeometry.width(); break; - + case Plasma::Types::RightEdge: position = {screenGeometry.x() + screenGeometry.width() - width(), screenGeometry.y()}; m_maxLength = screenGeometry.height(); break; - + case Plasma::Types::LeftEdge: position = {screenGeometry.x(), screenGeometry.y()}; m_maxLength = screenGeometry.height(); break; - + default: qWarning() << "wrong location, couldn't update the panel position" << location(); @@ -330,13 +326,8 @@ void DockView::statusChanged(Plasma::Types::ItemStatus status) } else { m_visibility->setBlockHiding(false); } - - /*} else if (status == Plasma::Types::AcceptingInputStatus) { - KWindowSystem::forceActiveWindow(winId());*/ - } - int DockView::currentThickness() const { if (formFactor() == Plasma::Types::Vertical) { @@ -349,48 +340,29 @@ int DockView::currentThickness() const int DockView::docksCount() const { auto dockCorona = qobject_cast(corona()); - + if (!dockCorona || !containment()) return 0; - + return dockCorona->docksCount(containment()->screen()); } -void DockView::updateDocksCount() -{ - auto *dockCorona = qobject_cast(this->corona()); - - if (!dockCorona || !containment()) { - return ; - } - - int count = dockCorona->docksCount(containment()->screen()); - - if (count == m_docksCount) { - return; - } - - m_docksCount = count; - - emit docksCountChanged(); -} - void DockView::updateFormFactor() { if (!containment()) return; - + switch (location()) { case Plasma::Types::TopEdge: case Plasma::Types::BottomEdge: containment()->setFormFactor(Plasma::Types::Horizontal); break; - + case Plasma::Types::LeftEdge: case Plasma::Types::RightEdge: containment()->setFormFactor(Plasma::Types::Vertical); break; - + default: qWarning() << "wrong location, couldn't update the panel position" << location(); } @@ -405,31 +377,12 @@ void DockView::setMaxThickness(int thickness) { if (m_maxThickness == thickness) return; - + m_maxThickness = thickness; syncGeometry(); emit maxThicknessChanged(); } -int DockView::length() const -{ - return m_length; -} - -void DockView::setLength(int length) -{ - if (m_length == length) - return; - - if (length > m_maxLength) - m_length = m_maxLength; - else - m_length = length; - - syncGeometry(); - emit lengthChanged(); -} - int DockView::maxLength() const { return m_maxLength; @@ -439,12 +392,11 @@ void DockView::setMaxLength(int maxLength) { if (m_maxLength == maxLength) return; - + m_maxLength = maxLength; emit maxLengthChanged(); } - QRect DockView::maskArea() const { return m_maskArea; @@ -454,9 +406,8 @@ void DockView::setMaskArea(QRect area) { if (m_maskArea == area) return; - + m_maskArea = area; - setMask(m_maskArea); //qDebug() << "dock mask set:" << m_maskArea; @@ -470,12 +421,10 @@ int DockView::shadow() const void DockView::setShadow(int shadow) { - if (m_shadow == shadow) { + if (m_shadow == shadow) return; - } - + m_shadow = shadow; - emit shadowChanged(); } @@ -484,9 +433,8 @@ bool DockView::tasksPresent() foreach (Plasma::Applet *applet, containment()->applets()) { KPluginMetaData meta = applet->kPackage().metadata(); - if (meta.pluginId() == "org.kde.latte.plasmoid") { + if (meta.pluginId() == "org.kde.latte.plasmoid") return true; - } } return false; @@ -506,7 +454,7 @@ bool DockView::event(QEvent *e) QList DockView::freeEdges() const { - QList edges = corona()->freeEdges(containment()->screen()); + const auto edges = corona()->freeEdges(containment()->screen()); QList edgesInt; @@ -519,14 +467,14 @@ QList DockView::freeEdges() const void DockView::closeApplication() { - DockCorona *corona = qobject_cast(this->corona()); + DockCorona *dockCorona = qobject_cast(this->corona()); - if (corona) { + if (dockCorona) { //m_configView->hide(); if (m_configView) m_configView->deleteLater(); - - corona->closeApplication(); + + dockCorona->closeApplication(); } } diff --git a/app/dockview.h b/app/dockview.h index 9c5e5009d..ccafb6922 100644 --- a/app/dockview.h +++ b/app/dockview.h @@ -44,118 +44,107 @@ namespace Latte { class DockView : public PlasmaQuick::ContainmentView { Q_OBJECT - + Q_PROPERTY(int docksCount READ docksCount NOTIFY docksCountChanged) Q_PROPERTY(int width READ width NOTIFY widthChanged) Q_PROPERTY(int height READ height NOTIFY heightChanged) - Q_PROPERTY(int length READ length WRITE setLength NOTIFY lengthChanged) Q_PROPERTY(int maxLength READ maxLength WRITE setMaxLength NOTIFY maxLengthChanged) Q_PROPERTY(int maxThickness READ maxThickness WRITE setMaxThickness NOTIFY maxThicknessChanged) Q_PROPERTY(int shadow READ shadow WRITE setShadow NOTIFY shadowChanged) - + Q_PROPERTY(QRect maskArea READ maskArea WRITE setMaskArea NOTIFY maskAreaChanged) Q_PROPERTY(VisibilityManager *visibility READ visibility NOTIFY visibilityChanged) Q_PROPERTY(QQmlListProperty screens READ screens) - + public: DockView(Plasma::Corona *corona, QScreen *targetScreen = nullptr); virtual ~DockView(); - + void init(); - + void adaptToScreen(QScreen *screen); - + void resizeWindow(); void syncGeometry(); - + int currentThickness() const; void updateAbsDockGeometry(); - + int docksCount() const; - - int length() const; - void setLength(int length); - + int maxLength() const; void setMaxLength(int maxLength); - + int maxThickness() const; void setMaxThickness(int thickness); - + int shadow() const; void setShadow(int shadow); - + QRect maskArea() const; void setMaskArea(QRect area); - + VisibilityManager *visibility(); - + QQmlListProperty screens(); static int countScreens(QQmlListProperty *property); static QScreen *atScreens(QQmlListProperty *property, int index); - + public slots: Q_INVOKABLE void addAppletItem(QObject *item); Q_INVOKABLE void removeAppletItem(QObject *item); - + Q_INVOKABLE void addNewDock(); Q_INVOKABLE void removeDock(); - + Q_INVOKABLE QList freeEdges() const; Q_INVOKABLE QVariantList containmentActions(); Q_INVOKABLE void setLocalDockGeometry(const QRect &geometry); Q_INVOKABLE bool tasksPresent(); - + Q_INVOKABLE void closeApplication(); - + protected slots: void showConfigurationInterface(Plasma::Applet *applet) override; - + protected: bool event(QEvent *ev) override; void mousePressEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; - + signals: void addInternalViewSplitter(); void removeInternalViewSplitter(); void eventTriggered(QEvent *ev); - + void docksCountChanged(); void widthChanged(); void heightChanged(); - void lengthChanged(); void maxLengthChanged(); void maxThicknessChanged(); void visibilityChanged(); void maskAreaChanged(); void shadowChanged(); - + void localDockGeometryChanged(); - + private slots: void menuAboutToHide(); void statusChanged(Plasma::Types::ItemStatus); - + private: void initWindow(); - + void addAppletActions(QMenu *desktopMenu, Plasma::Applet *applet, QEvent *event); void addContainmentActions(QMenu *desktopMenu, QEvent *event); void updatePosition(); - - void updateDocksCount(); void updateFormFactor(); - + private: - bool m_secondInitPass; - - int m_docksCount; - int m_length{0}; int m_maxLength{INT_MAX}; int m_maxThickness{24}; int m_shadow{0}; - + QRect m_localDockGeometry; QRect m_maskArea; QMenu *m_contextMenu; diff --git a/app/visibilitymanager.cpp b/app/visibilitymanager.cpp index 55f2ec23c..6386a333c 100644 --- a/app/visibilitymanager.cpp +++ b/app/visibilitymanager.cpp @@ -90,15 +90,15 @@ inline void VisibilityManagerPrivate::setMode(Dock::Visibility mode) case Dock::AlwaysVisible: { if (view->containment() && !view->containment()->isUserConfiguring()) wm->setDockStruts(dockRect, view->location()); - + connections[0] = connect(view->containment(), &Plasma::Containment::locationChanged - , this, [&]() { + , this, [&]() { if (view->containment()->isUserConfiguring()) wm->removeDockStruts(); }); connections[1] = connect(view->containment(), &Plasma::Containment::userConfiguringChanged - , this, [&](bool configuring) { + , this, [&](bool configuring) { if (!configuring) wm->setDockStruts(dockRect, view->containment()->location()); }); diff --git a/shell/contents/views/Panel.qml b/shell/contents/views/Panel.qml index d6ac7015e..376aa03b1 100644 --- a/shell/contents/views/Panel.qml +++ b/shell/contents/views/Panel.qml @@ -90,25 +90,8 @@ PlasmaCore.FrameSvgItem { } } - Binding { - target: dock - property: "length" - when: containment - value: { - if (!containment) { - return; - } - if (verticalPanel) { - return containment.Layout.preferredHeight - } else { - return containment.Layout.preferredWidth - } - } - } - - Item { id: containmentParent anchors.fill: parent } -} +}