KWin
Loading...
Searching...
No Matches
src
utils
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
11
namespace
KWin
12
{
13
14
OrientationSensor::OrientationSensor
()
15
: m_sensor(std::make_unique<QOrientationSensor>())
16
, m_reading(std::make_unique<QOrientationReading>())
17
{
18
m_reading->setOrientation(QOrientationReading::Orientation::Undefined);
19
}
20
21
OrientationSensor::~OrientationSensor
() =
default
;
22
23
void
OrientationSensor::setEnabled
(
bool
enable)
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
34
QOrientationReading *
OrientationSensor::reading
()
const
35
{
36
return
m_reading.get();
37
}
38
39
void
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"
KWin::OrientationSensor::setEnabled
void setEnabled(bool enable)
Definition
orientationsensor.cpp:23
KWin::OrientationSensor::orientationChanged
void orientationChanged()
KWin::OrientationSensor::reading
QOrientationReading * reading() const
Definition
orientationsensor.cpp:34
KWin::OrientationSensor::~OrientationSensor
~OrientationSensor()
KWin::OrientationSensor::OrientationSensor
OrientationSensor()
Definition
orientationsensor.cpp:14
KWin
Definition
activation_test.cpp:20
orientationsensor.h
Generated on Sat Feb 17 2024 01:42:10 for KWin by
1.10.0