Changeset View
Changeset View
Standalone View
Standalone View
orientation_sensor.h
Show All 15 Lines | |||||
16 | 16 | | |||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #pragma once | 20 | #pragma once | ||
21 | 21 | | |||
22 | #include <QObject> | 22 | #include <QObject> | ||
23 | 23 | | |||
24 | #include <KSharedConfig> | ||||
25 | | ||||
24 | #include <kwin_export.h> | 26 | #include <kwin_export.h> | ||
25 | 27 | | |||
26 | class QOrientationSensor; | 28 | class QOrientationSensor; | ||
29 | class OrientationSensorAdaptor; | ||||
27 | class KStatusNotifierItem; | 30 | class KStatusNotifierItem; | ||
28 | 31 | | |||
29 | namespace KWin | 32 | namespace KWin | ||
30 | { | 33 | { | ||
31 | 34 | | |||
32 | class KWIN_EXPORT OrientationSensor : public QObject | 35 | class KWIN_EXPORT OrientationSensor : public QObject | ||
33 | { | 36 | { | ||
34 | Q_OBJECT | 37 | Q_OBJECT | ||
38 | Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.OrientationSensor") | ||||
39 | Q_PROPERTY(bool userEnabled READ isUserEnabled WRITE setUserEnabled NOTIFY userEnabledChanged) | ||||
35 | public: | 40 | public: | ||
36 | explicit OrientationSensor(QObject *parent = nullptr); | 41 | explicit OrientationSensor(QObject *parent = nullptr); | ||
37 | ~OrientationSensor(); | 42 | ~OrientationSensor(); | ||
38 | 43 | | |||
39 | void setEnabled(bool enabled); | 44 | void setEnabled(bool enabled); | ||
40 | 45 | | |||
41 | /** | 46 | /** | ||
42 | * Just like QOrientationReading::Orientation, | 47 | * Just like QOrientationReading::Orientation, | ||
43 | * copied to not leak the QSensors API into internal API. | 48 | * copied to not leak the QSensors API into internal API. | ||
44 | **/ | 49 | **/ | ||
45 | enum class Orientation { | 50 | enum class Orientation { | ||
46 | Undefined, | 51 | Undefined, | ||
47 | TopUp, | 52 | TopUp, | ||
48 | TopDown, | 53 | TopDown, | ||
49 | LeftUp, | 54 | LeftUp, | ||
50 | RightUp, | 55 | RightUp, | ||
51 | FaceUp, | 56 | FaceUp, | ||
52 | FaceDown | 57 | FaceDown | ||
53 | }; | 58 | }; | ||
54 | 59 | | |||
55 | Orientation orientation() const { | 60 | Orientation orientation() const { | ||
56 | return m_orientation; | 61 | return m_orientation; | ||
57 | } | 62 | } | ||
58 | 63 | | |||
64 | void setConfig(KSharedConfig::Ptr config) { | ||||
65 | m_config = config; | ||||
66 | } | ||||
67 | | ||||
68 | bool isUserEnabled() const { | ||||
69 | return m_userEnabled; | ||||
70 | } | ||||
71 | void setUserEnabled(bool enabled); | ||||
72 | | ||||
59 | Q_SIGNALS: | 73 | Q_SIGNALS: | ||
60 | void orientationChanged(); | 74 | void orientationChanged(); | ||
75 | void userEnabledChanged(bool); | ||||
61 | 76 | | |||
62 | private: | 77 | private: | ||
63 | void setupStatusNotifier(); | 78 | void setupStatusNotifier(); | ||
64 | void startStopSensor(); | 79 | void startStopSensor(); | ||
80 | void loadConfig(); | ||||
65 | QOrientationSensor *m_sensor; | 81 | QOrientationSensor *m_sensor; | ||
66 | bool m_enabled = false; | 82 | bool m_enabled = false; | ||
67 | bool m_userEnabled = true; | 83 | bool m_userEnabled = true; | ||
68 | Orientation m_orientation = Orientation::Undefined; | 84 | Orientation m_orientation = Orientation::Undefined; | ||
69 | KStatusNotifierItem *m_sni = nullptr; | 85 | KStatusNotifierItem *m_sni = nullptr; | ||
86 | KSharedConfig::Ptr m_config; | ||||
87 | OrientationSensorAdaptor *m_adaptor = nullptr; | ||||
70 | 88 | | |||
71 | }; | 89 | }; | ||
72 | 90 | | |||
73 | } | 91 | } |