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:
Aleix Pol 2019-04-17 02:32:07 +02:00
parent 3323857a64
commit bf6f05bf3c
2 changed files with 32 additions and 29 deletions

View file

@ -34,8 +34,12 @@ OrientationSensor::OrientationSensor(QObject *parent)
: QObject(parent)
, m_sensor(new QOrientationSensor(this))
{
connect(m_sensor, &QOrientationSensor::readingChanged, this,
[this] {
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:
@ -62,9 +66,6 @@ OrientationSensor::OrientationSensor(QObject *parent)
emit orientationChanged();
}
}
);
connect(m_sensor, &QOrientationSensor::activeChanged, this, &OrientationSensor::refresh);
}
void OrientationSensor::activate()
{
@ -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) {

View file

@ -80,6 +80,7 @@ private:
void loadConfig();
void refresh();
void activate();
void updateState();
QOrientationSensor *m_sensor;
bool m_enabled = false;