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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
|
/*
* Copyright © 1999 Henry Davies
* Copyright © 2001 Stefan Gmeiner
* Copyright © 2002 S. Lehner
* Copyright © 2002 Peter Osterlund
* Copyright © 2002 Linuxcare Inc. David Kennedy
* Copyright © 2003 Hartwig Felger
* Copyright © 2003 Jörg Bösner
* Copyright © 2003 Fred Hucht
* Copyright © 2004 Alexei Gilchrist
* Copyright © 2004 Matthias Ihmig
* Copyright © 2006 Stefan Bethge
* Copyright © 2006 Christian Thaeter
* Copyright © 2007 Joseph P. Skudlarek
* Copyright © 2008 Fedor P. Goncharov
* Copyright © 2008-2012 Red Hat, Inc.
* Copyright © 2011 The Chromium OS Authors
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of Red Hat
* not be used in advertising or publicity pertaining to distribution
* of the software without specific, written prior permission. Red
* Hat makes no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied
* warranty.
*
* THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
* NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <xorg-server.h>
#include <xserver-properties.h>
#include <X11/Xatom.h>
#include <ptrveloc.h>
#include <xf86.h>
#include <xf86_OSproc.h>
#include <xf86Xinput.h>
#include <exevents.h>
#include "synaptics.h"
#include "synaptics-x11.h"
#include "synaptics-properties.h"
struct SynapticsX11 {
InputInfoPtr pInfo;
OsTimerPtr timer; /* for tap processing, etc */
ValuatorMask *event_mask;
};
static void DeviceInitTouchAxes(DeviceIntPtr dev, Atom *axes_labels);
/* frontend hooks */
static unsigned int X11SynapticsGetCurrentMillis(void);
static void X11SynapticsMsg(struct SynapticsPrivate *priv, enum MessageType type,
const char *format, va_list args);
static void X11SynapticsButtonEvent(struct SynapticsPrivate *priv, int button,
enum ButtonEventType press);
static void X11SynapticsMotionEvent(struct SynapticsPrivate *priv, int x, int y);
static void
X11SynapticsScrollEvent(struct SynapticsPrivate *priv, unsigned int which,
double vert, double horiz);
static void X11SynapticsTouchEvent(struct SynapticsPrivate *priv, unsigned int touchid,
enum TouchEventType type, struct VMask *mask);
static void X11SynapticsSetTimer(struct SynapticsPrivate *priv,
unsigned int now, unsigned int delay);
static void
X11SynapticsMsg(struct SynapticsPrivate *priv, enum MessageType type,
const char *format, va_list args)
{
struct SynapticsX11 *x11 = priv->frontend_data;
InputInfoPtr pInfo = x11->pInfo;
int x11_type;
switch (type) {
case MSG_DEBUG: x11_type = X_INFO; break;
case MSG_INFO: x11_type = X_INFO; break;
case MSG_WARN: x11_type = X_WARNING; break;
case MSG_ERROR: x11_type = X_ERROR; break;
}
xf86VIDrvMsgVerb(pInfo, x11_type, 1, format, args);
}
static unsigned int
X11SynapticsGetCurrentMillis(void)
{
return GetTimeInMillis();
}
static CARD32
X11TimerFunc(OsTimerPtr timer, CARD32 now, pointer arg)
{
InputInfoPtr pInfo = arg;
struct SynapticsPrivate *priv = (struct SynapticsPrivate *) (pInfo->private);
struct SynapticsX11 *x11 = priv->frontend_data;
int sigstate;
int delay;
sigstate = xf86BlockSIGIO();
delay = SynapticsTimerFunc(priv, now);
priv->timer_time = now;
x11->timer = TimerSet(x11->timer, 0, delay, X11TimerFunc, pInfo);
xf86UnblockSIGIO(sigstate);
return 0;
}
static void
X11SynapticsSetTimer(struct SynapticsPrivate *priv, unsigned int now, unsigned int delay)
{
struct SynapticsX11 *x11 = priv->frontend_data;
x11->timer = TimerSet(x11->timer, 0, delay, X11TimerFunc, x11->pInfo);
}
/*
* Alter the control parameters for the mouse. Note that all special
* protocol values are handled by dix.
*/
static void
SynapticsCtrl(DeviceIntPtr device, PtrCtrl * ctrl)
{
}
static void
InitAxesLabels(Atom *labels, int nlabels, const struct SynapticsPrivate * priv)
{
int i;
memset(labels, 0, nlabels * sizeof(Atom));
switch (nlabels) {
default:
case 4:
labels[3] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_VSCROLL);
case 3:
labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_HSCROLL);
case 2:
labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
case 1:
labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
break;
}
for (i = 0; i < priv->num_mt_axes; i++) {
SynapticsTouchAxisRec *axis = &priv->touch_axes[i];
int axnum = nlabels - priv->num_mt_axes + i;
labels[axnum] = XIGetKnownProperty(axis->label);
}
}
static void
InitButtonLabels(Atom *labels, int nlabels)
{
memset(labels, 0, nlabels * sizeof(Atom));
switch (nlabels) {
default:
case 7:
labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
case 6:
labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
case 5:
labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
case 4:
labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
case 3:
labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
case 2:
labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
case 1:
labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
break;
}
}
static double
SynapticsAccelerationProfile(DeviceIntPtr dev,
DeviceVelocityPtr vel,
double velocity, double thr, double acc)
{
InputInfoPtr pInfo = dev->public.devicePrivate;
struct SynapticsPrivate *priv = (struct SynapticsPrivate *) (pInfo->private);
struct SynapticsParameters *para = &priv->synpara;
double accelfct;
/*
* synaptics accel was originally base on device coordinate based
* velocity, which we recover this way so para->accl retains its scale.
*/
velocity /= vel->const_acceleration;
/* speed up linear with finger velocity */
accelfct = velocity * para->accl;
/* clip acceleration factor */
if (accelfct > para->max_speed * acc)
accelfct = para->max_speed * acc;
else if (accelfct < para->min_speed)
accelfct = para->min_speed;
/* modify speed according to pressure */
if (priv->moving_state == MS_TOUCHPAD_RELATIVE) {
int minZ = para->press_motion_min_z;
int maxZ = para->press_motion_max_z;
double minFctr = para->press_motion_min_factor;
double maxFctr = para->press_motion_max_factor;
if (priv->hwState->z <= minZ) {
accelfct *= minFctr;
}
else if (priv->hwState->z >= maxZ) {
accelfct *= maxFctr;
}
else {
accelfct *=
minFctr + (priv->hwState->z - minZ) * (maxFctr -
minFctr) / (maxZ - minZ);
}
}
return accelfct;
}
static void
DeviceInitAcceleration(DeviceIntPtr dev)
{
InputInfoPtr pInfo = dev->public.devicePrivate;
struct SynapticsPrivate *priv = (struct SynapticsPrivate *) (pInfo->private);
Atom float_type, prop;
DeviceVelocityPtr pVel;
float tmpf;
int i;
pVel = GetDevicePredictableAccelData(dev);
if (!pVel)
return;
/*
* setup dix acceleration to match legacy synaptics settings, and
* etablish a device-specific profile to do stuff like pressure-related
* acceleration.
*/
SetDeviceSpecificAccelerationProfile(pVel,
SynapticsAccelerationProfile);
/* float property type */
float_type = XIGetKnownProperty(XATOM_FLOAT);
/* translate MinAcc to constant deceleration.
* May be overridden in xf86InitValuatorDefaults */
tmpf = 1.0 / priv->synpara.min_speed;
SynapticsMsg(priv, X_CONFIG,
"(accel) MinSpeed is now constant deceleration %.1f\n",
tmpf);
prop = XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION);
XIChangeDeviceProperty(dev, prop, float_type, 32,
PropModeReplace, 1, &tmpf, FALSE);
/* adjust accordingly */
priv->synpara.max_speed /= priv->synpara.min_speed;
priv->synpara.min_speed = 1.0;
/* synaptics seems to report 80 packet/s, but dix scales for
* 100 packet/s by default. */
pVel->corr_mul = 12.5f; /*1000[ms]/80[/s] = 12.5 */
SynapticsMsg(priv, X_CONFIG, "MaxSpeed is now %.2f\n",
priv->synpara.max_speed);
SynapticsMsg(priv, X_CONFIG, "AccelFactor is now %.3f\n",
priv->synpara.accl);
prop = XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER);
i = AccelProfileDeviceSpecific;
XIChangeDeviceProperty(dev, prop, XA_INTEGER, 32,
PropModeReplace, 1, &i, FALSE);
}
static int
DeviceInit(DeviceIntPtr dev)
{
InputInfoPtr pInfo = dev->public.devicePrivate;
struct SynapticsPrivate *priv = (struct SynapticsPrivate *) (pInfo->private);
struct SynapticsX11 *x11 = priv->frontend_data;
unsigned char map[SYN_MAX_BUTTONS + 1];
int i;
int min, max;
int num_axes = 2;
Atom btn_labels[SYN_MAX_BUTTONS] = { 0 };
Atom *axes_labels;
if (!SynapticsInitDevice(priv))
return BadAlloc;
num_axes += 2;
num_axes += priv->num_mt_axes;
axes_labels = calloc(num_axes, sizeof(Atom));
if (!axes_labels) {
SynapticsMsg(priv, MSG_ERROR, "failed to allocate axis labels\n");
return BadAlloc;
}
InitAxesLabels(axes_labels, num_axes, priv);
InitButtonLabels(btn_labels, SYN_MAX_BUTTONS);
for (i = 0; i <= SYN_MAX_BUTTONS; i++)
map[i] = i;
dev->public.on = FALSE;
InitPointerDeviceStruct((DevicePtr) dev, map,
SYN_MAX_BUTTONS,
btn_labels,
SynapticsCtrl,
GetMotionHistorySize(), num_axes, axes_labels);
DeviceInitAcceleration(dev);
/* X valuator */
if (priv->minx < priv->maxx) {
min = priv->minx;
max = priv->maxx;
}
else {
min = 0;
max = -1;
}
xf86InitValuatorAxisStruct(dev, 0, axes_labels[0], min, max,
priv->resx * 1000, 0, priv->resx * 1000,
Relative);
xf86InitValuatorDefaults(dev, 0);
/* Y valuator */
if (priv->miny < priv->maxy) {
min = priv->miny;
max = priv->maxy;
}
else {
min = 0;
max = -1;
}
xf86InitValuatorAxisStruct(dev, 1, axes_labels[1], min, max,
priv->resy * 1000, 0, priv->resy * 1000,
Relative);
xf86InitValuatorDefaults(dev, 1);
xf86InitValuatorAxisStruct(dev, 2, axes_labels[2], 0, -1, 0, 0, 0,
Relative);
xf86InitValuatorAxisStruct(dev, 3, axes_labels[3], 0, -1, 0, 0, 0,
Relative);
SetScrollValuator(dev, priv->scroll_axis_horiz, SCROLL_TYPE_HORIZONTAL,
priv->synpara.scroll_dist_horiz, 0);
SetScrollValuator(dev, priv->scroll_axis_vert, SCROLL_TYPE_VERTICAL,
priv->synpara.scroll_dist_vert, 0);
DeviceInitTouchAxes(dev, axes_labels);
InitDeviceProperties(pInfo);
XIRegisterPropertyHandler(pInfo->dev, SetProperty, NULL, NULL);
x11->event_mask = valuator_mask_new(4 + priv->num_mt_axes);
free(axes_labels);
return Success;
}
static int
DeviceOn(DeviceIntPtr dev)
{
InputInfoPtr pInfo = dev->public.devicePrivate;
struct SynapticsPrivate *priv = (struct SynapticsPrivate *) (pInfo->private);
pInfo->fd = xf86OpenSerial(pInfo->options);
if (pInfo->fd == -1) {
SynapticsMsg(priv, MSG_WARN, "cannot open input device\n");
return BadAlloc;
}
if (!SynapticsEnableDevice(priv, pInfo->fd))
return BadAlloc;
xf86FlushInput(pInfo->fd);
xf86AddEnabledDevice(pInfo);
dev->public.on = TRUE;
return Success;
}
static int
DeviceOff(DeviceIntPtr dev)
{
InputInfoPtr pInfo = dev->public.devicePrivate;
struct SynapticsPrivate *priv = (struct SynapticsPrivate *) (pInfo->private);
struct SynapticsX11 *x11 = priv->frontend_data;
Bool rc = Success;
if (pInfo->fd != -1) {
TimerCancel(x11->timer);
xf86RemoveEnabledDevice(pInfo);
if (!SynapticsDisableDevice(priv, pInfo->fd))
rc = !Success;
xf86CloseSerial(pInfo->fd);
pInfo->fd = -1;
}
dev->public.on = FALSE;
return rc;
}
static int
DeviceClose(DeviceIntPtr dev)
{
Bool RetValue;
InputInfoPtr pInfo = dev->public.devicePrivate;
struct SynapticsPrivate *priv = (struct SynapticsPrivate *) pInfo->private;
struct SynapticsX11 *x11 = priv->frontend_data;
RetValue = DeviceOff(dev);
SynapticsCloseDevice(priv);
TimerFree(x11->timer);
x11->timer = NULL;
valuator_mask_free(&x11->event_mask);
return RetValue;
}
static int
DeviceControl(DeviceIntPtr dev, int mode)
{
Bool RetValue;
switch (mode) {
case DEVICE_INIT:
RetValue = DeviceInit(dev);
break;
case DEVICE_ON:
RetValue = DeviceOn(dev);
break;
case DEVICE_OFF:
RetValue = DeviceOff(dev);
break;
case DEVICE_CLOSE:
RetValue = DeviceClose(dev);
break;
default:
RetValue = BadValue;
}
return RetValue;
}
static int
ControlProc(InputInfoPtr pInfo, xDeviceCtl * control)
{
return Success;
}
/* Area options support both percent values and absolute values. This is
* awkward. The xf86Set* calls will print to the log, but they'll
* also print an error if we request a percent value but only have an
* int. So - check first for percent, then call xf86Set* again to get
* the log message.
*/
static int set_percent_option(pointer options, const char* optname,
const int range, const int offset,
const int default_value)
{
int result;
double percent = xf86CheckPercentOption(options, optname, -1);
if (percent >= 0.0) {
percent = xf86SetPercentOption(options, optname, -1);
result = percent/100.0 * range + offset;
} else
result = xf86SetIntOption(options, optname, default_value);
return result;
}
static void set_softbutton_areas_option(InputInfoPtr pInfo)
{
struct SynapticsPrivate *priv = pInfo->private;
struct SynapticsParameters *pars = &priv->synpara;
int values[8];
int in_percent = 0; /* bitmask for which ones are in % */
char *option_string;
char *next_num;
char *end_str;
int i;
int width, height;
if (!pars->clickpad)
return;
option_string = xf86SetStrOption(pInfo->options, "SoftButtonAreas", NULL);
if (!option_string)
return;
next_num = option_string;
for (i = 0; i < 8 && *next_num != '\0'; i++)
{
long int value = strtol(next_num, &end_str, 0);
if (value > INT_MAX || value < -INT_MAX)
goto fail;
values[i] = value;
if (next_num != end_str)
{
if (end_str && *end_str == '%')
{
in_percent |= 1 << i;
end_str++;
}
next_num = end_str;
} else
goto fail;
}
if (i < 8 || *next_num != '\0')
goto fail;
width = priv->maxx - priv->minx;
height = priv->maxy - priv->miny;
for (i = 0; in_percent && i < 8; i++)
{
int base, size;
if ((in_percent & (1 << i)) == 0 || values[i] == 0)
continue;
size = ((i % 4) < 2) ? width : height;
base = ((i % 4) < 2) ? priv->minx : priv->miny;
values[i] = base + size * values[i]/100.0;
}
if (!SynapticsIsSoftButtonAreasValid(values))
goto fail;
memcpy(pars->softbutton_areas[0], values, 4 * sizeof(int));
memcpy(pars->softbutton_areas[1], values + 4, 4 * sizeof(int));
return;
fail:
SynapticsMsg(priv, MSG_ERROR, "invalid SoftButtonAreas value '%s', keeping defaults\n",
option_string);
}
void SynapticsOverrideDefaults(InputInfoPtr pInfo, struct SynapticsPrivate *priv)
{
struct SynapticsParameters *pars = &priv->synpara;
pointer opts = pInfo->options; /* read-only */
int width, height;
width = abs(priv->maxx - priv->minx);
height = abs(priv->maxy - priv->miny);
pars->left_edge = xf86SetIntOption(opts, "LeftEdge", pars->left_edge);
pars->right_edge = xf86SetIntOption(opts, "RightEdge", pars->right_edge);
pars->top_edge = xf86SetIntOption(opts, "TopEdge", pars->top_edge);
pars->bottom_edge = xf86SetIntOption(opts, "BottomEdge", pars->bottom_edge);
pars->finger_low = xf86SetIntOption(opts, "FingerLow", pars->finger_low);
pars->finger_high = xf86SetIntOption(opts, "FingerHigh", pars->finger_high);
pars->tap_time = xf86SetIntOption(opts, "MaxTapTime", pars->tap_time);
pars->tap_move = xf86SetIntOption(opts, "MaxTapMove", pars->tap_move);
pars->tap_time_2 = xf86SetIntOption(opts, "MaxDoubleTapTime", pars->tap_time_2);
pars->click_time = xf86SetIntOption(opts, "ClickTime", pars->click_time);
pars->clickpad = xf86SetIntOption(opts, "ClickPad", pars->clickpad);
pars->emulate_mid_button_time = xf86SetIntOption(opts, "EmulateMidButtonTime", pars->emulate_mid_button_time);
pars->emulate_twofinger_z = xf86SetIntOption(opts, "EmulateTwoFingerMinZ", pars->emulate_twofinger_z);
pars->emulate_twofinger_w = xf86SetIntOption(opts, "EmulateTwoFingerMinW", pars->emulate_twofinger_w);
pars->scroll_dist_vert = xf86SetIntOption(opts, "VertScrollDelta", pars->scroll_dist_vert);
pars->scroll_dist_horiz = xf86SetIntOption(opts, "HorizScrollDelta", pars->scroll_dist_horiz);
pars->scroll_edge_vert = xf86SetBoolOption(opts, "VertEdgeScroll", pars->scroll_edge_vert);
pars->scroll_edge_horiz = xf86SetBoolOption(opts, "HorizEdgeScroll", pars->scroll_edge_horiz);
pars->scroll_edge_corner = xf86SetBoolOption(opts, "CornerCoasting", pars->scroll_edge_corner);
pars->scroll_twofinger_vert = xf86SetBoolOption(opts, "VertTwoFingerScroll", pars->scroll_twofinger_vert);
pars->scroll_twofinger_horiz = xf86SetBoolOption(opts, "HorizTwoFingerScroll", pars->scroll_twofinger_horiz);
pars->touchpad_off = xf86SetIntOption(opts, "TouchpadOff", pars->touchpad_off);
pars->locked_drags = xf86SetBoolOption(opts, "LockedDrags", pars->locked_drags);
pars->locked_drag_time = xf86SetIntOption(opts, "LockedDragTimeout", pars->locked_drag_time);
pars->tap_action[RT_TAP] = xf86SetIntOption(opts, "RTCornerButton", pars->tap_action[RT_TAP]);
pars->tap_action[RB_TAP] = xf86SetIntOption(opts, "RBCornerButton", pars->tap_action[RB_TAP]);
pars->tap_action[LT_TAP] = xf86SetIntOption(opts, "LTCornerButton", pars->tap_action[LT_TAP]);
pars->tap_action[LB_TAP] = xf86SetIntOption(opts, "LBCornerButton", pars->tap_action[LB_TAP]);
pars->tap_action[F1_TAP] = xf86SetIntOption(opts, "TapButton1", pars->tap_action[F1_TAP]);
pars->tap_action[F2_TAP] = xf86SetIntOption(opts, "TapButton2", pars->tap_action[F2_TAP]);
pars->tap_action[F3_TAP] = xf86SetIntOption(opts, "TapButton3", pars->tap_action[F3_TAP]);
pars->click_action[F1_CLICK1] = xf86SetIntOption(opts, "ClickFinger1", pars->click_action[F1_CLICK1]);
pars->click_action[F2_CLICK1] = xf86SetIntOption(opts, "ClickFinger2", pars->click_action[F2_CLICK1]);
pars->click_action[F3_CLICK1] = xf86SetIntOption(opts, "ClickFinger3", pars->click_action[F3_CLICK1]);
pars->circular_scrolling = xf86SetBoolOption(opts, "CircularScrolling", pars->circular_scrolling);
pars->circular_trigger = xf86SetIntOption(opts, "CircScrollTrigger", pars->circular_trigger );
pars->palm_detect = xf86SetBoolOption(opts, "PalmDetect", pars->palm_detect);
pars->palm_min_width = xf86SetIntOption(opts, "PalmMinWidth", pars->palm_min_width);
pars->palm_min_z = xf86SetIntOption(opts, "PalmMinZ", pars->palm_min_z);
pars->single_tap_timeout = xf86SetIntOption(opts, "SingleTapTimeout", pars->single_tap_timeout);
pars->press_motion_min_z = xf86SetIntOption(opts, "PressureMotionMinZ", pars->press_motion_min_z);
pars->press_motion_max_z = xf86SetIntOption(opts, "PressureMotionMaxZ", pars->press_motion_max_z);
pars->min_speed = xf86SetRealOption(opts, "MinSpeed", pars->min_speed);
pars->max_speed = xf86SetRealOption(opts, "MaxSpeed", pars->max_speed);
pars->accl = xf86SetRealOption(opts, "AccelFactor", pars->accl);
pars->scroll_dist_circ = xf86SetRealOption(opts, "CircScrollDelta", pars->scroll_dist_circ);
pars->coasting_speed = xf86SetRealOption(opts, "CoastingSpeed", pars->coasting_speed);
pars->coasting_friction = xf86SetRealOption(opts, "CoastingFriction", pars->coasting_friction);
pars->press_motion_min_factor = xf86SetRealOption(opts, "PressureMotionMinFactor", pars->press_motion_min_factor);
pars->press_motion_max_factor = xf86SetRealOption(opts, "PressureMotionMaxFactor", pars->press_motion_max_factor);
pars->grab_event_device = xf86SetBoolOption(opts, "GrabEventDevice", pars->grab_event_device);
pars->tap_and_drag_gesture = xf86SetBoolOption(opts, "TapAndDragGesture", pars->tap_and_drag_gesture);
pars->resolution_horiz = xf86SetIntOption(opts, "HorizResolution", pars->resolution_horiz);
pars->resolution_vert = xf86SetIntOption(opts, "VertResolution", pars->resolution_vert);
/* set the parameters */
pars->area_top_edge = set_percent_option(opts, "AreaTopEdge", height, priv->miny, 0);
pars->area_bottom_edge = set_percent_option(opts, "AreaBottomEdge", height, priv->miny, 0);
pars->area_left_edge = set_percent_option(opts, "AreaLeftEdge", width, priv->minx, 0);
pars->area_right_edge = set_percent_option(opts, "AreaRightEdge", width, priv->minx, 0);
pars->hyst_x = set_percent_option(opts, "HorizHysteresis", width, 0, pars->hyst_x);
pars->hyst_y = set_percent_option(opts, "VertHysteresis", height, 0, pars->hyst_y);
/* Warn about (and fix) incorrectly configured TopEdge/BottomEdge parameters */
if (pars->top_edge > pars->bottom_edge) {
int tmp = pars->top_edge;
pars->top_edge = pars->bottom_edge;
pars->bottom_edge = tmp;
SynapticsMsg(priv, MSG_WARN, "TopEdge is bigger than BottomEdge. Fixing.\n");
}
set_softbutton_areas_option(pInfo);
}
static int
SwitchMode(ClientPtr client, DeviceIntPtr dev, int mode)
{
return XI_BadMode;
}
static void
ReadInput(InputInfoPtr pInfo)
{
SynapticsReadInput(pInfo->private, pInfo->fd);
}
static void FreeX11Private(struct SynapticsX11 **x11)
{
if ((*x11)->timer)
TimerFree((*x11)->timer);
free(*x11);
*x11 = NULL;
}
struct SynapticsX11 *InitX11Private(void)
{
struct SynapticsX11 *x11;
x11 = calloc(1, sizeof(*x11));
if (x11) {
x11->timer = TimerSet(NULL, 0, 0, NULL, NULL);
if (!x11->timer)
FreeX11Private(&x11);
}
return x11;
}
struct SynapticsFrontend x11_frontend = {
X11SynapticsMsg,
X11SynapticsGetCurrentMillis,
X11SynapticsButtonEvent,
X11SynapticsMotionEvent,
X11SynapticsScrollEvent,
X11SynapticsTouchEvent,
X11SynapticsSetTimer,
};
static int
SynapticsPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
{
struct SynapticsPrivate *priv;
struct SynapticsX11 *x11;
char *proto;
char *device, *actual_device;
x11 = InitX11Private();
if (!x11)
return BadAlloc;
/* allocate memory for struct SynapticsPrivateRec */
priv = SynapticsInitPrivate(&x11_frontend);
if (!priv) {
FreeX11Private(&x11);
return BadAlloc;
}
priv->frontend_data = x11;
x11->pInfo = pInfo;
pInfo->type_name = XI_TOUCHPAD;
pInfo->device_control = DeviceControl;
pInfo->read_input = ReadInput;
pInfo->control_proc = ControlProc;
pInfo->switch_mode = SwitchMode;
pInfo->private = priv;
proto = xf86SetStrOption(pInfo->options, "Protocol", NULL);
device = xf86SetStrOption(pInfo->options, "Device", NULL);
priv->proto_ops = SynapticsGetDeviceProtocolOps(priv, proto, device, &actual_device);
free(proto);
free(device);
if (!priv->proto_ops) {
xf86IDrvMsg(pInfo, MSG_ERROR,
"Synaptics driver unable to detect protocol\n");
goto SetupProc_fail;
}
priv->device = actual_device;
/* open the touchpad device */
pInfo->fd = xf86OpenSerial(pInfo->options);
if (pInfo->fd == -1) {
xf86IDrvMsg(pInfo, MSG_ERROR, "Synaptics driver unable to open device\n");
goto SetupProc_fail;
}
xf86ErrorFVerb(6, "port opened successfully\n");
/* read hardware dimensions */
if (!SynapticsQueryHardware(priv, pInfo->fd)) {
xf86IDrvMsg(pInfo, MSG_ERROR,
"Unable to query/initialize Synaptics hardware.\n");
goto SetupProc_fail;
}
SynapticsOverrideDefaults(pInfo, priv);
SynapticsFinishPreInit(priv);
xf86ProcessCommonOptions(pInfo, pInfo->options);
if (pInfo->fd != -1)
xf86CloseSerial(pInfo->fd);
pInfo->fd = -1;
return Success;
SetupProc_fail:
if (pInfo->fd >= 0) {
xf86CloseSerial(pInfo->fd);
pInfo->fd = -1;
}
FreeX11Private(&x11);
SynapticsFreePrivate(&priv);
pInfo->private = NULL;
return BadAlloc;
}
static void
DeviceInitTouchAxes(DeviceIntPtr dev, Atom *axes_labels)
{
InputInfoPtr pInfo = dev->public.devicePrivate;
struct SynapticsPrivate *priv = (struct SynapticsPrivate *) (pInfo->private);
int i;
if (!priv->has_touch)
return;
/* x/y + whatever other MT axes we found */
if (!InitTouchClassDeviceStruct(dev, priv->max_touches,
XIDependentTouch,
2 + priv->num_mt_axes)) {
SynapticsMsg(priv, MSG_ERROR,
"failed to initialize touch class device\n");
priv->has_touch = 0;
priv->num_slots = 0;
free(priv->open_slots);
priv->open_slots = NULL;
return;
}
for (i = 0; i < priv->num_mt_axes; i++) {
SynapticsTouchAxisRec *axis = &priv->touch_axes[i];
int axnum = 4 + i; /* Skip x, y, and scroll axes */
if (!xf86InitValuatorAxisStruct(dev, axnum, axes_labels[axnum],
axis->min, axis->max, axis->res, 0,
axis->res, Absolute)) {
SynapticsMsg(priv, MSG_WARN,
"failed to initialize axis %s, skipping\n",
axis->label);
continue;
}
xf86InitValuatorDefaults(dev, axnum);
}
}
static void
X11SynapticsButtonEvent(struct SynapticsPrivate *priv, int button, enum ButtonEventType press)
{
struct SynapticsX11 *x11 = priv->frontend_data;
InputInfoPtr pInfo = x11->pInfo;
xf86PostButtonEvent(pInfo->dev, FALSE, button, press == BTN_PRESS, 0, 0);
}
static void
X11SynapticsMotionEvent(struct SynapticsPrivate *priv, int x, int y)
{
struct SynapticsX11 *x11 = priv->frontend_data;
InputInfoPtr pInfo = x11->pInfo;
xf86PostMotionEvent(pInfo->dev, FALSE, 0, 2, x, y);
}
static void
X11SynapticsScrollEvent(struct SynapticsPrivate *priv, unsigned int which, double vert, double horiz)
{
struct SynapticsX11 *x11 = priv->frontend_data;
InputInfoPtr pInfo = x11->pInfo;
ValuatorMask *m = x11->event_mask;
if (!which)
return;
valuator_mask_zero(x11->event_mask);
if (which & SCROLL_VERT)
valuator_mask_set_double(m, priv->scroll_axis_vert, vert);
if (which & SCROLL_HORIZ)
valuator_mask_set_double(m, priv->scroll_axis_horiz, horiz);
xf86PostMotionEventM(pInfo->dev, FALSE, m);
}
static void
X11SynapticsTouchEvent(struct SynapticsPrivate *priv, unsigned int touchid,
enum TouchEventType type, struct VMask *mask)
{
struct SynapticsX11 *x11 = priv->frontend_data;
InputInfoPtr pInfo = x11->pInfo;
int x11_type, i;
ValuatorMask *m = x11->event_mask;
switch (type) {
case T_BEGIN: x11_type = XI_TouchBegin; break;
case T_UPDATE: x11_type = XI_TouchUpdate; break;
case T_END: x11_type = XI_TouchEnd; break;
}
valuator_mask_zero(x11->event_mask);
for (i = 0; i < vmask_size(mask); i++) {
double val;
if (vmask_fetch_double(mask, i, &val))
valuator_mask_set_double(m, i, val);
}
xf86PostTouchEvent(pInfo->dev, touchid, x11_type, 0, m);
}
/*
* Uninitialize the device.
*/
static void
SynapticsUnInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
{
struct SynapticsPrivate *priv = pInfo->private;
if (priv) {
struct SynapticsX11 *x11 = priv->frontend_data;
if (x11)
FreeX11Private(&x11);
SynapticsFreePrivate(&priv);
}
xf86DeleteInput(pInfo, 0);
}
InputDriverRec SYNAPTICS = {
1,
"synaptics",
NULL,
SynapticsPreInit,
SynapticsUnInit,
NULL,
};
static XF86ModuleVersionInfo VersionRec = {
"synaptics",
MODULEVENDORSTRING,
MODINFOSTRING1,
MODINFOSTRING2,
XORG_VERSION_CURRENT,
PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
ABI_CLASS_XINPUT,
ABI_XINPUT_VERSION,
MOD_CLASS_XINPUT,
{0, 0, 0, 0}
};
static pointer
SetupProc(pointer module, pointer options, int *errmaj, int *errmin)
{
xf86AddInputDriver(&SYNAPTICS, module, 0);
return module;
}
_X_EXPORT XF86ModuleData synapticsModuleData = {
&VersionRec,
&SetupProc,
NULL
};
|