Commit bf6f05bf authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Initialise the orientation sensor at start

Summary: We want to set the right orientation as the system starts.

Reviewers: #plasma, #kwin, zzag, davidedmundson

Reviewed By: #plasma, #kwin, zzag, davidedmundson

Subscribers: zzag, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D20622
parent 3323857a
......@@ -34,38 +34,39 @@ OrientationSensor::OrientationSensor(QObject *parent)
: QObject(parent)
, m_sensor(new QOrientationSensor(this))
{
connect(m_sensor, &QOrientationSensor::readingChanged, this,
[this] {
auto toOrientation = [] (auto reading) {
switch (reading->orientation()) {
case QOrientationReading::Undefined:
return OrientationSensor::Orientation::Undefined;
case QOrientationReading::TopUp:
return OrientationSensor::Orientation::TopUp;
case QOrientationReading::TopDown:
return OrientationSensor::Orientation::TopDown;
case QOrientationReading::LeftUp:
return OrientationSensor::Orientation::LeftUp;
case QOrientationReading::RightUp:
return OrientationSensor::Orientation::RightUp;
case QOrientationReading::FaceUp:
return OrientationSensor::Orientation::FaceUp;
case QOrientationReading::FaceDown:
return OrientationSensor::Orientation::FaceDown;
default:
Q_UNREACHABLE();
}
};
const auto orientation = toOrientation(m_sensor->reading());
if (m_orientation != orientation) {
m_orientation = orientation;
emit orientationChanged();
}
}
);
connect(m_sensor, &QOrientationSensor::readingChanged, this, &OrientationSensor::updateState);
connect(m_sensor, &QOrientationSensor::activeChanged, this, &OrientationSensor::refresh);
}
void OrientationSensor::updateState()
{
auto toOrientation = [] (auto reading) {
switch (reading->orientation()) {
case QOrientationReading::Undefined:
return OrientationSensor::Orientation::Undefined;
case QOrientationReading::TopUp:
return OrientationSensor::Orientation::TopUp;
case QOrientationReading::TopDown:
return OrientationSensor::Orientation::TopDown;
case QOrientationReading::LeftUp:
return OrientationSensor::Orientation::LeftUp;
case QOrientationReading::RightUp:
return OrientationSensor::Orientation::RightUp;
case QOrientationReading::FaceUp:
return OrientationSensor::Orientation::FaceUp;
case QOrientationReading::FaceDown:
return OrientationSensor::Orientation::FaceDown;
default:
Q_UNREACHABLE();
}
};
const auto orientation = toOrientation(m_sensor->reading());
if (m_orientation != orientation) {
m_orientation = orientation;
emit orientationChanged();
}
}
void OrientationSensor::activate()
{
m_userEnabled = !m_userEnabled;
......@@ -96,6 +97,7 @@ void OrientationSensor::refresh()
if (m_sensor->isActive()) {
m_sni->setTitle(i18n("Allow Rotation"));
m_sni->setToolTipTitle(i18n("Automatic screen rotation is enabled"));
updateState();
} else {
QString text;
switch(m_orientation) {
......
......@@ -80,6 +80,7 @@ private:
void loadConfig();
void refresh();
void activate();
void updateState();
QOrientationSensor *m_sensor;
bool m_enabled = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment