KWin
Loading...
Searching...
No Matches
orientationsensor.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2019 Roman Gilg <subdiff@gmail.com>
3 SPDX-FileCopyrightText: 2023 Xaver Hugl <xaver.hugl@gmail.com>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7#include "orientationsensor.h"
8
9#include <QOrientationSensor>
10
11namespace KWin
12{
13
15 : m_sensor(std::make_unique<QOrientationSensor>())
16 , m_reading(std::make_unique<QOrientationReading>())
17{
18 m_reading->setOrientation(QOrientationReading::Orientation::Undefined);
19}
20
22
24{
25 if (enable) {
26 connect(m_sensor.get(), &QOrientationSensor::readingChanged, this, &OrientationSensor::update, Qt::UniqueConnection);
27 m_sensor->start();
28 } else {
29 disconnect(m_sensor.get(), &QOrientationSensor::readingChanged, this, &OrientationSensor::update);
30 m_reading->setOrientation(QOrientationReading::Undefined);
31 }
32}
33
34QOrientationReading *OrientationSensor::reading() const
35{
36 return m_reading.get();
37}
38
39void OrientationSensor::update()
40{
41 if (auto reading = m_sensor->reading()) {
42 if (m_reading->orientation() != reading->orientation()) {
43 m_reading->setOrientation(reading->orientation());
44 Q_EMIT orientationChanged();
45 }
46 } else if (m_reading->orientation() != QOrientationReading::Orientation::Undefined) {
47 m_reading->setOrientation(QOrientationReading::Orientation::Undefined);
48 Q_EMIT orientationChanged();
49 }
50}
51
52}
53
54#include "moc_orientationsensor.cpp"
QOrientationReading * reading() const