Changeset View
Changeset View
Standalone View
Standalone View
kcms/input/backends/x11/x11_libinput_dummydevice.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2018 Roman Gilg <subdiff@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU General Public License as published by | ||||
6 | * the Free Software Foundation; either version 2 of the License, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU General Public License | ||||
15 | * along with this program; if not, write to the Free Software | ||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
17 | */ | ||||
18 | | ||||
19 | #ifndef X11LIBINPUTDUMMYDEVICE_H | ||||
20 | #define X11LIBINPUTDUMMYDEVICE_H | ||||
21 | | ||||
22 | #include <QObject> | ||||
23 | #include <QString> | ||||
24 | #include <QX11Info> | ||||
25 | | ||||
26 | #include <X11/Xdefs.h> | ||||
27 | | ||||
28 | class LibinputSettings; | ||||
29 | | ||||
30 | class X11LibinputDummyDevice : public QObject | ||||
31 | { | ||||
32 | Q_OBJECT | ||||
33 | | ||||
34 | // | ||||
35 | // general | ||||
36 | Q_PROPERTY(QString name READ name CONSTANT) | ||||
37 | Q_PROPERTY(bool supportsDisableEvents READ supportsDisableEvents CONSTANT) | ||||
38 | Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) | ||||
39 | | ||||
40 | // | ||||
41 | // advanced | ||||
42 | Q_PROPERTY(Qt::MouseButtons supportedButtons READ supportedButtons CONSTANT) | ||||
43 | | ||||
44 | Q_PROPERTY(bool supportsLeftHanded READ supportsLeftHanded CONSTANT) | ||||
45 | Q_PROPERTY(bool leftHandedEnabledByDefault READ leftHandedEnabledByDefault CONSTANT) | ||||
46 | Q_PROPERTY(bool leftHanded READ isLeftHanded WRITE setLeftHanded NOTIFY leftHandedChanged) | ||||
47 | | ||||
48 | Q_PROPERTY(bool supportsMiddleEmulation READ supportsMiddleEmulation CONSTANT) | ||||
49 | Q_PROPERTY(bool middleEmulationEnabledByDefault READ middleEmulationEnabledByDefault CONSTANT) | ||||
50 | Q_PROPERTY(bool middleEmulation READ isMiddleEmulation WRITE setMiddleEmulation NOTIFY middleEmulationChanged) | ||||
51 | | ||||
52 | // | ||||
53 | // acceleration speed and profile | ||||
54 | Q_PROPERTY(bool supportsPointerAcceleration READ supportsPointerAcceleration CONSTANT) | ||||
55 | Q_PROPERTY(qreal pointerAcceleration READ pointerAcceleration WRITE setPointerAcceleration NOTIFY pointerAccelerationChanged) | ||||
56 | | ||||
57 | Q_PROPERTY(bool supportsPointerAccelerationProfileFlat READ supportsPointerAccelerationProfileFlat CONSTANT) | ||||
58 | Q_PROPERTY(bool defaultPointerAccelerationProfileFlat READ defaultPointerAccelerationProfileFlat CONSTANT) | ||||
59 | Q_PROPERTY(bool pointerAccelerationProfileFlat READ pointerAccelerationProfileFlat WRITE setPointerAccelerationProfileFlat NOTIFY pointerAccelerationProfileChanged) | ||||
60 | | ||||
61 | Q_PROPERTY(bool supportsPointerAccelerationProfileAdaptive READ supportsPointerAccelerationProfileAdaptive CONSTANT) | ||||
62 | Q_PROPERTY(bool defaultPointerAccelerationProfileAdaptive READ defaultPointerAccelerationProfileAdaptive CONSTANT) | ||||
63 | Q_PROPERTY(bool pointerAccelerationProfileAdaptive READ pointerAccelerationProfileAdaptive WRITE setPointerAccelerationProfileAdaptive NOTIFY pointerAccelerationProfileChanged) | ||||
64 | | ||||
65 | // | ||||
66 | // scrolling | ||||
67 | Q_PROPERTY(bool supportsNaturalScroll READ supportsNaturalScroll CONSTANT) | ||||
68 | Q_PROPERTY(bool naturalScrollEnabledByDefault READ naturalScrollEnabledByDefault CONSTANT) | ||||
69 | Q_PROPERTY(bool naturalScroll READ isNaturalScroll WRITE setNaturalScroll NOTIFY naturalScrollChanged) | ||||
70 | | ||||
71 | public: | ||||
72 | X11LibinputDummyDevice(QObject *parent, Display *dpy); | ||||
73 | ~X11LibinputDummyDevice() override; | ||||
74 | | ||||
75 | bool getConfig(); | ||||
76 | bool getDefaultConfig(); | ||||
77 | bool applyConfig(); | ||||
78 | bool isChangedConfig() const; | ||||
79 | | ||||
80 | // | ||||
81 | // general | ||||
82 | QString name() const { | ||||
83 | return m_name.val; | ||||
84 | } | ||||
85 | QString sysName() const { | ||||
86 | return m_sysName.val; | ||||
87 | } | ||||
88 | bool supportsDisableEvents() const { | ||||
89 | return m_supportsDisableEvents.val; | ||||
90 | } | ||||
91 | void setEnabled(bool enabled) { | ||||
92 | m_enabled.set(enabled); | ||||
93 | } | ||||
94 | bool isEnabled() const { | ||||
95 | return m_enabled.val; | ||||
96 | } | ||||
97 | Qt::MouseButtons supportedButtons() const { | ||||
98 | return m_supportedButtons.val; | ||||
99 | } | ||||
100 | | ||||
101 | // | ||||
102 | // advanced | ||||
103 | bool supportsLeftHanded() const { | ||||
104 | return m_supportsLeftHanded.val; | ||||
105 | } | ||||
106 | bool leftHandedEnabledByDefault() const { | ||||
107 | return m_leftHandedEnabledByDefault.val; | ||||
108 | } | ||||
109 | bool isLeftHanded() const { | ||||
110 | return m_leftHanded.val; | ||||
111 | } | ||||
112 | void setLeftHanded(bool set) { | ||||
113 | m_leftHanded.set(set); | ||||
114 | } | ||||
115 | | ||||
116 | bool supportsMiddleEmulation() const { | ||||
117 | return m_supportsMiddleEmulation.val; | ||||
118 | } | ||||
119 | bool middleEmulationEnabledByDefault() const { | ||||
120 | return m_middleEmulationEnabledByDefault.val; | ||||
121 | } | ||||
122 | bool isMiddleEmulation() const { | ||||
123 | return m_middleEmulation.val; | ||||
124 | } | ||||
125 | void setMiddleEmulation(bool set) { | ||||
126 | m_middleEmulation.set(set); | ||||
127 | } | ||||
128 | | ||||
129 | // | ||||
130 | // acceleration speed and profile | ||||
131 | bool supportsPointerAcceleration() const { | ||||
132 | return m_supportsPointerAcceleration.val; | ||||
133 | } | ||||
134 | qreal pointerAcceleration() const { | ||||
135 | return m_pointerAcceleration.val; | ||||
136 | } | ||||
137 | void setPointerAcceleration(qreal acceleration) { | ||||
138 | m_pointerAcceleration.set(acceleration); | ||||
139 | } | ||||
140 | | ||||
141 | bool supportsPointerAccelerationProfileFlat() const { | ||||
142 | return m_supportsPointerAccelerationProfileFlat.val; | ||||
143 | } | ||||
144 | bool defaultPointerAccelerationProfileFlat() const { | ||||
145 | return m_defaultPointerAccelerationProfileFlat.val; | ||||
146 | } | ||||
147 | bool pointerAccelerationProfileFlat() const { | ||||
148 | return m_pointerAccelerationProfileFlat.val; | ||||
149 | } | ||||
150 | void setPointerAccelerationProfileFlat(bool set) { | ||||
151 | m_pointerAccelerationProfileFlat.set(set); | ||||
152 | } | ||||
153 | | ||||
154 | bool supportsPointerAccelerationProfileAdaptive() const { | ||||
155 | return m_supportsPointerAccelerationProfileAdaptive.val; | ||||
156 | } | ||||
157 | bool defaultPointerAccelerationProfileAdaptive() const { | ||||
158 | return m_defaultPointerAccelerationProfileAdaptive.val; | ||||
159 | } | ||||
160 | bool pointerAccelerationProfileAdaptive() const { | ||||
161 | return m_pointerAccelerationProfileAdaptive.val; | ||||
162 | } | ||||
163 | void setPointerAccelerationProfileAdaptive(bool set) { | ||||
164 | m_pointerAccelerationProfileAdaptive.set(set); | ||||
165 | } | ||||
166 | | ||||
167 | // | ||||
168 | // scrolling | ||||
169 | bool supportsNaturalScroll() const { | ||||
170 | return m_supportsNaturalScroll.val; | ||||
171 | } | ||||
172 | bool naturalScrollEnabledByDefault() const { | ||||
173 | return m_naturalScrollEnabledByDefault.val; | ||||
174 | } | ||||
175 | bool isNaturalScroll() const { | ||||
176 | return m_naturalScroll.val; | ||||
177 | } | ||||
178 | void setNaturalScroll(bool set) { | ||||
179 | m_naturalScroll.set(set); | ||||
180 | } | ||||
181 | | ||||
182 | Q_SIGNALS: | ||||
183 | void leftHandedChanged(); | ||||
184 | void pointerAccelerationChanged(); | ||||
185 | void pointerAccelerationProfileChanged(); | ||||
186 | void enabledChanged(); | ||||
187 | void middleEmulationChanged(); | ||||
188 | void naturalScrollChanged(); | ||||
189 | | ||||
190 | private: | ||||
191 | template <typename T> | ||||
192 | struct Prop { | ||||
193 | explicit Prop(const QString &_name, const QString &_cfgName = "") | ||||
194 | : name(_name), | ||||
195 | cfgName(_cfgName) | ||||
196 | {} | ||||
197 | | ||||
198 | void set(T newVal) { | ||||
199 | if (avail && val != newVal) { | ||||
200 | val = newVal; | ||||
201 | } | ||||
202 | } | ||||
203 | void set(const Prop<T> &p) { | ||||
204 | if (avail && val != p.val) { | ||||
205 | val = p.val; | ||||
206 | } | ||||
207 | } | ||||
208 | bool changed() const { | ||||
209 | return avail && (old != val); | ||||
210 | } | ||||
211 | | ||||
212 | void reset(T newVal) { | ||||
213 | val = newVal; | ||||
214 | old = newVal; | ||||
215 | } | ||||
216 | | ||||
217 | QString name; | ||||
218 | QString cfgName; | ||||
219 | | ||||
220 | bool avail = true; | ||||
221 | T old; | ||||
222 | T val; | ||||
223 | | ||||
224 | Atom atom; | ||||
225 | }; | ||||
226 | | ||||
227 | template<typename T> | ||||
228 | bool valueWriter(Prop<T> &prop); | ||||
229 | | ||||
230 | // | ||||
231 | // general | ||||
232 | Prop<QString> m_name = Prop<QString>("name"); | ||||
233 | Prop<QString> m_sysName = Prop<QString>("sysName"); | ||||
234 | Prop<bool> m_supportsDisableEvents = Prop<bool>("supportsDisableEvents"); | ||||
235 | Prop<bool> m_enabled = Prop<bool>("enabled"); | ||||
236 | | ||||
237 | // | ||||
238 | // advanced | ||||
239 | Prop<Qt::MouseButtons> m_supportedButtons = Prop<Qt::MouseButtons>("supportedButtons"); | ||||
240 | | ||||
241 | Prop<bool> m_supportsLeftHanded = Prop<bool>("supportsLeftHanded"); | ||||
242 | Prop<bool> m_leftHandedEnabledByDefault = Prop<bool>("leftHandedEnabledByDefault"); | ||||
243 | Prop<bool> m_leftHanded = Prop<bool>("leftHanded", "XLbInptLeftHanded"); | ||||
244 | | ||||
245 | Prop<bool> m_supportsMiddleEmulation = Prop<bool>("supportsMiddleEmulation"); | ||||
246 | Prop<bool> m_middleEmulationEnabledByDefault = Prop<bool>("middleEmulationEnabledByDefault"); | ||||
247 | Prop<bool> m_middleEmulation = Prop<bool>("middleEmulation", "XLbInptMiddleEmulation"); | ||||
248 | | ||||
249 | // | ||||
250 | // acceleration speed and profile | ||||
251 | Prop<bool> m_supportsPointerAcceleration = Prop<bool>("supportsPointerAcceleration"); | ||||
252 | Prop<qreal> m_defaultPointerAcceleration = Prop<qreal>("defaultPointerAcceleration"); | ||||
253 | Prop<qreal> m_pointerAcceleration = Prop<qreal>("pointerAcceleration", "XLbInptPointerAcceleration"); | ||||
254 | | ||||
255 | Prop<bool> m_supportsPointerAccelerationProfileFlat = Prop<bool>("supportsPointerAccelerationProfileFlat"); | ||||
256 | Prop<bool> m_defaultPointerAccelerationProfileFlat = Prop<bool>("defaultPointerAccelerationProfileFlat"); | ||||
257 | Prop<bool> m_pointerAccelerationProfileFlat = Prop<bool>("pointerAccelerationProfileFlat", "XLbInptAccelProfileFlat"); | ||||
258 | | ||||
259 | Prop<bool> m_supportsPointerAccelerationProfileAdaptive = Prop<bool>("supportsPointerAccelerationProfileAdaptive"); | ||||
260 | Prop<bool> m_defaultPointerAccelerationProfileAdaptive = Prop<bool>("defaultPointerAccelerationProfileAdaptive"); | ||||
261 | Prop<bool> m_pointerAccelerationProfileAdaptive = Prop<bool>("pointerAccelerationProfileAdaptive"); | ||||
262 | | ||||
263 | // | ||||
264 | // scrolling | ||||
265 | Prop<bool> m_supportsNaturalScroll = Prop<bool>("supportsNaturalScroll"); | ||||
266 | Prop<bool> m_naturalScrollEnabledByDefault = Prop<bool>("naturalScrollEnabledByDefault"); | ||||
267 | Prop<bool> m_naturalScroll = Prop<bool>("naturalScroll", "XLbInptNaturalScroll"); | ||||
268 | | ||||
269 | LibinputSettings *m_settings; | ||||
270 | Display *m_dpy = nullptr; | ||||
271 | }; | ||||
272 | | ||||
273 | #endif // X11LIBINPUTDUMMYDEVICE_H |