Changeset View
Changeset View
Standalone View
Standalone View
kcms/touchpadx/src/backends/x11/synapticstouchpad.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2013 Alexander Mezin <mezin.alexander@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 | /* | ||||
20 | //krazy:excludeall=copyright | ||||
21 | * This file incorporates work covered by the following copyright and | ||||
22 | * permission notice: | ||||
23 | * | ||||
24 | * Copyright © 2002-2005,2007 Peter Osterlund | ||||
25 | * | ||||
26 | * Permission to use, copy, modify, distribute, and sell this software | ||||
27 | * and its documentation for any purpose is hereby granted without | ||||
28 | * fee, provided that the above copyright notice appear in all copies | ||||
29 | * and that both that copyright notice and this permission notice | ||||
30 | * appear in supporting documentation, and that the name of Red Hat | ||||
31 | * not be used in advertising or publicity pertaining to distribution | ||||
32 | * of the software without specific, written prior permission. Red | ||||
33 | * Hat makes no representations about the suitability of this software | ||||
34 | * for any purpose. It is provided "as is" without express or implied | ||||
35 | * warranty. | ||||
36 | * | ||||
37 | * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||||
38 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN | ||||
39 | * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR | ||||
40 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||||
41 | * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | ||||
42 | * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||||
43 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||||
44 | * | ||||
45 | * Authors: | ||||
46 | * Peter Osterlund (petero2@telia.com) | ||||
47 | */ | ||||
48 | | ||||
49 | #include <cmath> | ||||
50 | #include <QDebug> | ||||
51 | | ||||
52 | #include "synapticstouchpad.h" | ||||
53 | | ||||
54 | #include <stddef.h> | ||||
55 | #include <limits.h> | ||||
56 | #include <xorg/synaptics-properties.h> | ||||
57 | | ||||
58 | #define SYN_MAX_BUTTONS 12 | ||||
59 | | ||||
60 | const struct Parameter synapticsProperties[] = { | ||||
61 | {"LeftEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_EDGES, 32, 0}, | ||||
62 | {"RightEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_EDGES, 32, 1}, | ||||
63 | {"TopEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_EDGES, 32, 2}, | ||||
64 | {"BottomEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_EDGES, 32, 3}, | ||||
65 | {"FingerLow", PT_INT, 0, 255, SYNAPTICS_PROP_FINGER, 32, 0}, | ||||
66 | {"FingerHigh", PT_INT, 0, 255, SYNAPTICS_PROP_FINGER, 32, 1}, | ||||
67 | {"MaxTapTime", PT_INT, 0, 1000, SYNAPTICS_PROP_TAP_TIME, 32, 0}, | ||||
68 | {"MaxTapMove", PT_INT, 0, 2000, SYNAPTICS_PROP_TAP_MOVE, 32, 0}, | ||||
69 | {"MaxDoubleTapTime", PT_INT, 0, 1000, SYNAPTICS_PROP_TAP_DURATIONS,32, 1}, | ||||
70 | {"SingleTapTimeout", PT_INT, 0, 1000, SYNAPTICS_PROP_TAP_DURATIONS,32, 0}, | ||||
71 | {"ClickTime", PT_INT, 0, 1000, SYNAPTICS_PROP_TAP_DURATIONS,32, 2}, | ||||
72 | {"FastTaps", PT_BOOL, 0, 1, SYNAPTICS_PROP_TAP_FAST, 8, 0}, | ||||
73 | {"EmulateMidButtonTime", PT_INT, 0, 1000, SYNAPTICS_PROP_MIDDLE_TIMEOUT,32, 0}, | ||||
74 | {"EmulateTwoFingerMinZ", PT_INT, 0, 1000, SYNAPTICS_PROP_TWOFINGER_PRESSURE, 32, 0}, | ||||
75 | {"EmulateTwoFingerMinW", PT_INT, 0, 15, SYNAPTICS_PROP_TWOFINGER_WIDTH, 32, 0}, | ||||
76 | {"VertScrollDelta", PT_INT, -1000, 1000, SYNAPTICS_PROP_SCROLL_DISTANCE, 32, 0}, | ||||
77 | {"HorizScrollDelta", PT_INT, -1000, 1000, SYNAPTICS_PROP_SCROLL_DISTANCE, 32, 1}, | ||||
78 | {"VertEdgeScroll", PT_BOOL, 0, 1, SYNAPTICS_PROP_SCROLL_EDGE, 8, 0}, | ||||
79 | {"HorizEdgeScroll", PT_BOOL, 0, 1, SYNAPTICS_PROP_SCROLL_EDGE, 8, 1}, | ||||
80 | {"CornerCoasting", PT_BOOL, 0, 1, SYNAPTICS_PROP_SCROLL_EDGE, 8, 2}, | ||||
81 | {"VertTwoFingerScroll", PT_BOOL, 0, 1, SYNAPTICS_PROP_SCROLL_TWOFINGER, 8, 0}, | ||||
82 | {"HorizTwoFingerScroll", PT_BOOL, 0, 1, SYNAPTICS_PROP_SCROLL_TWOFINGER, 8, 1}, | ||||
83 | {"MinSpeed", PT_DOUBLE, 0, 255.0, SYNAPTICS_PROP_SPEED, 0, /*float */ 0}, | ||||
84 | {"MaxSpeed", PT_DOUBLE, 0, 255.0, SYNAPTICS_PROP_SPEED, 0, /*float */ 1}, | ||||
85 | {"AccelFactor", PT_DOUBLE, 0, 1.0, SYNAPTICS_PROP_SPEED, 0, /*float */ 2}, | ||||
86 | /*{"TouchpadOff", PT_INT, 0, 2, SYNAPTICS_PROP_OFF, 8, 0},*/ | ||||
87 | {"LockedDrags", PT_BOOL, 0, 1, SYNAPTICS_PROP_LOCKED_DRAGS, 8, 0}, | ||||
88 | {"LockedDragTimeout", PT_INT, 0, 30000, SYNAPTICS_PROP_LOCKED_DRAGS_TIMEOUT, 32, 0}, | ||||
89 | {"RTCornerButton", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 0}, | ||||
90 | {"RBCornerButton", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 1}, | ||||
91 | {"LTCornerButton", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 2}, | ||||
92 | {"LBCornerButton", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 3}, | ||||
93 | {"OneFingerTapButton", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 4}, | ||||
94 | {"TwoFingerTapButton", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 5}, | ||||
95 | {"ThreeFingerTapButton", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 6}, | ||||
96 | {"ClickFinger1", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_CLICK_ACTION, 8, 0}, | ||||
97 | {"ClickFinger2", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_CLICK_ACTION, 8, 1}, | ||||
98 | {"ClickFinger3", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_CLICK_ACTION, 8, 2}, | ||||
99 | {"CircularScrolling", PT_BOOL, 0, 1, SYNAPTICS_PROP_CIRCULAR_SCROLLING, 8, 0}, | ||||
100 | {"CircScrollDelta", PT_DOUBLE, .01, 3, SYNAPTICS_PROP_CIRCULAR_SCROLLING_DIST, 0 /* float */, 0}, | ||||
101 | {"CircScrollTrigger", PT_INT, 0, 8, SYNAPTICS_PROP_CIRCULAR_SCROLLING_TRIGGER, 8, 0}, | ||||
102 | {"PalmDetect", PT_BOOL, 0, 1, SYNAPTICS_PROP_PALM_DETECT, 8, 0}, | ||||
103 | {"PalmMinWidth", PT_INT, 0, 15, SYNAPTICS_PROP_PALM_DIMENSIONS, 32, 0}, | ||||
104 | {"PalmMinZ", PT_INT, 0, 255, SYNAPTICS_PROP_PALM_DIMENSIONS, 32, 1}, | ||||
105 | {"CoastingSpeed", PT_DOUBLE, 0, 255, SYNAPTICS_PROP_COASTING_SPEED, 0 /* float*/, 0}, | ||||
106 | {"CoastingFriction", PT_DOUBLE, 0, 255, SYNAPTICS_PROP_COASTING_SPEED, 0 /* float*/, 1}, | ||||
107 | {"PressureMotionMinZ", PT_INT, 1, 255, SYNAPTICS_PROP_PRESSURE_MOTION, 32, 0}, | ||||
108 | {"PressureMotionMaxZ", PT_INT, 1, 255, SYNAPTICS_PROP_PRESSURE_MOTION, 32, 1}, | ||||
109 | {"PressureMotionMinFactor", PT_DOUBLE, 0, 10.0,SYNAPTICS_PROP_PRESSURE_MOTION_FACTOR, 0 /*float*/, 0}, | ||||
110 | {"PressureMotionMaxFactor", PT_DOUBLE, 0, 10.0,SYNAPTICS_PROP_PRESSURE_MOTION_FACTOR, 0 /*float*/, 1}, | ||||
111 | {"GrabEventDevice", PT_BOOL, 0, 1, SYNAPTICS_PROP_GRAB, 8, 0}, | ||||
112 | {"TapAndDragGesture", PT_BOOL, 0, 1, SYNAPTICS_PROP_GESTURES, 8, 0}, | ||||
113 | {"AreaLeftEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_AREA, 32, 0}, | ||||
114 | {"AreaRightEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_AREA, 32, 1}, | ||||
115 | {"AreaTopEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_AREA, 32, 2}, | ||||
116 | {"AreaBottomEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_AREA, 32, 3}, | ||||
117 | {"HorizHysteresis", PT_INT, 0, 10000, SYNAPTICS_PROP_NOISE_CANCELLATION, 32, 0}, | ||||
118 | {"VertHysteresis", PT_INT, 0, 10000, SYNAPTICS_PROP_NOISE_CANCELLATION, 32, 1}, | ||||
119 | {"ClickPad", PT_BOOL, 0, 1, SYNAPTICS_PROP_CLICKPAD, 8, 0}, | ||||
120 | {"RightButtonAreaLeft", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 0}, | ||||
121 | {"RightButtonAreaRight", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 1}, | ||||
122 | {"RightButtonAreaTop", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 2}, | ||||
123 | {"RightButtonAreaBottom", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 3}, | ||||
124 | {"MiddleButtonAreaLeft", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 4}, | ||||
125 | {"MiddleButtonAreaRight", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 5}, | ||||
126 | {"MiddleButtonAreaTop", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 6}, | ||||
127 | {"MiddleButtonAreaBottom", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 7}, | ||||
128 | { NULL, PT_INT, 0, 0, 0, 0, 0 } | ||||
129 | }; | ||||
130 | | ||||
131 | SynapticsTouchpad::SynapticsTouchpad(Display *display, int deviceId): XlibTouchpad(display, deviceId), | ||||
132 | m_resX(1), m_resY(1) | ||||
133 | { | ||||
134 | m_capsAtom.intern(m_connection, SYNAPTICS_PROP_CAPABILITIES); | ||||
135 | m_touchpadOffAtom.intern(m_connection, SYNAPTICS_PROP_OFF); | ||||
136 | XcbAtom resolutionAtom(m_connection, SYNAPTICS_PROP_RESOLUTION); | ||||
137 | XcbAtom edgesAtom(m_connection, SYNAPTICS_PROP_EDGES); | ||||
138 | | ||||
139 | loadSupportedProperties(synapticsProperties); | ||||
140 | | ||||
141 | m_toRadians.append("CircScrollDelta"); | ||||
142 | | ||||
143 | PropertyInfo edges(m_display, m_deviceId, edgesAtom, 0); | ||||
144 | if (edges.i && edges.nitems == 4) { | ||||
145 | int w = qAbs(edges.i[1] - edges.i[0]); | ||||
146 | int h = qAbs(edges.i[3] - edges.i[2]); | ||||
147 | m_resX = w / 90; | ||||
148 | m_resY = h / 50; | ||||
149 | qDebug() << "Width: " << w << " height: " << h; | ||||
150 | qDebug() << "Approx. resX: " << m_resX << " resY: " << m_resY; | ||||
151 | } | ||||
152 | | ||||
153 | PropertyInfo resolution(m_display, m_deviceId, resolutionAtom, 0); | ||||
154 | if (resolution.i && resolution.nitems == 2 && | ||||
155 | resolution.i[0] > 1 && resolution.i[1] > 1) | ||||
156 | { | ||||
157 | m_resY = qMin(static_cast<unsigned long>(resolution.i[0]), | ||||
158 | static_cast<unsigned long>(INT_MAX)); | ||||
159 | m_resX = qMin(static_cast<unsigned long>(resolution.i[1]), | ||||
160 | static_cast<unsigned long>(INT_MAX)); | ||||
161 | qDebug() << "Touchpad resolution: x: " << m_resX << " y: " << m_resY; | ||||
162 | } | ||||
163 | | ||||
164 | m_scaleByResX.append("HorizScrollDelta"); | ||||
165 | m_scaleByResY.append("VertScrollDelta"); | ||||
166 | m_scaleByResX.append("MaxTapMove"); | ||||
167 | m_scaleByResY.append("MaxTapMove"); | ||||
168 | | ||||
169 | m_resX = qMax(10, m_resX); | ||||
170 | m_resY = qMax(10, m_resY); | ||||
171 | qDebug() << "Final resolution x:" << m_resX << " y:" << m_resY; | ||||
172 | m_negate["HorizScrollDelta"] = "InvertHorizScroll"; | ||||
173 | m_negate["VertScrollDelta"] = "InvertVertScroll"; | ||||
174 | m_supported.append(m_negate.values()); | ||||
175 | m_supported.append("Coasting"); | ||||
176 | | ||||
177 | PropertyInfo caps(m_display, m_deviceId, m_capsAtom.atom(), 0); | ||||
178 | if (!caps.b) { | ||||
179 | return; | ||||
180 | } | ||||
181 | | ||||
182 | enum TouchpadCapabilitiy | ||||
183 | { | ||||
184 | TouchpadHasLeftButton, | ||||
185 | TouchpadHasMiddleButton, | ||||
186 | TouchpadHasRightButton, | ||||
187 | TouchpadTwoFingerDetect, | ||||
188 | TouchpadThreeFingerDetect, | ||||
189 | TouchpadPressureDetect, | ||||
190 | TouchpadPalmDetect, | ||||
191 | TouchpadCapsCount | ||||
192 | }; | ||||
193 | | ||||
194 | QVector<bool> cap(TouchpadCapsCount, false); | ||||
195 | qCopy(caps.b, caps.b + qMin(cap.size(), static_cast<int>(caps.nitems)), | ||||
196 | cap.begin()); | ||||
197 | | ||||
198 | if (!cap[TouchpadTwoFingerDetect]) { | ||||
199 | m_supported.removeAll("HorizTwoFingerScroll"); | ||||
200 | m_supported.removeAll("VertTwoFingerScroll"); | ||||
201 | m_supported.removeAll("TwoFingerTapButton"); | ||||
202 | } | ||||
203 | | ||||
204 | if (!cap[TouchpadThreeFingerDetect]) { | ||||
205 | m_supported.removeAll("ThreeFingerTapButton"); | ||||
206 | } | ||||
207 | | ||||
208 | if (!cap[TouchpadPressureDetect]) { | ||||
209 | m_supported.removeAll("FingerHigh"); | ||||
210 | m_supported.removeAll("FingerLow"); | ||||
211 | | ||||
212 | m_supported.removeAll("PalmMinZ"); | ||||
213 | m_supported.removeAll("PressureMotionMinZ"); | ||||
214 | m_supported.removeAll("PressureMotionMinFactor"); | ||||
215 | m_supported.removeAll("PressureMotionMaxZ"); | ||||
216 | m_supported.removeAll("PressureMotionMaxFactor"); | ||||
217 | m_supported.removeAll("EmulateTwoFingerMinZ"); | ||||
218 | } | ||||
219 | | ||||
220 | if (!cap[TouchpadPalmDetect]) { | ||||
221 | m_supported.removeAll("PalmDetect"); | ||||
222 | m_supported.removeAll("PalmMinWidth"); | ||||
223 | m_supported.removeAll("PalmMinZ"); | ||||
224 | m_supported.removeAll("EmulateTwoFingerMinW"); | ||||
225 | } | ||||
226 | | ||||
227 | for (QMap<QString, QString>::Iterator i = m_negate.begin(); | ||||
228 | i != m_negate.end(); ++i) | ||||
229 | { | ||||
230 | if (!m_supported.contains(i.key())) { | ||||
231 | m_supported.removeAll(i.value()); | ||||
232 | } | ||||
233 | } | ||||
234 | | ||||
235 | m_paramList = synapticsProperties; | ||||
236 | } | ||||
237 | | ||||
238 | double SynapticsTouchpad::getPropertyScale(const QString &name) const | ||||
239 | { | ||||
240 | if (m_scaleByResX.contains(name) && m_scaleByResY.contains(name)) { | ||||
241 | return std::sqrt(static_cast<double>(m_resX) * m_resX | ||||
242 | + static_cast<double>(m_resY) * m_resY); | ||||
243 | } else if (m_scaleByResX.contains(name)) { | ||||
244 | return m_resX; | ||||
245 | } else if (m_scaleByResY.contains(name)) { | ||||
246 | return m_resY; | ||||
247 | } else if (m_toRadians.contains(name)) { | ||||
248 | return M_PI_4 / 45.0; | ||||
249 | } | ||||
250 | return 1.0; | ||||
251 | } |