From f2836a81d7e77735fd0610ca6357de77aa24db3a Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Sun, 17 Dec 2023 17:46:40 -0800 Subject: [PATCH] quicksettings/screenrotation: Ensure that state is up to date when screens are added --- quicksettings/screenrotation/screenrotationutil.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/quicksettings/screenrotation/screenrotationutil.cpp b/quicksettings/screenrotation/screenrotationutil.cpp index a62ed0ae..cc829e20 100644 --- a/quicksettings/screenrotation/screenrotationutil.cpp +++ b/quicksettings/screenrotation/screenrotationutil.cpp @@ -24,7 +24,17 @@ ScreenRotationUtil::ScreenRotationUtil(QObject *parent) connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished, this, [this](auto *op) { m_config = qobject_cast(op)->config(); + // update all screens with event connect Q_EMIT autoScreenRotationEnabledChanged(); + for (KScreen::OutputPtr output : m_config->outputs()) { + connect(output.data(), &KScreen::Output::autoRotatePolicyChanged, this, &ScreenRotationUtil::autoScreenRotationEnabledChanged); + } + + // listen to all new screens and connect + connect(m_config.data(), &KScreen::Config::outputAdded, this, [this](const auto &output) { + Q_EMIT autoScreenRotationEnabledChanged(); + connect(output.data(), &KScreen::Output::autoRotatePolicyChanged, this, &ScreenRotationUtil::autoScreenRotationEnabledChanged); + }); }); }