From 088c0d985b0b04dfd8ad6f996756644044adeb30 Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Fri, 5 Dec 2025 00:04:02 -0500 Subject: [PATCH] kscreen: Retry fetching config if kscreen gives nullptr Apparently GetConfigOperation can retrieve a nullptr config, in which case we just need to retry until kscreen gives us something. --- .../panelsettingsdbusobjectmanager.cpp | 6 ++++-- components/rotationplugin/rotationutil.cpp | 13 ++++++++++--- components/rotationplugin/rotationutil.h | 2 ++ initialstart/modules/prepare/prepareutil.cpp | 4 +++- quicksettings/kscreenosd/kscreenosdutil.cpp | 6 +++++- quicksettings/kscreenosd/kscreenosdutil.h | 2 ++ 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/components/mobileshellstate/panelsettingsdbusobjectmanager.cpp b/components/mobileshellstate/panelsettingsdbusobjectmanager.cpp index 7db52ce8..375e111e 100644 --- a/components/mobileshellstate/panelsettingsdbusobjectmanager.cpp +++ b/components/mobileshellstate/panelsettingsdbusobjectmanager.cpp @@ -58,15 +58,17 @@ void PanelSettingsDBusObjectManager::registerObjects() return; } - m_initialized = true; - // Fetch kscreen config connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished, this, [this](auto *op) { m_kscreenConfig = qobject_cast(op)->config(); if (!m_kscreenConfig) { + qDebug() << "PanelSettingsDBusObjectManager: Failed to get kscreen config, attempting again"; + registerObjects(); return; } + m_initialized = true; + KScreen::ConfigMonitor::instance()->addConfig(m_kscreenConfig); // Listen to all new screens and create a new output diff --git a/components/rotationplugin/rotationutil.cpp b/components/rotationplugin/rotationutil.cpp index c1ba46ee..86266c46 100644 --- a/components/rotationplugin/rotationutil.cpp +++ b/components/rotationplugin/rotationutil.cpp @@ -53,10 +53,20 @@ RotationUtil::Rotation mapRotation(KScreen::Output::Rotation rotation) RotationUtil::RotationUtil(QObject *parent) : QObject{parent} , m_sensor{new QOrientationSensor(this)} +{ + retrieveKScreen(); + + connect(m_sensor, &QOrientationSensor::readingChanged, this, &RotationUtil::updateShowRotationButton); + m_sensor->start(); +} + +void RotationUtil::retrieveKScreen() { connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished, this, [this](auto *op) { m_config = qobject_cast(op)->config(); if (!m_config) { + qDebug() << "RotationUtil: Failed to get kscreen config, attempting again"; + retrieveKScreen(); return; } KScreen::ConfigMonitor::instance()->addConfig(m_config); @@ -71,9 +81,6 @@ RotationUtil::RotationUtil(QObject *parent) connect(output.data(), &KScreen::Output::autoRotatePolicyChanged, this, &RotationUtil::updateShowRotationButton); }); }); - - connect(m_sensor, &QOrientationSensor::readingChanged, this, &RotationUtil::updateShowRotationButton); - m_sensor->start(); } void RotationUtil::rotateToSuggestedRotation() diff --git a/components/rotationplugin/rotationutil.h b/components/rotationplugin/rotationutil.h index 8a9af36b..adf3cb1d 100644 --- a/components/rotationplugin/rotationutil.h +++ b/components/rotationplugin/rotationutil.h @@ -47,6 +47,8 @@ private Q_SLOTS: void updateShowRotationButton(); private: + void retrieveKScreen(); + bool m_showRotationButton{false}; KScreen::Output::Rotation m_rotateTo; Rotation m_deviceRotation; diff --git a/initialstart/modules/prepare/prepareutil.cpp b/initialstart/modules/prepare/prepareutil.cpp index 409af2cf..9747b519 100644 --- a/initialstart/modules/prepare/prepareutil.cpp +++ b/initialstart/modules/prepare/prepareutil.cpp @@ -26,10 +26,12 @@ void PrepareUtil::initKScreen(std::function callback) { connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished, this, [this, callback](auto *op) { m_config = qobject_cast(op)->config(); - if (!m_config) { + qDebug() << "PrepareUtil: Failed to get kscreen config, attempting again"; + initKScreen(callback); return; } + KScreen::ConfigMonitor::instance()->addConfig(m_config); int scaling = 100; diff --git a/quicksettings/kscreenosd/kscreenosdutil.cpp b/quicksettings/kscreenosd/kscreenosdutil.cpp index 3aa2355c..d5db928d 100644 --- a/quicksettings/kscreenosd/kscreenosdutil.cpp +++ b/quicksettings/kscreenosd/kscreenosdutil.cpp @@ -20,11 +20,15 @@ KScreenOSDUtil::KScreenOSDUtil(QObject *parent) } setOutputs(m_config->outputs().size()); }); +} +void KScreenOSDUtil::retrieveKScreen() +{ connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished, this, [this](auto *op) { m_config = qobject_cast(op)->config(); if (!m_config) { - qDebug() << "kscreenosdutil: Unable to obtain kscreen config"; + qDebug() << "kscreenosdutil: Unable to obtain kscreen config, attempting again"; + retrieveKScreen(); return; } KScreen::ConfigMonitor::instance()->addConfig(m_config); diff --git a/quicksettings/kscreenosd/kscreenosdutil.h b/quicksettings/kscreenosd/kscreenosdutil.h index 2e910db7..73a95864 100644 --- a/quicksettings/kscreenosd/kscreenosdutil.h +++ b/quicksettings/kscreenosd/kscreenosdutil.h @@ -23,6 +23,8 @@ Q_SIGNALS: void outputsChanged(); private: + void retrieveKScreen(); + KScreen::ConfigPtr m_config{nullptr}; int m_outputs{0};