From 912f2f1cfa26276ed08e9527bc25b70591f29256 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Sun, 14 Nov 2021 13:39:18 +0200 Subject: [PATCH] plasmadesk:fix startup freezes from QDbusInterface --as it appears plasma applets were not the main faulter to blame for startup freezes. The bug was that Latte was trying to communicate with Plasma DBus interface to inform it about docks/panels geometries. For some reason during startup other applets could also were trying the same and for that reason Qt provides a 25sec forced delay in case there are too many such calls. The new approach does not block the startup code at all and it should work at all cases. BUG:444739 FIXED-IN:0.10.4 --- app/plasma/extended/screengeometries.cpp | 86 ++++++++++++++++-------- app/plasma/extended/screengeometries.h | 2 + 2 files changed, 61 insertions(+), 27 deletions(-) diff --git a/app/plasma/extended/screengeometries.cpp b/app/plasma/extended/screengeometries.cpp index 5bf7195a5..10542e080 100644 --- a/app/plasma/extended/screengeometries.cpp +++ b/app/plasma/extended/screengeometries.cpp @@ -60,11 +60,17 @@ ScreenGeometries::~ScreenGeometries() void ScreenGeometries::init() { - QDBusInterface plasmaStrutsIface(PLASMASERVICE, "/StrutManager", PLASMASTRUTNAMESPACE, QDBusConnection::sessionBus()); + qDebug() << " PLASMA STRUTS MANAGER :: checking availability...."; + bool serviceavailable{false}; + + if (QDBusConnection::sessionBus().interface()) { + serviceavailable = QDBusConnection::sessionBus().interface()->isServiceRegistered(PLASMASERVICE).value(); + qDebug() << "PLASMA STRUTS MANAGER :: interface availability :: " << QDBusConnection::sessionBus().interface()->isServiceRegistered(PLASMASERVICE).value(); + } connect(m_corona->universalSettings(), &Latte::UniversalSettings::isAvailableGeometryBroadcastedToPlasmaChanged, this, &ScreenGeometries::onBroadcastToPlasmaChanged); - if (plasmaStrutsIface.isValid()) { + if (serviceavailable) { m_plasmaInterfaceAvailable = true; qDebug() << " PLASMA STRUTS MANAGER :: is available..."; @@ -109,15 +115,54 @@ void ScreenGeometries::onBroadcastToPlasmaChanged() } } -void ScreenGeometries::clearGeometries() +void ScreenGeometries::setPlasmaAvailableScreenRect(const QString &screenName, const QRect &rect) { - if (!m_plasmaInterfaceAvailable) { - return; + QDBusMessage message = QDBusMessage::createMethodCall(PLASMASERVICE, + "/StrutManager", + PLASMASTRUTNAMESPACE, + "setAvailableScreenRect"); + QVariantList args; + + args << LATTESERVICE + << screenName + << rect; + + message.setArguments(args); + QDBusConnection::sessionBus().call(message, QDBus::NoBlock); +} + +void ScreenGeometries::setPlasmaAvailableScreenRegion(const QString &screenName, const QRegion ®ion) +{ + QDBusMessage message = QDBusMessage::createMethodCall(PLASMASERVICE, + "/StrutManager", + PLASMASTRUTNAMESPACE, + "setAvailableScreenRegion"); + + QVariant regionvariant; + + if (!region.isNull()) { + //! transorm QRegion to QList in order to be sent through dbus + QList rects; + foreach (const QRect &rect, region) { + rects << rect; + } + + regionvariant = QVariant::fromValue(rects); } - QDBusInterface plasmaStrutsIface(PLASMASERVICE, "/StrutManager", PLASMASTRUTNAMESPACE, QDBusConnection::sessionBus()); + QVariantList args; + + args << LATTESERVICE + << screenName + << regionvariant; - if (!plasmaStrutsIface.isValid()) { + message.setArguments(args); + QDBusConnection::sessionBus().call(message, QDBus::NoBlock); +} + +void ScreenGeometries::clearGeometries() +{ + if (!m_plasmaInterfaceAvailable) { return; } @@ -126,8 +171,8 @@ void ScreenGeometries::clearGeometries() int scrId = m_corona->screenPool()->id(screen->name()); if (m_corona->screenPool()->hasScreenId(scrId)) { - plasmaStrutsIface.call("setAvailableScreenRect", LATTESERVICE, scrName, QRect()); - plasmaStrutsIface.call("setAvailableScreenRegion", LATTESERVICE, scrName, QVariant()); + setPlasmaAvailableScreenRect(scrName, QRect()); + setPlasmaAvailableScreenRegion(scrName, QRegion()); } } @@ -141,12 +186,6 @@ void ScreenGeometries::updateGeometries() return; } - QDBusInterface plasmaStrutsIface(PLASMASERVICE, "/StrutManager", PLASMASTRUTNAMESPACE, QDBusConnection::sessionBus()); - - if (!plasmaStrutsIface.isValid()) { - return; - } - QStringList availableScreenNames; qDebug() << " PLASMA SCREEN GEOMETRIES, LAST AVAILABLE SCREEN RECTS :: " << m_lastAvailableRect; @@ -178,13 +217,13 @@ void ScreenGeometries::updateGeometries() //! is using a different layout. When the user from Unity is switching to //! Music and afterwards to Canvas the desktop elements are not positioned properly if (m_forceGeometryBroadcast) { - plasmaStrutsIface.call("setAvailableScreenRect", LATTESERVICE, scrName, QRect()); + setPlasmaAvailableScreenRect(scrName, QRect()); } //! Disable checks because of the workaround concerning plasma desktop behavior if (m_forceGeometryBroadcast || (!m_lastAvailableRect.contains(scrName) || m_lastAvailableRect[scrName] != availableRect)) { m_lastAvailableRect[scrName] = availableRect; - plasmaStrutsIface.call("setAvailableScreenRect", LATTESERVICE, scrName, availableRect); + setPlasmaAvailableScreenRect(scrName, availableRect); qDebug() << " PLASMA SCREEN GEOMETRIES, AVAILABLE RECT :: " << screen->name() << " : " << availableRect; } @@ -194,14 +233,7 @@ void ScreenGeometries::updateGeometries() if (!m_lastAvailableRegion.contains(scrName) || m_lastAvailableRegion[scrName] != availableRegion) { m_lastAvailableRegion[scrName] = availableRegion; - - //! transorm QRegion to QList in order to be sent through dbus - QList rects; - foreach (const QRect &rect, availableRegion) { - rects << rect; - } - - plasmaStrutsIface.call("setAvailableScreenRegion", LATTESERVICE, scrName, QVariant::fromValue(rects)); + setPlasmaAvailableScreenRegion(scrName, availableRegion); qDebug() << " PLASMA SCREEN GEOMETRIES, AVAILABLE REGION :: " << screen->name() << " : " << availableRegion; } } @@ -213,8 +245,8 @@ void ScreenGeometries::updateGeometries() for (QString &lastScrName : m_lastScreenNames) { if (!screenIsActive(lastScrName)) { //! screen became inactive and its geometries could be unpublished - plasmaStrutsIface.call("setAvailableScreenRect", LATTESERVICE, lastScrName, QRect()); - plasmaStrutsIface.call("setAvailableScreenRegion", LATTESERVICE, lastScrName, QVariant::fromValue(QList())); + setPlasmaAvailableScreenRect(lastScrName, QRect()); + setPlasmaAvailableScreenRegion(lastScrName, QRegion()); m_lastAvailableRect.remove(lastScrName); m_lastAvailableRegion.remove(lastScrName); diff --git a/app/plasma/extended/screengeometries.h b/app/plasma/extended/screengeometries.h index eede1ba14..ec511d716 100644 --- a/app/plasma/extended/screengeometries.h +++ b/app/plasma/extended/screengeometries.h @@ -43,6 +43,8 @@ private slots: private slots: bool screenIsActive(const QString &screenName) const; + void setPlasmaAvailableScreenRect(const QString &screenName, const QRect &rect); + void setPlasmaAvailableScreenRegion(const QString &screenName, const QRegion ®ion); private: bool m_plasmaInterfaceAvailable{false};