Changeset View
Changeset View
Standalone View
Standalone View
kcms/touchpad/src/backends/kwin_wayland/kwinwaylandtouchpad.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2017 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 | #include "kwinwaylandtouchpad.h" | ||||
20 | | ||||
21 | #include <QDBusInterface> | ||||
22 | #include <QDBusError> | ||||
23 | #include <QVector> | ||||
24 | | ||||
25 | #include "logging.h" | ||||
26 | | ||||
27 | namespace { | ||||
28 | template<typename T> | ||||
29 | T valueLoaderPart(QVariant const &reply) { Q_UNUSED(reply); return T(); } | ||||
30 | | ||||
31 | template<> | ||||
32 | bool valueLoaderPart(QVariant const &reply) { return reply.toBool(); } | ||||
33 | | ||||
34 | template<> | ||||
35 | int valueLoaderPart(QVariant const &reply) { return reply.toInt(); } | ||||
36 | | ||||
37 | template<> | ||||
38 | quint32 valueLoaderPart(QVariant const &reply) { return reply.toInt(); } | ||||
39 | | ||||
40 | template<> | ||||
41 | qreal valueLoaderPart(QVariant const &reply) { return reply.toReal(); } | ||||
42 | | ||||
43 | template<> | ||||
44 | QString valueLoaderPart(QVariant const &reply) { return reply.toString(); } | ||||
45 | | ||||
46 | template<> | ||||
47 | Qt::MouseButtons valueLoaderPart(QVariant const &reply) { return static_cast<Qt::MouseButtons>(reply.toInt()); } | ||||
48 | } | ||||
49 | | ||||
50 | KWinWaylandTouchpad::KWinWaylandTouchpad(QString dbusName) | ||||
51 | { | ||||
52 | m_iface = new QDBusInterface(QStringLiteral("org.kde.KWin"), | ||||
53 | QStringLiteral("/org/kde/KWin/InputDevice/") + dbusName, | ||||
54 | QStringLiteral("org.kde.KWin.InputDevice"), | ||||
55 | QDBusConnection::sessionBus(), | ||||
56 | this); | ||||
57 | } | ||||
58 | | ||||
59 | KWinWaylandTouchpad::~KWinWaylandTouchpad() | ||||
60 | { | ||||
61 | delete m_iface; | ||||
62 | } | ||||
63 | | ||||
64 | bool KWinWaylandTouchpad::init() | ||||
65 | { | ||||
66 | // need to do it here in order to populate combobox and handle events | ||||
67 | return valueLoader(m_name) && valueLoader(m_sysName); | ||||
68 | } | ||||
69 | | ||||
70 | bool KWinWaylandTouchpad::getConfig() | ||||
71 | { | ||||
72 | bool success = true; | ||||
73 | | ||||
74 | // general | ||||
75 | success &= valueLoader(m_supportsDisableEvents); | ||||
76 | success &= valueLoader(m_supportsLeftHanded); | ||||
77 | success &= valueLoader(m_supportedButtons); | ||||
78 | success &= valueLoader(m_leftHandedEnabledByDefault); | ||||
79 | success &= valueLoader(m_enabled); | ||||
80 | success &= valueLoader(m_leftHanded); | ||||
81 | // advanced | ||||
82 | success &= valueLoader(m_supportsPointerAcceleration); | ||||
83 | success &= valueLoader(m_supportsPointerAccelerationProfileFlat); | ||||
84 | success &= valueLoader(m_supportsPointerAccelerationProfileAdaptive); | ||||
85 | success &= valueLoader(m_supportsDisableWhileTyping); | ||||
86 | success &= valueLoader(m_supportsDisableEventsOnExternalMouse); | ||||
87 | success &= valueLoader(m_defaultPointerAcceleration); | ||||
88 | success &= valueLoader(m_defaultPointerAccelerationProfileFlat); | ||||
89 | success &= valueLoader(m_defaultPointerAccelerationProfileAdaptive); | ||||
90 | success &= valueLoader(m_disableWhileTypingEnabledByDefault); | ||||
91 | success &= valueLoader(m_leftHandedEnabledByDefault); | ||||
92 | success &= valueLoader(m_pointerAcceleration); | ||||
93 | success &= valueLoader(m_pointerAccelerationProfileFlat); | ||||
94 | success &= valueLoader(m_pointerAccelerationProfileAdaptive); | ||||
95 | success &= valueLoader(m_disableWhileTyping); | ||||
96 | // tapping | ||||
97 | success &= valueLoader(m_tapFingerCount); | ||||
98 | success &= valueLoader(m_supportsMiddleEmulation); | ||||
99 | success &= valueLoader(m_tapToClickEnabledByDefault); | ||||
100 | success &= valueLoader(m_tapAndDragEnabledByDefault); | ||||
101 | success &= valueLoader(m_tapDragLockEnabledByDefault); | ||||
102 | success &= valueLoader(m_middleEmulationEnabledByDefault); | ||||
103 | success &= valueLoader(m_tapToClick); | ||||
104 | success &= valueLoader(m_tapAndDrag); | ||||
105 | success &= valueLoader(m_tapDragLock); | ||||
106 | success &= valueLoader(m_middleEmulation); | ||||
107 | success &= valueLoader(m_lmrTapButtonMapEnabledByDefault); | ||||
108 | success &= valueLoader(m_lmrTapButtonMap); | ||||
109 | // scrolling modes avail | ||||
110 | success &= valueLoader(m_supportsNaturalScroll); | ||||
111 | success &= valueLoader(m_supportsScrollTwoFinger); | ||||
112 | success &= valueLoader(m_supportsScrollEdge); | ||||
113 | success &= valueLoader(m_supportsScrollOnButtonDown); | ||||
114 | // default scrolling modes | ||||
115 | success &= valueLoader(m_naturalScrollEnabledByDefault); | ||||
116 | success &= valueLoader(m_scrollTwoFingerEnabledByDefault); | ||||
117 | success &= valueLoader(m_scrollEdgeEnabledByDefault); | ||||
118 | success &= valueLoader(m_scrollOnButtonDownEnabledByDefault); | ||||
119 | success &= valueLoader(m_defaultScrollButton); | ||||
120 | // current scrolling mode | ||||
121 | success &= valueLoader(m_naturalScroll); | ||||
122 | success &= valueLoader(m_isScrollTwoFinger); | ||||
123 | success &= valueLoader(m_isScrollEdge); | ||||
124 | success &= valueLoader(m_isScrollOnButtonDown); | ||||
125 | success &= valueLoader(m_scrollButton); | ||||
126 | | ||||
127 | return success; | ||||
128 | } | ||||
129 | | ||||
130 | bool KWinWaylandTouchpad::getDefaultConfig() | ||||
131 | { | ||||
132 | m_enabled.set(true); | ||||
133 | m_leftHanded.set(false); | ||||
134 | | ||||
135 | m_pointerAcceleration.set(m_defaultPointerAcceleration); | ||||
136 | m_pointerAccelerationProfileFlat.set(m_defaultPointerAccelerationProfileFlat); | ||||
137 | m_pointerAccelerationProfileAdaptive.set(m_defaultPointerAccelerationProfileAdaptive); | ||||
138 | | ||||
139 | m_disableWhileTyping.set(m_disableWhileTypingEnabledByDefault); | ||||
140 | | ||||
141 | m_tapToClick.set(m_tapToClickEnabledByDefault); | ||||
142 | m_tapAndDrag.set(m_tapAndDragEnabledByDefault); | ||||
143 | m_tapDragLock.set(m_tapDragLockEnabledByDefault); | ||||
144 | m_middleEmulation.set(m_middleEmulationEnabledByDefault); | ||||
145 | | ||||
146 | m_naturalScroll.set(m_naturalScrollEnabledByDefault); | ||||
147 | m_isScrollTwoFinger.set(m_scrollTwoFingerEnabledByDefault); | ||||
148 | m_isScrollEdge.set(m_scrollEdgeEnabledByDefault); | ||||
149 | m_isScrollOnButtonDown.set(m_scrollOnButtonDownEnabledByDefault); | ||||
150 | | ||||
151 | return true; | ||||
152 | } | ||||
153 | | ||||
154 | bool KWinWaylandTouchpad::applyConfig() | ||||
155 | { | ||||
156 | QVector<QString> msgs; | ||||
157 | | ||||
158 | msgs << valueWriter(m_enabled) | ||||
159 | << valueWriter(m_leftHanded) | ||||
160 | << valueWriter(m_pointerAcceleration) | ||||
161 | << valueWriter(m_defaultPointerAccelerationProfileFlat) | ||||
162 | << valueWriter(m_defaultPointerAccelerationProfileAdaptive) | ||||
163 | | ||||
164 | << valueWriter(m_disableWhileTyping) | ||||
165 | << valueWriter(m_middleEmulation) | ||||
166 | | ||||
167 | << valueWriter(m_tapToClick) | ||||
168 | << valueWriter(m_tapAndDrag) | ||||
169 | << valueWriter(m_tapDragLock) | ||||
170 | << valueWriter(m_lmrTapButtonMap) | ||||
171 | | ||||
172 | << valueWriter(m_naturalScroll) | ||||
173 | << valueWriter(m_isScrollTwoFinger) | ||||
174 | << valueWriter(m_isScrollEdge) | ||||
175 | << valueWriter(m_isScrollOnButtonDown) | ||||
176 | << valueWriter(m_scrollButton); | ||||
177 | | ||||
178 | bool success = true; | ||||
179 | QString error_msg; | ||||
180 | | ||||
181 | for (QString m : msgs) { | ||||
182 | if (!m.isNull()) { | ||||
183 | qCCritical(KCM_TOUCHPAD) << "in error:" << m; | ||||
184 | if (!success) { | ||||
185 | error_msg.append("\n"); | ||||
186 | } | ||||
187 | error_msg.append(m); | ||||
188 | success = false; | ||||
189 | } | ||||
190 | } | ||||
191 | | ||||
192 | if (!success) { | ||||
193 | qCCritical(KCM_TOUCHPAD) << error_msg; | ||||
194 | } | ||||
195 | return success; | ||||
196 | } | ||||
197 | | ||||
198 | bool KWinWaylandTouchpad::isChangedConfig() const | ||||
199 | { | ||||
200 | return m_enabled.changed() || | ||||
201 | m_leftHanded.changed() || | ||||
202 | m_pointerAcceleration.changed() || | ||||
203 | m_pointerAccelerationProfileFlat.changed() || | ||||
204 | m_pointerAccelerationProfileAdaptive.changed() || | ||||
205 | m_disableWhileTyping.changed() || | ||||
206 | m_middleEmulation.changed() || | ||||
207 | m_tapToClick.changed() || | ||||
208 | m_tapAndDrag.changed() || | ||||
209 | m_tapDragLock.changed() || | ||||
210 | m_lmrTapButtonMap.changed() || | ||||
211 | m_naturalScroll.changed() || | ||||
212 | m_isScrollTwoFinger.changed() || | ||||
213 | m_isScrollEdge.changed() || | ||||
214 | m_isScrollOnButtonDown.changed() || | ||||
215 | m_scrollButton.changed(); | ||||
216 | } | ||||
217 | | ||||
218 | template<typename T> | ||||
219 | QString KWinWaylandTouchpad::valueWriter(const Prop<T> &prop) | ||||
220 | { | ||||
221 | if (!prop.changed()) { | ||||
222 | return QString(); | ||||
223 | } | ||||
224 | m_iface->setProperty(prop.dbus, prop.val); | ||||
225 | QDBusError error = m_iface->lastError(); | ||||
226 | if (error.isValid()) { | ||||
227 | qCCritical(KCM_TOUCHPAD) << error.message(); | ||||
228 | return error.message(); | ||||
229 | } | ||||
230 | return QString(); | ||||
231 | } | ||||
232 | | ||||
233 | template<typename T> | ||||
234 | bool KWinWaylandTouchpad::valueLoader(Prop<T> &prop) | ||||
235 | { | ||||
236 | QVariant reply = m_iface->property(prop.dbus); | ||||
237 | if (!reply.isValid()) { | ||||
238 | qCCritical(KCM_TOUCHPAD) << "Error on d-bus read of" << prop.dbus; | ||||
239 | prop.avail = false; | ||||
240 | return false; | ||||
241 | } | ||||
242 | prop.avail = true; | ||||
243 | | ||||
244 | T replyValue = valueLoaderPart<T>(reply); | ||||
245 | | ||||
246 | prop.old = replyValue; | ||||
247 | prop.val = replyValue; | ||||
248 | return true; | ||||
249 | } |