From 1ac2745bfb90e2b201b07438a985988af8a59a93 Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Thu, 3 Oct 2024 22:41:29 -0700 Subject: [PATCH] quicksettings/screenrotation: Don't call rotate in signal handler This is a workaround for https://invent.kde.org/plasma/plasma-mobile/-/issues/405, where if the caller gets deleted by the screen rotation, the entire shell crashes. Eventually, we need to implement https://invent.kde.org/plasma/plasma-mobile/-/issues/406 to reduce the amount of oddities we have from recreating the quick settings panel during screen rotation. --- .../screenrotation/screenrotationutil.cpp | 20 ++++++++++++++----- .../screenrotation/screenrotationutil.h | 2 ++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/quicksettings/screenrotation/screenrotationutil.cpp b/quicksettings/screenrotation/screenrotationutil.cpp index f9a1d080..4e94a9a8 100644 --- a/quicksettings/screenrotation/screenrotationutil.cpp +++ b/quicksettings/screenrotation/screenrotationutil.cpp @@ -13,6 +13,7 @@ #include #include +#include ScreenRotationUtil::ScreenRotationUtil(QObject *parent) : QObject{parent} @@ -57,6 +58,20 @@ bool ScreenRotationUtil::autoScreenRotationEnabled() } void ScreenRotationUtil::setAutoScreenRotationEnabled(bool value) +{ + // Don't execute immediately, in case the screen rotation + // deletes the caller mid-function call, causing a crash. + QTimer::singleShot(0, this, [this, value]() { + actuallySetAutoScreenRotationEnabled(value); + }); +} + +bool ScreenRotationUtil::isAvailable() +{ + return m_sensor->connectToBackend(); +} + +void ScreenRotationUtil::actuallySetAutoScreenRotationEnabled(bool value) { if (!m_config) { return; @@ -76,8 +91,3 @@ void ScreenRotationUtil::setAutoScreenRotationEnabled(bool value) Q_EMIT autoScreenRotationEnabledChanged(); } - -bool ScreenRotationUtil::isAvailable() -{ - return m_sensor->connectToBackend(); -} diff --git a/quicksettings/screenrotation/screenrotationutil.h b/quicksettings/screenrotation/screenrotationutil.h index 32c49346..0039720a 100644 --- a/quicksettings/screenrotation/screenrotationutil.h +++ b/quicksettings/screenrotation/screenrotationutil.h @@ -27,6 +27,8 @@ Q_SIGNALS: void availableChanged(); private: + void actuallySetAutoScreenRotationEnabled(bool value); + KScreen::ConfigPtr m_config; QOrientationSensor *m_sensor;