1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
|
/*******************************************************************************
tdecm_touchpad
A touchpad module for the TDE Control Centre
Copyright © 2024 Mavridis Philippe <mavridisf@gmail.com>
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>.
*******************************************************************************/
// TDE
#include <tdeapplication.h>
#include <tdeconfig.h>
#include <kdebug.h>
// DCOP
#include <dcopref.h>
// X11
#include <X11/extensions/XInput.h>
#include <X11/extensions/XInput2.h>
// tdecm_touchpad
#include "xiproperty.h"
#include "touchpad_settings.h"
/****************************** TouchpadSettings ******************************/
TouchpadSettings::TouchpadSettings()
: m_foundTouchpad(false)
{
findTouchpad();
}
bool TouchpadSettings::findTouchpad()
{
Display *display = tqt_xdisplay();
ATOM(isTouchpad, XI_TOUCHPAD)
ATOM(isLibinput, "libinput Send Events Mode Enabled")
ATOM(isSynaptics, "Synaptics Off")
int devicesCount;
XDeviceInfo *deviceList = XListInputDevices(display, &devicesCount);
for (int d = 0; d < devicesCount; ++d)
{
if (deviceList[d].type != isTouchpad) continue;
m_foundTouchpad = true;
m_touchpad.init(deviceList[d].id, deviceList[d].name);
int propertiesCount;
Atom *propertiesList = XIListProperties(display, deviceList[d].id,
&propertiesCount);
for (int p = 0; p < propertiesCount; ++p)
{
if (propertiesList[p] == isLibinput)
{
m_touchpad.driver = Touchpad::Driver::LibInput;
break;
}
else if (propertiesList[p] == isSynaptics)
{
m_touchpad.driver = Touchpad::Driver::Synaptics;
}
}
XFree(propertiesList);
if (m_foundTouchpad) break;
}
XFreeDeviceList(deviceList);
return m_foundTouchpad;
}
void TouchpadSettings::load(bool defaults)
{
TDEConfig cfg("kcminputrc");
cfg.setGroup("Touchpad");
cfg.setReadDefaults(defaults);
enabled = cfg.readBoolEntry("Enabled", true);
// Behaviour
offWhileTyping = cfg.readBoolEntry("OffWhileTyping", false);
IF_DRIVER(LibInput)
{
midButtonEmulation = cfg.readBoolEntry("MidButtonEmulation", false);
}
// Speed
IF_DRIVER(LibInput)
{
accelSpeed = cfg.readNumEntry("AccelSpeed", 0);
accelProfile = cfg.readNumEntry("AccelProfile", 0);
}
// Tapping
tapClick = cfg.readBoolEntry("TapToClick", true);
tapDrag = cfg.readBoolEntry("TapAndDrag", true);
IF_DRIVER(LibInput)
{
tapDragLock = cfg.readBoolEntry("TapAndDragLock", false);
}
tapMapping = cfg.readNumEntry("TapMapping", 0);
// Scrolling options
int both = TQt::Horizontal | TQt::Vertical;
scrollDirections = cfg.readNumEntry("ScrollDirections", both);
naturalScroll = cfg.readBoolEntry("NaturalScroll", false);
naturalScrollDirections = cfg.readNumEntry("NaturalScrollDirections", both);
// Scrolling method
scrollMethod = cfg.readNumEntry("ScrollMethod", 0);
}
void TouchpadSettings::save()
{
TDEConfig cfg("kcminputrc");
cfg.setGroup("Touchpad");
cfg.writeEntry("Enabled", enabled);
// Behaviour
cfg.writeEntry("OffWhileTyping", offWhileTyping);
IF_DRIVER(LibInput)
{
cfg.writeEntry("MidButtonEmulation", midButtonEmulation);
}
// Speed
cfg.writeEntry("AccelSpeed", accelSpeed);
cfg.writeEntry("AccelProfile", accelProfile);
// Tapping
cfg.writeEntry("TapToClick", tapClick);
cfg.writeEntry("TapAndDrag", tapDrag);
IF_DRIVER(LibInput)
{
cfg.writeEntry("TapAndDragLock", tapDragLock);
}
cfg.writeEntry("TapMapping", tapMapping);
// Scrolling options
cfg.writeEntry("ScrollDirections", scrollDirections);
cfg.writeEntry("NaturalScroll", naturalScroll);
cfg.writeEntry("NaturalScrollDirections", naturalScrollDirections);
// Scrolling method
cfg.writeEntry("ScrollMethod", scrollMethod);
cfg.sync();
}
bool TouchpadSettings::setTouchpadEnabled(bool on)
{
enabled = on;
XIProperty *prop = nullptr;
int fail = 0;
IF_DRIVER(LibInput)
{
SET_PROP("Device Enabled", b)
{
prop->b[0] = enabled;
prop->set();
}
}
else
IF_DRIVER(Synaptics)
{
SET_PROP("Synaptics Off", b)
{
prop->b[0] = !enabled;
prop->set();
}
}
return !fail;
}
void TouchpadSettings::apply(bool force)
{
kdDebug() << "applying touchpad settings" << endl;
if (!foundTouchpad())
{
kdWarning() << "no supported touchpads! settings not applied" << endl;
return;
}
load();
Display *display = tqt_xdisplay();
XIProperty *prop = nullptr;
int fail = 0;
if (!setTouchpadEnabled(enabled))
++fail;
IF_DRIVER(LibInput)
{
kdDebug() << "driver: libinput" << endl;
SET_PROP("libinput Disable While Typing Enabled", b)
{
prop->b[0] = offWhileTyping;
prop->set();
}
SET_PROP("libinput Middle Emulation Enabled", b)
{
prop->b[0] = midButtonEmulation;
prop->set();
}
SET_PROP("libinput Accel Speed", f)
{
float val = accelSpeed;
val /= 100;
prop->f[0] = val;
prop->set();
}
SET_PROP("libinput Accel Profile Enabled", b)
{
prop->b[0] = (accelProfile == 0);
prop->b[1] = (accelProfile == 1);
prop->set();
}
SET_PROP("libinput Tapping Enabled", b)
{
prop->b[0] = tapClick;
prop->set();
}
SET_PROP("libinput Tapping Drag Enabled", b)
{
prop->b[0] = tapClick && tapDrag;
prop->set();
}
SET_PROP("libinput Tapping Drag Lock Enabled", b)
{
prop->b[0] = tapClick && tapDrag && tapDragLock;
prop->set();
}
SET_PROP("libinput Tapping Button Mapping Enabled", b)
{
prop->b[0] = (tapMapping == 0);
prop->b[1] = (tapMapping == 1);
prop->set();
}
SET_PROP("libinput Horizontal Scroll Enabled", b)
{
prop->b[0] = scrollDirections & TQt::Horizontal;
prop->set();
}
SET_PROP("libinput Natural Scrolling Enabled", b)
{
prop->b[0] = naturalScroll;
prop->set();
}
SET_PROP("libinput Scroll Method Enabled", b)
{
prop->b[0] = scrollDirections ? (scrollMethod == 0) : 0; // two-finger
prop->b[1] = scrollDirections ? (scrollMethod == 1) : 0; // edge
prop->b[2] = scrollDirections ? (scrollMethod == 2) : 0; // button
prop->set();
}
}
else IF_DRIVER(Synaptics)
{
kdDebug() << "driver: synaptics" << endl;
SET_PROP("Synaptics Tap Action", b)
{
prop->b[0] = 0;
prop->b[1] = 0;
prop->b[2] = 0;
prop->b[3] = 0;
prop->b[4] = tapClick ? 1 : 0; // 1 finger
prop->b[5] = tapClick ? (tapMapping == 0 ? 3 : 2) : 0; // 2 fingers
prop->b[6] = tapClick ? (tapMapping == 0 ? 2 : 3) : 0; // 3 fingers
prop->set();
}
SET_PROP("Synaptics Gestures", b)
{
prop->b[0] = tapDrag;
prop->set();
}
SET_PROP("Synaptics Edge Scrolling", b)
{
prop->b[0] = scrollMethod == 1 ? (scrollDirections & TQt::Vertical ? 1 : 0) : 0;
prop->b[1] = scrollMethod == 1 ? (scrollDirections & TQt::Horizontal ? 1 : 0) : 0;
prop->b[2] = 0; // corner
prop->set();
}
SET_PROP("Synaptics Two-Finger Scrolling", b)
{
prop->b[0] = scrollMethod == 0 ? (scrollDirections & TQt::Vertical ? 1 : 0) : 0;
prop->b[1] = scrollMethod == 0 ? (scrollDirections & TQt::Horizontal ? 1 : 0) : 0;
prop->set();
}
SET_PROP("Synaptics Scrolling Distance", i)
{
prop->i[0] = naturalScroll && naturalScrollDirections & TQt::Vertical ? -80 : 80;
prop->i[1] = naturalScroll && naturalScrollDirections & TQt::Horizontal ? -80 : 80;
prop->set();
}
// start/stop tdesyndaemon
DCOPRef tdesyndaemon("tdesyndaemon", "tdesyndaemon");
tdesyndaemon.call("stop()");
if (offWhileTyping)
{
kapp->tdeinitExec("tdesyndaemon");
}
}
if (fail > 0)
kdWarning() << "some options could not be applied!" << endl;
}
TQValueList<bool> TouchpadSettings::getScrollMethodsAvailability()
{
TQValueList<bool> avail;
IF_DRIVER(LibInput)
{
PROP(propScrollMethodsAvail, "libinput Scroll Methods Available")
for (int i = 0; i < propScrollMethodsAvail.count(); ++i)
{
avail.append(propScrollMethodsAvail[i].toBool());
}
}
IF_DRIVER(Synaptics)
{
avail.append(1); // two-finger
avail.append(1); // edge
}
return avail;
}
TQValueList<bool> TouchpadSettings::getAccelProfilesAvailability()
{
TQValueList<bool> avail;
IF_DRIVER(LibInput)
{
PROP(propAccelProfilesAvail, "libinput Accel Profiles Available")
for (int i = 0; i < propAccelProfilesAvail.count(); ++i)
{
avail.append(propAccelProfilesAvail[i].toBool());
}
}
IF_DRIVER(Synaptics) { /* TODO no support yet */ }
return avail;
}
Touchpad TouchpadSettings::touchpad()
{
return m_touchpad;
}
bool TouchpadSettings::foundTouchpad()
{
return m_foundTouchpad;
}
bool TouchpadSettings::supportedTouchpad()
{
return m_foundTouchpad && m_touchpad.driver != Touchpad::Driver::None;
}
|