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.
This commit is contained in:
Devin Lin 2024-10-03 22:41:29 -07:00
parent fbdd90066d
commit 1ac2745bfb
2 changed files with 17 additions and 5 deletions

View file

@ -13,6 +13,7 @@
#include <QDebug>
#include <QOrientationSensor>
#include <QTimer>
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();
}

View file

@ -27,6 +27,8 @@ Q_SIGNALS:
void availableChanged();
private:
void actuallySetAutoScreenRotationEnabled(bool value);
KScreen::ConfigPtr m_config;
QOrientationSensor *m_sensor;