-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathVoodooPS2TouchPadBase.cpp
1017 lines (890 loc) · 32.7 KB
/
VoodooPS2TouchPadBase.cpp
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
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// Created by Brandon Pedersen on 5/1/13.
//
#include <IOKit/IOLib.h>
#include <IOKit/hidsystem/IOHIDParameter.h>
#include <IOKit/IOWorkLoop.h>
#include <IOKit/IOTimerEventSource.h>
#include "VoodooPS2Controller.h"
#include "VoodooPS2TouchPadBase.h"
// =============================================================================
// VoodooPS2TouchPadBase Class Implementation
//
OSDefineMetaClassAndAbstractStructors(VoodooPS2TouchPadBase, IOHIPointing);
UInt32 VoodooPS2TouchPadBase::deviceType()
{ return NX_EVS_DEVICE_TYPE_MOUSE; };
UInt32 VoodooPS2TouchPadBase::interfaceID()
{ return NX_EVS_DEVICE_INTERFACE_BUS_ACE; };
IOItemCount VoodooPS2TouchPadBase::buttonCount() { return _buttonCount; };
IOFixed VoodooPS2TouchPadBase::resolution() { return _resolution << 16; };
#define abs(x) ((x) < 0 ? -(x) : (x))
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool VoodooPS2TouchPadBase::init(OSDictionary * dict)
{
//
// Initialize this object's minimal state. This is invoked right after this
// object is instantiated.
//
if (!super::init(dict))
return false;
// find config specific to Platform Profile
OSDictionary* list = OSDynamicCast(OSDictionary, dict->getObject(kPlatformProfile));
OSDictionary* config = ApplePS2Controller::makeConfigurationNode(list);
if (config)
{
// if DisableDevice is Yes, then do not load at all...
OSBoolean* disable = OSDynamicCast(OSBoolean, config->getObject(kDisableDevice));
if (disable && disable->isTrue())
{
config->release();
return false;
}
#ifdef DEBUG
// save configuration for later/diagnostics...
setProperty(kMergedConfiguration, config);
#endif
}
// initialize state...
_device = NULL;
_interruptHandlerInstalled = false;
_powerControlHandlerInstalled = false;
_messageHandlerInstalled = false;
_packetByteCount = 0;
_lastdata = 0;
_cmdGate = 0;
// set defaults for configuration items
/*z_finger=45;
divisorx=divisory=1;
ledge=1700;
redge=5200;
tedge=4200;
bedge=1700;
vscrolldivisor=30;
hscrolldivisor=30;
cscrolldivisor=0;
ctrigger=0;
centerx=3000;
centery=3000;
maxtaptime=130000000;
maxdragtime=230000000;
hsticky=0;
vsticky=0;
wsticky=0;
tapstable=1;
wlimit=9;
wvdivisor=30;
whdivisor=30;
clicking=true;
rtap=true;
dragging=true;
threefingervertswipe=true;
threefingerhorizswipe=true;
draglock=false;
draglocktemp=0;
hscroll=vscroll=true;
scroll=true;
outzone_wt = palm = palm_wt = false;
zlimit = 100;
noled = false;
maxaftertyping = 500000000;
mousemultiplierx = 20;
mousemultipliery = 20;
mousescrollmultiplierx = 20;
mousescrollmultipliery = 20;
mousemiddlescroll = true;
wakedelay = 1000;
skippassthru = false;
tapthreshx = tapthreshy = 50;
dblthreshx = dblthreshy = 100;
zonel = 1700; zoner = 5200;
zonet = 99999; zoneb = 0;
diszl = 0; diszr = 1700;
diszt = 99999; diszb = 4200;
diszctrl = 0;
_resolution = 2300;
_scrollresolution = 2300;
swipedx = swipedy = 800;
rczl = 3800; rczt = 2000;
rczr = 99999; rczb = 0;
_buttonCount = 2;
swapdoubletriple = false;
draglocktempmask = 0x0100010; // default is Command key
clickpadclicktime = 300000000; // 300ms default
clickpadtrackboth = true;
bogusdxthresh = 400;
bogusdythresh = 350;
scrolldxthresh = 10;
scrolldythresh = 10;
immediateclick = true;
xupmm = yupmm = 50; // 50 is just arbitrary, but same
_extendedwmode=false;
// intialize state
lastx=0;
lasty=0;
last_fingers=0;
xrest=0;
yrest=0;
lastbuttons=0;
// intialize state for secondary packets/extendedwmode
xrest2=0;
yrest2=0;
clickedprimary=false;
lastx2=0;
lasty2=0;
tracksecondary=false;
// state for middle button
_buttonTimer = 0;
_mbuttonstate = STATE_NOBUTTONS;
_pendingbuttons = 0;
_buttontime = 0;
_maxmiddleclicktime = 100000000;
_fakemiddlebutton = true;
ignoredeltas=0;
ignoredeltasstart=0;
scrollrest=0;
touchtime=untouchtime=0;
wastriple=wasdouble=false;
keytime = 0;
ignoreall = false;
passbuttons = 0;
passthru = false;
ledpresent = false;
clickpadtype = 0;
_clickbuttons = 0;
_reportsv = false;
mousecount = 0;
usb_mouse_stops_trackpad = true;
_modifierdown = 0;
scrollzoommask = 0;
inSwipeLeft=inSwipeRight=inSwipeDown=inSwipeUp=0;
xmoved=ymoved=0;
momentumscroll = true;
scrollTimer = 0;
momentumscrolltimer = 10000000;
momentumscrollthreshy = 7;
momentumscrollmultiplier = 98;
momentumscrolldivisor = 100;
momentumscrollsamplesmin = 3;
momentumscrollcurrent = 0;
dragexitdelay = 100000000;
dragTimer = 0;
touchmode=MODE_NOTOUCH;*/
IOLog("VoodooPS2TouchPad Base Driver loaded...\n");
setProperty("Revision", 24, 32);
//
// Load settings specific to Platform Profile
//
setParamPropertiesGated(config);
OSSafeReleaseNULL(config);
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool VoodooPS2TouchPadBase::start( IOService * provider )
{
//
// The driver has been instructed to start. This is called after a
// successful probe and match.
//
if (!super::start(provider))
return false;
//
// Maintain a pointer to and retain the provider object.
//
_device = (ApplePS2MouseDevice *) provider;
_device->retain();
//
// Advertise the current state of the tapping feature.
//
// Must add this property to let our superclass know that it should handle
// trackpad acceleration settings from user space. Without this, tracking
// speed adjustments from the mouse prefs panel have no effect.
//
setProperty(kIOHIDPointerAccelerationTypeKey, kIOHIDTrackpadAccelerationType);
setProperty(kIOHIDScrollAccelerationTypeKey, kIOHIDTrackpadScrollAccelerationKey);
setProperty(kIOHIDScrollResolutionKey, _scrollresolution << 16, 32);
setProperty("HIDScrollResolutionX", _scrollresolution << 16, 32);
setProperty("HIDScrollResolutionY", _scrollresolution << 16, 32);
//
// Setup workloop with command gate for thread synchronization...
//
IOWorkLoop* pWorkLoop = getWorkLoop();
_cmdGate = IOCommandGate::commandGate(this);
if (!pWorkLoop || !_cmdGate)
{
_device->release();
return false;
}
//
// Setup button timer event source
//
if (_buttonCount >= 3)
{
_buttonTimer = IOTimerEventSource::timerEventSource(this, OSMemberFunctionCast(IOTimerEventSource::Action, this, &VoodooPS2TouchPadBase::onButtonTimer));
if (!_buttonTimer)
{
_device->release();
return false;
}
pWorkLoop->addEventSource(_buttonTimer);
}
//
// Setup dragTimer event source
//
if (dragexitdelay)
{
dragTimer = IOTimerEventSource::timerEventSource(this, OSMemberFunctionCast(IOTimerEventSource::Action, this, &VoodooPS2TouchPadBase::onDragTimer));
if (dragTimer)
pWorkLoop->addEventSource(dragTimer);
}
pWorkLoop->addEventSource(_cmdGate);
//
// Setup scrolltimer event source
//
scrollTimer = IOTimerEventSource::timerEventSource(this, OSMemberFunctionCast(IOTimerEventSource::Action, this, &VoodooPS2TouchPadBase::onScrollTimer));
if (scrollTimer)
pWorkLoop->addEventSource(scrollTimer);
//
// Lock the controller during initialization
//
_device->lock();
//
// Perform any implementation specific device initialization
//
if (!deviceSpecificInit()) {
_device->unlock();
_device->release();
// TODO: any other cleanup?
return false;
}
//
// Install our driver's interrupt handler, for asynchronous data delivery.
//
_device->installInterruptAction(this,
OSMemberFunctionCast(PS2InterruptAction,this,&VoodooPS2TouchPadBase::interruptOccurred),
OSMemberFunctionCast(PS2PacketAction, this, &VoodooPS2TouchPadBase::packetReady));
_interruptHandlerInstalled = true;
// now safe to allow other threads
_device->unlock();
//
// Install our power control handler.
//
_device->installPowerControlAction( this,
OSMemberFunctionCast(PS2PowerControlAction, this, &VoodooPS2TouchPadBase::setDevicePowerState) );
_powerControlHandlerInstalled = true;
//
// Install message hook for keyboard to trackpad communication
//
_device->installMessageAction( this,
OSMemberFunctionCast(PS2MessageAction, this, &VoodooPS2TouchPadBase::receiveMessage));
_messageHandlerInstalled = true;
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void VoodooPS2TouchPadBase::stop( IOService * provider )
{
DEBUG_LOG("%s: stop called\n", getName());
//
// The driver has been instructed to stop. Note that we must break all
// connections to other service objects now (ie. no registered actions,
// no pointers and retains to objects, etc), if any.
//
assert(_device == provider);
// free up timer for scroll momentum
IOWorkLoop* pWorkLoop = getWorkLoop();
if (pWorkLoop)
{
if (scrollTimer)
{
pWorkLoop->removeEventSource(scrollTimer);
scrollTimer->release();
scrollTimer = 0;
}
if (_buttonTimer)
{
pWorkLoop->removeEventSource(_buttonTimer);
_buttonTimer->release();
_buttonTimer = 0;
}
if (_cmdGate)
{
pWorkLoop->removeEventSource(_cmdGate);
_cmdGate->release();
_cmdGate = 0;
}
}
//
// Uninstall the interrupt handler.
//
if (_interruptHandlerInstalled)
{
_device->uninstallInterruptAction();
_interruptHandlerInstalled = false;
}
//
// Uninstall the power control handler.
//
if (_powerControlHandlerInstalled)
{
_device->uninstallPowerControlAction();
_powerControlHandlerInstalled = false;
}
//
// Uinstall message handler.
//
if (_messageHandlerInstalled)
{
_device->uninstallMessageAction();
_messageHandlerInstalled = false;
}
//
// Release the pointer to the provider object.
//
OSSafeReleaseNULL(_device);
super::stop(provider);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void VoodooPS2TouchPadBase::onScrollTimer(void)
{
//
// This will be invoked by our workloop timer event source to implement
// momentum scroll.
//
if (!momentumscrollcurrent)
return;
uint64_t now_abs;
clock_get_uptime(&now_abs);
int64_t dy64 = momentumscrollcurrent / (int64_t)momentumscrollinterval + momentumscrollrest2;
int dy = (int)dy64;
if (abs(dy) > momentumscrollthreshy)
{
// dispatch the scroll event
dispatchScrollWheelEventX(wvdivisor ? dy / wvdivisor : 0, 0, 0, now_abs);
momentumscrollrest2 = wvdivisor ? dy % wvdivisor : 0;
// adjust momentumscrollcurrent
momentumscrollcurrent = momentumscrollcurrent * momentumscrollmultiplier + momentumscrollrest1;
momentumscrollrest1 = momentumscrollcurrent % momentumscrolldivisor;
momentumscrollcurrent /= momentumscrolldivisor;
// start another timer
setTimerTimeout(scrollTimer, momentumscrolltimer);
}
else
{
// no more scrolling...
momentumscrollcurrent = 0;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void VoodooPS2TouchPadBase::onButtonTimer(void)
{
uint64_t now_abs;
clock_get_uptime(&now_abs);
middleButton(lastbuttons, now_abs, fromTimer);
}
UInt32 VoodooPS2TouchPadBase::middleButton(UInt32 buttons, uint64_t now_abs, MBComingFrom from)
{
if (!_fakemiddlebutton || _buttonCount <= 2 || (ignoreall && fromTrackpad == from))
return buttons;
// cancel timer if we see input before timeout has fired, but after expired
bool timeout = false;
uint64_t now_ns;
absolutetime_to_nanoseconds(now_abs, &now_ns);
if (fromTimer == from || fromCancel == from || now_ns - _buttontime > _maxmiddleclicktime)
timeout = true;
//
// A state machine to simulate middle buttons with two buttons pressed
// together.
//
switch (_mbuttonstate)
{
// no buttons down, waiting for something to happen
case STATE_NOBUTTONS:
if (fromCancel != from)
{
if (buttons & 0x4)
_mbuttonstate = STATE_NOOP;
else if (0x3 == buttons)
_mbuttonstate = STATE_MIDDLE;
else if (0x0 != buttons)
{
// only single button, so delay this for a bit
_pendingbuttons = buttons;
_buttontime = now_ns;
setTimerTimeout(_buttonTimer, _maxmiddleclicktime);
_mbuttonstate = STATE_WAIT4TWO;
}
}
break;
// waiting for second button to come down or timeout
case STATE_WAIT4TWO:
if (!timeout && 0x3 == buttons)
{
_pendingbuttons = 0;
cancelTimer(_buttonTimer);
_mbuttonstate = STATE_MIDDLE;
}
else if (timeout || buttons != _pendingbuttons)
{
if (fromTimer == from || !(buttons & _pendingbuttons))
dispatchRelativePointerEventX(0, 0, buttons|_pendingbuttons, now_abs);
_pendingbuttons = 0;
cancelTimer(_buttonTimer);
if (0x0 == buttons)
_mbuttonstate = STATE_NOBUTTONS;
else
_mbuttonstate = STATE_NOOP;
}
break;
// both buttons down and delivering middle button
case STATE_MIDDLE:
if (0x0 == buttons)
_mbuttonstate = STATE_NOBUTTONS;
else if (0x3 != (buttons & 0x3))
{
// only single button, so delay to see if we get to none
_pendingbuttons = buttons;
_buttontime = now_ns;
setTimerTimeout(_buttonTimer, _maxmiddleclicktime);
_mbuttonstate = STATE_WAIT4NONE;
}
break;
// was middle button, but one button now up, waiting for second to go up
case STATE_WAIT4NONE:
if (!timeout && 0x0 == buttons)
{
_pendingbuttons = 0;
cancelTimer(_buttonTimer);
_mbuttonstate = STATE_NOBUTTONS;
}
else if (timeout || buttons != _pendingbuttons)
{
if (fromTimer == from)
dispatchRelativePointerEventX(0, 0, buttons|_pendingbuttons, now_abs);
_pendingbuttons = 0;
cancelTimer(_buttonTimer);
if (0x0 == buttons)
_mbuttonstate = STATE_NOBUTTONS;
else
_mbuttonstate = STATE_NOOP;
}
break;
case STATE_NOOP:
if (0x0 == buttons)
_mbuttonstate = STATE_NOBUTTONS;
break;
}
// modify buttons after new state set
switch (_mbuttonstate)
{
case STATE_MIDDLE:
buttons = 0x4;
break;
case STATE_WAIT4NONE:
case STATE_WAIT4TWO:
buttons &= ~0x3;
break;
case STATE_NOBUTTONS:
case STATE_NOOP:
break;
}
// return modified buttons
return buttons;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void VoodooPS2TouchPadBase::onDragTimer(void)
{
if (MODE_DRAGNOTOUCH==touchmode)
{
touchmode=MODE_NOTOUCH;
uint64_t now_abs;
clock_get_uptime(&now_abs);
UInt32 buttons = middleButton(lastbuttons & ~0x01, now_abs, fromPassthru);
DEBUG_LOG("ps2: onDragTimer, button = %d\n", buttons);
dispatchRelativePointerEventX(0, 0, buttons, now_abs);
}
else
{
//REVIEW: for debugging...
IOLog("rehab: onDragTimer called with unexpected mode = %d\n", touchmode);
}
//TODO: cancel dragnotouch mode, revert to notouch
//TODO: send lbutton up without modifying other buttons
//TODO: find other places the timer should be cancelled.
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void VoodooPS2TouchPadBase::initTouchPad()
{
//
// Clear packet buffer pointer to avoid issues caused by
// stale packet fragments.
//
_packetByteCount = 0;
_ringBuffer.reset();
// clear passbuttons, just in case buttons were down when system
// went to sleep (now just assume they are up)
passbuttons = 0;
_clickbuttons = 0;
tracksecondary=false;
// clear state of control key cache
_modifierdown = 0;
// initialize the touchpad
deviceSpecificInit();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void VoodooPS2TouchPadBase::setParamPropertiesGated(OSDictionary * config)
{
if (NULL == config)
return;
const struct {const char *name; int *var;} int32vars[]={
{"FingerZ", &z_finger},
{"DivisorX", &divisorx},
{"DivisorY", &divisory},
{"EdgeRight", &redge},
{"EdgeLeft", &ledge},
{"EdgeTop", &tedge},
{"EdgeBottom", &bedge},
{"VerticalScrollDivisor", &vscrolldivisor},
{"HorizontalScrollDivisor", &hscrolldivisor},
{"CircularScrollDivisor", &cscrolldivisor},
{"CenterX", ¢erx},
{"CenterY", ¢ery},
{"CircularScrollTrigger", &ctrigger},
{"MultiFingerWLimit", &wlimit},
{"MultiFingerVerticalDivisor", &wvdivisor},
{"MultiFingerHorizontalDivisor", &whdivisor},
{"ZLimit", &zlimit},
{"MouseMultiplierX", &mousemultiplierx},
{"MouseMultiplierY", &mousemultipliery},
{"MouseScrollMultiplierX", &mousescrollmultiplierx},
{"MouseScrollMultiplierY", &mousescrollmultipliery},
{"WakeDelay", &wakedelay},
{"TapThresholdX", &tapthreshx},
{"TapThresholdY", &tapthreshy},
{"DoubleTapThresholdX", &dblthreshx},
{"DoubleTapThresholdY", &dblthreshy},
{"ZoneLeft", &zonel},
{"ZoneRight", &zoner},
{"ZoneTop", &zonet},
{"ZoneBottom", &zoneb},
{"DisableZoneLeft", &diszl},
{"DisableZoneRight", &diszr},
{"DisableZoneTop", &diszt},
{"DisableZoneBottom", &diszb},
{"DisableZoneControl", &diszctrl},
{"Resolution", &_resolution},
{"ScrollResolution", &_scrollresolution},
{"SwipeDeltaX", &swipedx},
{"SwipeDeltaY", &swipedy},
{"MouseCount", &mousecount},
{"RightClickZoneLeft", &rczl},
{"RightClickZoneRight", &rczr},
{"RightClickZoneTop", &rczt},
{"RightClickZoneBottom", &rczb},
{"HIDScrollZoomModifierMask", &scrollzoommask},
{"ButtonCount", &_buttonCount},
{"DragLockTempMask", &draglocktempmask},
{"MomentumScrollThreshY", &momentumscrollthreshy},
{"MomentumScrollMultiplier", &momentumscrollmultiplier},
{"MomentumScrollDivisor", &momentumscrolldivisor},
{"MomentumScrollSamplesMin", &momentumscrollsamplesmin},
{"FingerChangeIgnoreDeltas", &ignoredeltasstart},
{"BogusDeltaThreshX", &bogusdxthresh},
{"BogusDeltaThreshY", &bogusdythresh},
{"UnitsPerMMX", &xupmm},
{"UnitsPerMMY", &yupmm},
{"ScrollDeltaThreshX", &scrolldxthresh},
{"ScrollDeltaThreshY", &scrolldythresh},
{"TrackpadThreeFingerVertSwipeGesture", &threefingervertswipe},
{"TrackpadThreeFingerHorizSwipeGesture", &threefingerhorizswipe},
};
const struct {const char *name; int *var;} boolvars[]={
{"StickyHorizontalScrolling", &hsticky},
{"StickyVerticalScrolling", &vsticky},
{"StickyMultiFingerScrolling", &wsticky},
{"StabilizeTapping", &tapstable},
{"DisableLEDUpdate", &noled},
{"SmoothInput", &smoothinput},
{"UnsmoothInput", &unsmoothinput},
{"SkipPassThrough", &skippassthru},
{"SwapDoubleTriple", &swapdoubletriple},
{"ClickPadTrackBoth", &clickpadtrackboth},
{"ImmediateClick", &immediateclick},
{"MouseMiddleScroll", &mousemiddlescroll},
{"FakeMiddleButton", &_fakemiddlebutton},
};
const struct {const char* name; bool* var;} lowbitvars[]={
{"Clicking", &clicking},
{"Dragging", &dragging},
{"TrackpadRightClick", &rtap},
{"DragLock", &draglock},
{"TrackpadHorizScroll", &hscroll},
{"TrackpadVertScroll", &vscroll},
{"TrackpadScroll", &scroll},
{"OutsidezoneNoAction When Typing", &outzone_wt},
{"PalmNoAction Permanent", &palm},
{"PalmNoAction When Typing", &palm_wt},
{"USBMouseStopsTrackpad", &usb_mouse_stops_trackpad},
{"TrackpadMomentumScroll", &momentumscroll},
};
const struct {const char* name; uint64_t* var; } int64vars[]={
{"MaxDragTime", &maxdragtime},
{"MaxTapTime", &maxtaptime},
{"HIDClickTime", &maxdbltaptime},
{"QuietTimeAfterTyping", &maxaftertyping},
{"MomentumScrollTimer", &momentumscrolltimer},
{"ClickPadClickTime", &clickpadclicktime},
{"MiddleClickTime", &_maxmiddleclicktime},
{"DragExitDelayTime", &dragexitdelay},
};
int oldmousecount = mousecount;
bool old_usb_mouse_stops_trackpad = usb_mouse_stops_trackpad;
OSBoolean *bl;
OSNumber *num;
// 64-bit config items
for (int i = 0; i < countof(int64vars); i++) {
if ((num=OSDynamicCast(OSNumber, config->getObject(int64vars[i].name))))
{
*int64vars[i].var = num->unsigned64BitValue();
////DEBUG_LOG("%s::setProperty64(%s, %llu)\n", getName(), int64vars[i].name, *int64vars[i].var);
setProperty(int64vars[i].name, *int64vars[i].var, 64);
}
}
// boolean config items
for (int i = 0; i < countof(boolvars); i++) {
if ((bl=OSDynamicCast (OSBoolean,config->getObject (boolvars[i].name))))
{
*boolvars[i].var = bl->isTrue();
////DEBUG_LOG("%s::setPropertyBool(%s, %d)\n", getName(), boolvars[i].name, *boolvars[i].var);
setProperty(boolvars[i].name, *boolvars[i].var ? kOSBooleanTrue : kOSBooleanFalse);
}
}
// 32-bit config items
for (int i = 0; i < countof(int32vars);i++) {
if ((num=OSDynamicCast (OSNumber,config->getObject (int32vars[i].name))))
{
*int32vars[i].var = num->unsigned32BitValue();
////DEBUG_LOG("%s::setProperty32(%s, %d)\n", getName(), int32vars[i].name, *int32vars[i].var);
setProperty(int32vars[i].name, *int32vars[i].var, 32);
}
}
// lowbit config items
for (int i = 0; i < countof(lowbitvars); i++) {
if ((num=OSDynamicCast (OSNumber,config->getObject(lowbitvars[i].name))))
{
*lowbitvars[i].var = (num->unsigned32BitValue()&0x1)?true:false;
////DEBUG_LOG("%s::setPropertyLowBit(%s, %d)\n", getName(), lowbitvars[i].name, *lowbitvars[i].var);
setProperty(lowbitvars[i].name, *lowbitvars[i].var ? 1 : 0, 32);
}
}
// special case for MaxDragTime (which is really max time for a double-click)
// we can let it go no more than 230ms because otherwise taps on
// the menu bar take too long if drag mode is enabled. The code in that case
// has to "hold button 1 down" for the duration of maxdragtime because if
// it didn't then dragging on the caption of a window will not work
// (some other apps too) because these apps will see a double tap+hold as
// a single click, then double click and they don't go into drag mode when
// initiated with a double click.
//
// same thing going on with the forward/back buttons in Finder, except the
// timeout OS X is using is different (shorter)
//
// this all happens during MODE_PREDRAG
//
// summary:
// if the code releases button 1 after a tap, then dragging windows
// breaks
// if the maxdragtime is too large (200ms is small enough, 500ms is too large)
// then clicking on menus breaks because the system sees it as a long
// press and hold
//
// fyi:
// also tried to allow release of button 1 during MODE_PREDRAG, and then when
// attempting to initiate the drag (in the case the second touch comes soon
// enough), modifying the time such that it is not seen as a double tap.
// unfortunately, that destroys double tap as well, probably because the
// system is confused seeing input "out of order"
//if (maxdragtime > 230000000)
// maxdragtime = 230000000;
// DivisorX and DivisorY cannot be zero, but don't crash if they are...
if (!divisorx)
divisorx = 1;
if (!divisory)
divisory = 1;
// bogusdeltathreshx/y = 0 is MAX_INT
if (!bogusdxthresh)
bogusdxthresh = 0x7FFFFFFF;
if (!bogusdythresh)
bogusdythresh = 0x7FFFFFFF;
//REVIEW: this should be done maybe only when necessary...
touchmode=MODE_NOTOUCH;
// check for special terminating sequence from PS2Daemon
if (-1 == mousecount)
{
DEBUG_LOG("Shutdown touchpad, mousecount=%d\n", mousecount);
touchpadShutdown();
mousecount = oldmousecount;
}
// disable trackpad when USB mouse is plugged in
// check for mouse count changing...
if ((oldmousecount != 0) != (mousecount != 0) || old_usb_mouse_stops_trackpad != usb_mouse_stops_trackpad)
{
// either last mouse removed or first mouse added
ignoreall = (mousecount != 0) && usb_mouse_stops_trackpad;
touchpadToggled();
}
}
IOReturn VoodooPS2TouchPadBase::setParamProperties(OSDictionary* dict)
{
////IOReturn result = super::IOHIDevice::setParamProperties(dict);
if (_cmdGate)
{
// syncronize through workloop...
////_cmdGate->runAction(OSMemberFunctionCast(IOCommandGate::Action, this, &VooodooPS2TouchPadBase::setParamPropertiesGated), dict);
setParamPropertiesGated(dict);
}
return super::setParamProperties(dict);
////return result;
}
IOReturn VoodooPS2TouchPadBase::setProperties(OSObject *props)
{
OSDictionary *dict = OSDynamicCast(OSDictionary, props);
if (dict && _cmdGate)
{
// syncronize through workloop...
_cmdGate->runAction(OSMemberFunctionCast(IOCommandGate::Action, this, &VoodooPS2TouchPadBase::setParamPropertiesGated), dict);
}
return super::setProperties(props);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void VoodooPS2TouchPadBase::setDevicePowerState( UInt32 whatToDo )
{
switch ( whatToDo )
{
case kPS2C_DisableDevice:
//
// Disable touchpad (synchronous).
//
setTouchPadEnable( false );
break;
case kPS2C_EnableDevice:
//
// Must not issue any commands before the device has
// completed its power-on self-test and calibration.
//
IOSleep(wakedelay);
// Reset and enable the touchpad.
initTouchPad();
break;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void VoodooPS2TouchPadBase::receiveMessage(int message, void* data)
{
//
// Here is where we receive messages from the keyboard driver
//
// This allows for the keyboard driver to enable/disable the trackpad
// when a certain keycode is pressed.
//
// It also allows the trackpad driver to learn the last time a key
// has been pressed, so it can implement various "ignore trackpad
// input while typing" options.
//
switch (message)
{
case kPS2M_getDisableTouchpad:
{
bool* pResult = (bool*)data;
*pResult = !ignoreall;
break;
}
case kPS2M_setDisableTouchpad:
{
bool enable = *((bool*)data);
// ignoreall is true when trackpad has been disabled
if (enable == ignoreall)
{
// save state, and update LED
ignoreall = !enable;
touchpadToggled();
}
break;
}
case kPS2M_notifyKeyPressed:
{
// just remember last time key pressed... this can be used in
// interrupt handler to detect unintended input while typing
PS2KeyInfo* pInfo = (PS2KeyInfo*)data;
static const int masks[] =
{
0x10, // 0x36
0x100000, // 0x37
0, // 0x38
0, // 0x39
0x080000, // 0x3a
0x040000, // 0x3b
0, // 0x3c
0x08, // 0x3d
0x04, // 0x3e
0x200000, // 0x3f
};
#ifdef SIMULATE_PASSTHRU
static int buttons = 0;
int button;
switch (pInfo->adbKeyCode)
{
// make right Alt,Menu,Ctrl into three button passthru
case 0x36:
button = 0x1;
goto dispatch_it;
case 0x3f:
button = 0x4;
goto dispatch_it;
case 0x3e:
button = 0x2;
// fall through...
dispatch_it:
if (pInfo->goingDown)
buttons |= button;
else
buttons &= ~button;
UInt8 packet[6];
packet[0] = 0x84 | trackbuttons;
packet[1] = 0x08 | buttons;
packet[2] = 0;
packet[3] = 0xC4 | trackbuttons;
packet[4] = 0;
packet[5] = 0;
dispatchEventsWithPacket(packet, 6);
pInfo->eatKey = true;
}
#endif
switch (pInfo->adbKeyCode)
{
// don't store key time for modifier keys going down
// track modifiers for scrollzoom feature...
// (note: it turns out we didn't need to do this, but leaving this code in for now in case it is useful)
case 0x38: // left shift
case 0x3c: // right shift
case 0x3b: // left control
case 0x3e: // right control
case 0x3a: // left windows (option)
case 0x3d: // right windows
case 0x37: // left alt (command)
case 0x36: // right alt
case 0x3f: // osx fn (function)