Git commit ea95ebd0cdc8991938994daadaccea883ceabacc by Luca Beltrame. Committed on 24/04/2021 at 22:15. Pushed by lbeltrame into branch 'master'.
Revert "don't make config key change and size change conflict" This reverts commit 156509b785b6b4312d984841f9ba6375687389d3. At least this prevents plasmashell from crashing until a solution is found. CCMAIL: notm...@gmail.com CCMAIL: plasma-devel@kde.org CCBUG: 436041 M +32 -58 components/containmentlayoutmanager/appletslayout.cpp M +2 -22 components/containmentlayoutmanager/appletslayout.h https://invent.kde.org/plasma/plasma-workspace/commit/ea95ebd0cdc8991938994daadaccea883ceabacc diff --git a/components/containmentlayoutmanager/appletslayout.cpp b/components/containmentlayoutmanager/appletslayout.cpp index 64de4006c..c9cf2ebca 100644 --- a/components/containmentlayoutmanager/appletslayout.cpp +++ b/components/containmentlayoutmanager/appletslayout.cpp @@ -47,11 +47,9 @@ AppletsLayout::AppletsLayout(QQuickItem *parent) connect(m_saveLayoutTimer, &QTimer::timeout, this, [this]() { // We can't save the layout during bootup, for performance reasons and to avoid race consitions as much as possible, so if we needto save and still starting up, // don't actually savenow, but we will when Corona::startupCompleted is emitted - if (!m_configKey.isEmpty() && m_containment && m_containment->corona()->isStartupCompleted()) { const QString serializedConfig = m_layoutManager->serializeLayout(); m_containment->config().writeEntry(m_configKey, serializedConfig); - m_containment->config().writeEntry(m_fallbackConfigKey, serializedConfig); // FIXME: something more efficient m_layoutManager->parseLayout(serializedConfig); m_savedSize = size(); @@ -59,43 +57,44 @@ AppletsLayout::AppletsLayout(QQuickItem *parent) } }); - m_layoutChangeTimer = new QTimer(this); - m_layoutChangeTimer->setSingleShot(true); - m_layoutChangeTimer->setInterval(100); - connect(m_layoutChangeTimer, &QTimer::timeout, this, [this]() { - const QString &serializedConfig = m_containment->config().readEntry(m_configKey, ""); - if ((m_layoutChanges & ConfigKeyChange) && !serializedConfig.isEmpty()) { - if (!m_configKey.isEmpty() && m_containment) { - m_layoutManager->parseLayout(serializedConfig); - - if (width() > 0 && height() > 0) { - m_layoutManager->resetLayoutFromConfig(); - m_savedSize = size(); - } - } - } else if (m_layoutChanges & SizeChange) { - const QRect newGeom(x(), y(), width(), height()); - // The size has been restored from the last one it has been saved: restore that exact same layout - if (newGeom.size() == m_savedSize) { - m_layoutManager->resetLayoutFromConfig(); - - // If the resize is consequence of a screen resolution change, queue a relayout maintaining the distance between screen edges - } else if (!m_geometryBeforeResolutionChange.isEmpty()) { - m_layoutManager->layoutGeometryChanged(newGeom, m_geometryBeforeResolutionChange); - m_geometryBeforeResolutionChange = QRectF(); + m_configKeyChangeTimer = new QTimer(this); + m_configKeyChangeTimer->setSingleShot(true); + m_configKeyChangeTimer->setInterval(100); + connect(m_configKeyChangeTimer, &QTimer::timeout, this, [this]() { + if (!m_configKey.isEmpty() && m_containment) { + m_layoutManager->parseLayout(m_containment->config().readEntry(m_configKey, "")); - // Heuristically relayout items only when the plasma startup is fully completed - } else { - polish(); + if (width() > 0 && height() > 0) { + m_layoutManager->resetLayoutFromConfig(); + m_savedSize = size(); } } - m_layoutChanges = NoChange; }); m_pressAndHoldTimer = new QTimer(this); m_pressAndHoldTimer->setSingleShot(true); connect(m_pressAndHoldTimer, &QTimer::timeout, this, [this]() { setEditMode(true); }); + + m_sizeSyncTimer = new QTimer(this); + m_sizeSyncTimer->setSingleShot(true); + m_sizeSyncTimer->setInterval(150); + connect(m_sizeSyncTimer, &QTimer::timeout, this, [this]() { + const QRect newGeom(x(), y(), width(), height()); + // The size has been restored from the last one it has been saved: restore that exact same layout + if (newGeom.size() == m_savedSize) { + m_layoutManager->resetLayoutFromConfig(); + + // If the resize is consequence of a screen resolution change, queue a relayout maintaining the distance between screen edges + } else if (!m_geometryBeforeResolutionChange.isEmpty()) { + m_layoutManager->layoutGeometryChanged(newGeom, m_geometryBeforeResolutionChange); + m_geometryBeforeResolutionChange = QRectF(); + + // Heuristically relayout items only when the plasma startup is fully completed + } else { + polish(); + } + }); } AppletsLayout::~AppletsLayout() @@ -151,30 +150,11 @@ void AppletsLayout::setConfigKey(const QString &key) m_configKey = key; // Reloading everything from the new config is expansive, event compress it - m_layoutChanges |= ConfigKeyChange; - m_layoutChangeTimer->start(); + m_configKeyChangeTimer->start(); emit configKeyChanged(); } -QString AppletsLayout::fallbackConfigKey() const -{ - return m_fallbackConfigKey; -} - -void AppletsLayout::setFallbackConfigKey(const QString &key) -{ - if (m_fallbackConfigKey == key) { - return; - } - - m_fallbackConfigKey = key; - - - - emit fallbackConfigKeyChanged(); -} - QJSValue AppletsLayout::acceptsAppletCallback() const { return m_acceptsAppletCallback; @@ -475,8 +455,7 @@ void AppletsLayout::geometryChanged(const QRectF &newGeometry, const QRectF &old // Only do a layouting procedure if we received a valid size if (!newGeometry.isEmpty()) { - m_layoutChanges |= SizeChange; - m_layoutChangeTimer->start(); + m_sizeSyncTimer->start(); } QQuickItem::geometryChanged(newGeometry, oldGeometry); @@ -496,12 +475,7 @@ void AppletsLayout::componentComplete() } if (!m_configKey.isEmpty()) { - const QString &serializedConfig = m_containment->config().readEntry(m_configKey, ""); - if (!serializedConfig.isEmpty()) { - m_layoutManager->parseLayout(serializedConfig); - } else { - m_layoutManager->parseLayout(m_containment->config().readEntry(m_fallbackConfigKey, "")); - } + m_layoutManager->parseLayout(m_containment->config().readEntry(m_configKey, "")); } const QList<QObject *> appletObjects = m_containmentItem->property("applets").value<QList<QObject *>>(); diff --git a/components/containmentlayoutmanager/appletslayout.h b/components/containmentlayoutmanager/appletslayout.h index c27d9d6f7..fc8b65afb 100644 --- a/components/containmentlayoutmanager/appletslayout.h +++ b/components/containmentlayoutmanager/appletslayout.h @@ -48,11 +48,6 @@ class AppletsLayout : public QQuickItem Q_PROPERTY(QString configKey READ configKey WRITE setConfigKey NOTIFY configKeyChanged) - // A config key that can be used as fallback when loading and configKey is not found - // Is always a backup of the last used configKey. Useful when the configkey depends - // from the screen size and plasma starts on an "unexpected" size - Q_PROPERTY(QString fallbackConfigKey READ fallbackConfigKey WRITE setFallbackConfigKey NOTIFY fallbackConfigKeyChanged) - Q_PROPERTY(PlasmaQuick::AppletQuickItem *containment READ containment WRITE setContainment NOTIFY containmentChanged) Q_PROPERTY(QJSValue acceptsAppletCallback READ acceptsAppletCallback WRITE setAcceptsAppletCallback NOTIFY acceptsAppletCallbackChanged) @@ -100,13 +95,6 @@ public: }; Q_ENUM(EditModeCondition) - enum LayoutChange { - NoChange = 0, - SizeChange = 1, - ConfigKeyChange = 2 - }; - Q_DECLARE_FLAGS(LayoutChanges, LayoutChange) - AppletsLayout(QQuickItem *parent = nullptr); ~AppletsLayout(); @@ -114,9 +102,6 @@ public: QString configKey() const; void setConfigKey(const QString &key); - QString fallbackConfigKey() const; - void setFallbackConfigKey(const QString &key); - PlasmaQuick::AppletQuickItem *containment() const; void setContainment(PlasmaQuick::AppletQuickItem *containment); @@ -175,7 +160,6 @@ Q_SIGNALS: void appletRefused(QObject *applet, int x, int y); void configKeyChanged(); - void fallbackConfigKeyChanged(); void containmentChanged(); void minimumItemWidthChanged(); void minimumItemHeightChanged(); @@ -210,10 +194,8 @@ private: AppletContainer *createContainerForApplet(PlasmaQuick::AppletQuickItem *appletItem); QString m_configKey; - QString m_fallbackConfigKey; QTimer *m_saveLayoutTimer; - QTimer *m_layoutChangeTimer; - LayoutChanges m_layoutChanges = NoChange; + QTimer *m_configKeyChangeTimer; PlasmaQuick::AppletQuickItem *m_containmentItem = nullptr; Plasma::Containment *m_containment = nullptr; @@ -225,6 +207,7 @@ private: QPointer<QQuickItem> m_eventManagerToFilter; QTimer *m_pressAndHoldTimer; + QTimer *m_sizeSyncTimer; QJSValue m_acceptsAppletCallback; @@ -240,7 +223,4 @@ private: QPointF m_mouseDownPosition = QPoint(-1, -1); bool m_mouseDownWasEditMode = false; bool m_editMode = false; - bool m_sizeSpecificLayouts = false; }; - -Q_DECLARE_OPERATORS_FOR_FLAGS(AppletsLayout::LayoutChanges)