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
This commit is contained in:
parent
3323857a64
commit
bf6f05bf3c
2 changed files with 32 additions and 29 deletions
|
@ -34,38 +34,39 @@ OrientationSensor::OrientationSensor(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_sensor(new QOrientationSensor(this))
|
, m_sensor(new QOrientationSensor(this))
|
||||||
{
|
{
|
||||||
connect(m_sensor, &QOrientationSensor::readingChanged, this,
|
connect(m_sensor, &QOrientationSensor::readingChanged, this, &OrientationSensor::updateState);
|
||||||
[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::activeChanged, this, &OrientationSensor::refresh);
|
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()
|
void OrientationSensor::activate()
|
||||||
{
|
{
|
||||||
m_userEnabled = !m_userEnabled;
|
m_userEnabled = !m_userEnabled;
|
||||||
|
@ -96,6 +97,7 @@ void OrientationSensor::refresh()
|
||||||
if (m_sensor->isActive()) {
|
if (m_sensor->isActive()) {
|
||||||
m_sni->setTitle(i18n("Allow Rotation"));
|
m_sni->setTitle(i18n("Allow Rotation"));
|
||||||
m_sni->setToolTipTitle(i18n("Automatic screen rotation is enabled"));
|
m_sni->setToolTipTitle(i18n("Automatic screen rotation is enabled"));
|
||||||
|
updateState();
|
||||||
} else {
|
} else {
|
||||||
QString text;
|
QString text;
|
||||||
switch(m_orientation) {
|
switch(m_orientation) {
|
||||||
|
|
|
@ -80,6 +80,7 @@ private:
|
||||||
void loadConfig();
|
void loadConfig();
|
||||||
void refresh();
|
void refresh();
|
||||||
void activate();
|
void activate();
|
||||||
|
void updateState();
|
||||||
|
|
||||||
QOrientationSensor *m_sensor;
|
QOrientationSensor *m_sensor;
|
||||||
bool m_enabled = false;
|
bool m_enabled = false;
|
||||||
|
|
Loading…
Reference in a new issue