#include "AppleADBMouse.h"
#include <IOKit/hidsystem/IOHIDTypes.h>
#include <IOKit/hidsystem/IOHIDParameter.h>
#include <IOKit/IOLib.h>
#include <IOKit/IOPlatformExpert.h>
static inline int
my_abs(int x)
{
return x < 0 ? -x : x;
}
static bool check_usb_mouse(OSObject *, void *, IOService * );
static void NewMouseData(IOService * target, UInt8 adbCommand, IOByteCount length, UInt8 * data)
{
((AppleADBMouse *)target)->packet(adbCommand, length, data);
}
#undef super
#define super IOHIPointing
OSDefineMetaClassAndStructors(AppleADBMouse, IOHIPointing);
IOService * AppleADBMouse::probe(IOService * provider, SInt32 * score)
{
adbDevice = (IOADBDevice *)provider;
return this;
}
bool AppleADBMouse::start(IOService * provider)
{
if(!super::start(provider)) return false;
if(!adbDevice->seizeForClient(this, NewMouseData)) {
IOLog("%s: Seize failed\n", getName());
return false;
}
return true;
}
UInt32 AppleADBMouse::interfaceID(void)
{
return NX_EVS_DEVICE_INTERFACE_ADB;
}
UInt32 AppleADBMouse::deviceType ( void )
{
return adbDevice->handlerID();
}
IOFixed AppleADBMouse::resolution(void)
{
return _resolution;
}
IOItemCount AppleADBMouse::buttonCount(void)
{
return _buttonCount;
}
void AppleADBMouse::packet(UInt8 ,
IOByteCount , UInt8 * data)
{
int dx, dy;
UInt32 buttonState = 0;
AbsoluteTime now;
dy = data[0] & 0x7f;
dx = data[1] & 0x7f;
if (dy & 0x40) dy |= 0xffffffc0;
if (dx & 0x40) dx |= 0xffffffc0;
if ((data[0] & 0x80) == 0) buttonState |= 1;
clock_get_uptime(&now);
dispatchRelativePointerEvent(dx, dy, buttonState, now);
}
#undef super
#define super AppleADBMouse
OSDefineMetaClassAndStructors(AppleADBMouseType1, AppleADBMouse);
IOService * AppleADBMouseType1::probe(IOService * provider, SInt32 * score)
{
if (!super::probe(provider, score)) return 0;
return this;
}
bool AppleADBMouseType1::start(IOService * provider)
{
OSNumber *dpi;
if (adbDevice->setHandlerID(1) != kIOReturnSuccess) return false;
dpi = OSDynamicCast( OSNumber, getProperty("dpi"));
if (dpi)
{
_resolution = dpi->unsigned16BitValue() << 16;
}
else
{
_resolution = 100 << 16;
}
_buttonCount = 1;
return super::start(provider);
}
#undef super
#define super AppleADBMouse
OSDefineMetaClassAndStructors(AppleADBMouseType2, AppleADBMouse);
IOService * AppleADBMouseType2::probe(IOService * provider, SInt32 * score)
{
if (!super::probe(provider, score)) return 0;
if (adbDevice->setHandlerID(2) != kIOReturnSuccess) return 0;
return this;
}
bool AppleADBMouseType2::start(IOService * provider)
{
OSNumber *dpi;
if (adbDevice->setHandlerID(2) != kIOReturnSuccess) return false;
dpi = OSDynamicCast( OSNumber, getProperty("dpi"));
if (dpi)
{
_resolution = dpi->unsigned16BitValue() << 16;
}
else
{
_resolution = 200 << 16;
}
_buttonCount = 1;
return super::start(provider);
}
#undef super
#define super AppleADBMouse
OSDefineMetaClassAndStructors(AppleADBMouseType4, AppleADBMouse);
IOService * AppleADBMouseType4::probe(IOService * provider, SInt32 * score)
{
UInt8 data[8];
IOByteCount length = 8;
if (!super::probe(provider, score)) return 0;
if (adbDevice->setHandlerID(4) != kIOReturnSuccess) {
adbDevice->setHandlerID(adbDevice->defaultHandlerID());
return 0;
}
if (adbDevice->readRegister(1, data, &length) != kIOReturnSuccess) return 0;
if (length != 8) return 0;
deviceSignature = ((UInt32 *)data)[0];
deviceResolution = ((UInt16 *)data)[2];
deviceClass = data[6];
deviceNumButtons = data[7];
return this;
}
bool AppleADBMouseType4::start(IOService * provider)
{
UInt8 adbdata[8];
IOByteCount adblength = 8;
OSNumber *dpi;
typeTrackpad = FALSE;
if (adbDevice->setHandlerID(4) != kIOReturnSuccess) return false;
dpi = OSDynamicCast( OSNumber, getProperty("dpi"));
if (dpi)
{
_resolution = dpi->unsigned16BitValue() << 16;
}
else
{
_resolution = deviceResolution << 16;
}
_buttonCount = deviceNumButtons;
_notifierA = _notifierT = NULL; _gettime = OSSymbol::withCString("get_last_keydown");
_mouseLock = IOLockAlloc();
adbDevice->readRegister(1, adbdata, &adblength);
if( (adbdata[0] == 't') && (adbdata[1] = 'p') && (adbdata[2] == 'a') && (adbdata[3] == 'd') )
{
mach_timespec_t t;
OSNumber *jitter_num;
t.tv_sec = 1; t.tv_nsec = 0;
typeTrackpad = TRUE;
enableEnhancedMode();
_pADBKeyboard = waitForService(serviceMatching("AppleADBKeyboard"), &t);
jitter_num = OSDynamicCast( OSNumber, getProperty("Trackpad Jitter Milliseconds"));
if (jitter_num)
{
_jitterclicktime64 = jitter_num->unsigned16BitValue() * 1000 * 1000; nanoseconds_to_absolutetime( _jitterclicktime64, &_jitterclicktimeAB);
}
else
{
_jitterclicktime64 = 750 * 1000 * 1000; nanoseconds_to_absolutetime( _jitterclicktime64, &_jitterclicktimeAB);
}
jitter_num = OSDynamicCast( OSNumber, getProperty("Trackpad Jitter Max delta"));
if (jitter_num)
{
_jitterdelta = jitter_num->unsigned16BitValue();
if (_jitterdelta == 0)
_jittermove = false;
}
else
{
_jitterdelta = 16; }
setProperty(kIOHIDPointerAccelerationTypeKey, kIOHIDTrackpadAccelerationType);
if (_buttonCount == 4)
{
_buttonCount = 2; setProperty("W Enhanced Trackpad", (unsigned long long)true, sizeof(Clicking)*8);
_isWEnhanced = true;
_usePantherSettings = false;
_jitterclick = _jittermove; }
else
{
_isWEnhanced = false;
}
}
return super::start(provider);
}
void AppleADBMouseType4::free( void )
{
if (_notifierA)
{
_notifierA->remove();
_notifierA = NULL;
}
if (_notifierT)
{
_notifierT->remove();
_notifierT = NULL;
}
_ignoreTrackpad = false;
_sticky2finger = false;
_zonepeckingtimeAB = _keyboardTimeAB;
if (_gettime)
_gettime->release();
if (_mouseLock)
{
IOLock * lock;
IOLockLock(_mouseLock);
lock = _mouseLock;
_mouseLock = NULL;
IOLockUnlock(lock);
IOLockFree(lock);
}
super::free();
}
bool check_usb_mouse(OSObject * us, void *, IOService * yourDevice)
{
if (us)
{
((AppleADBMouseType4 *)us)->_check_usb_mouse();
}
return true;
}
void AppleADBMouseType4::_check_usb_mouse( void )
{
IOService *pHIDDevice;
bool foundUSBHIDMouse = false;
OSIterator *iterator = NULL;
OSDictionary *dict = NULL;
OSNumber *usbClass, *usbPage, *usbUsage;
dict = IOService::serviceMatching( "IOUSBHIDDriver" );
if( dict )
{
iterator = IOService::getMatchingServices( dict );
if( iterator )
{
while( (pHIDDevice = (IOHIDDevice *) iterator->getNextObject()) )
{
usbClass = OSDynamicCast( OSNumber, pHIDDevice->getProperty("bInterfaceClass"));
usbPage = OSDynamicCast( OSNumber, pHIDDevice->getProperty("PrimaryUsagePage"));
usbUsage = OSDynamicCast( OSNumber, pHIDDevice->getProperty("PrimaryUsage"));
if ((usbClass == NULL) || (usbPage == NULL) || (usbUsage == NULL) )
{
IOLog("Null found for properties that should exist in IOUSBHIDDriver\n");
continue;
}
if ((usbClass->unsigned16BitValue() == 3) && (usbUsage->unsigned16BitValue() == 2)
&& (usbPage->unsigned16BitValue() == 1))
{
_ignoreTrackpad = true;
foundUSBHIDMouse = true;
break;
}
}
}
if( dict ) dict->release();
if( iterator ) iterator->release();
}
if (!foundUSBHIDMouse)
{
_ignoreTrackpad = false;
}
}
void AppleADBMouseType4::packet(UInt8 , IOByteCount length, UInt8 * data)
{
int dx, dy, cnt, numExtraBytes;
UInt32 buttonState = 0;
AbsoluteTime now;
if (_notifierA && _notifierT)
{
if (typeTrackpad && _ignoreTrackpad)
return;
}
if(_isWEnhanced) {
packetW(0, length, data);
return;
}
numExtraBytes = length - 2;
dy = data[0] & 0x7f;
dx = data[1] & 0x7f;
if ((data[0] & 0x80) == 0)
{
buttonState |= 1;
}
if ((deviceNumButtons > 1) && ((data[1] & 0x80) == 0))
{
if(typeTrackpad)
{
if ((_jitterclick) && (_pADBKeyboard))
{
AbsoluteTime keyboardtime;
UInt64 nowtime64, keytime64;
keyboardtime.hi = 0;
keyboardtime.lo = 0;
_pADBKeyboard->callPlatformFunction(_gettime, false,
(void *)&keyboardtime, 0, 0, 0);
clock_get_uptime(&now);
absolutetime_to_nanoseconds(now, &nowtime64);
absolutetime_to_nanoseconds(keyboardtime, &keytime64);
if (nowtime64 - keytime64 > _jitterclicktime64)
{
buttonState |= 1;
}
}
else
buttonState |= 1;
}
else
{
buttonState |= 2;
}
}
for (cnt = 0; cnt < numExtraBytes; cnt++) {
dy |= ((data[2 + cnt] >> 4) & 7) << (7 + (cnt * 3));
dx |= ((data[2 + cnt]) & 7) << (7 + (cnt * 3));
if ((deviceNumButtons > (cnt + 2)) && ((data[2 + cnt] & 0x80) == 0))
buttonState |= 4 << (cnt * 2);
if ((deviceNumButtons > (cnt + 2 + 1)) && ((data[2 + cnt] & 0x08) == 0))
buttonState |= 4 << (cnt * 2 + 1);
}
if (dy & (0x40 << (numExtraBytes * 3)))
dy |= (0xffffffc0 << (numExtraBytes * 3));
if (dx & (0x40 << (numExtraBytes * 3)))
dx |= (0xffffffc0 << (numExtraBytes * 3));
clock_get_uptime(&now);
if(typeTrackpad)
{
if (_jittermove)
{
if (_pADBKeyboard)
{
AbsoluteTime keyboardtime;
UInt64 nowtime64, keytime64;
keyboardtime.hi = 0;
keyboardtime.lo = 0;
_pADBKeyboard->callPlatformFunction(_gettime, false, (void *)&keyboardtime, 0, 0, 0);
absolutetime_to_nanoseconds(now, &nowtime64);
absolutetime_to_nanoseconds(keyboardtime, &keytime64);
if (nowtime64 - keytime64 < _jitterclicktime64)
{
if ((my_abs(dx) < _jitterdelta) && (my_abs(dy) < _jitterdelta))
{
if (!buttonState)
{
return;
}
else
{
dx = 0;
dy = 0;
}
}
}
}
} }
dispatchRelativePointerEvent(dx, dy, buttonState, now);
}
void AppleADBMouseType4::packetW(UInt8 , IOByteCount length, UInt8 * data)
{
int dx, dy, cnt, numExtraBytes;
bool palm = false, outzone = false, has2fingers = false;
UInt32 buttonState = 0;
AbsoluteTime now;
if (_usePantherSettings)
{
packetWP(0, length, data);
return;
}
numExtraBytes = length - 2;
dy = data[0] & 0x7f;
dx = data[1] & 0x7f;
if ((data[0] & 0x80) == 0)
{
buttonState |= 1;
}
{
if ((data[2] & 0x80) == 0)
{
if (_zonenomove)
outzone = true;
}
if ((data[2] & 0x08) == 0)
{
if (_palmnomove)
palm = true;
}
if ((data[3] & 0x80) == 0)
{
if (_2fingernoaction)
{
has2fingers = true;
_sticky2finger = true;
clock_get_uptime(&_sticky2fingerTimeAB);
}
}
if ((data[3] & 0x08) != 0)
{
_sticky2finger = false;
}
if (_sticky2finger)
{
AbsoluteTime nowtimeAB;
clock_get_uptime(&nowtimeAB);
SUB_ABSOLUTETIME(&nowtimeAB, &_sticky2fingerTimeAB);
if ( CMP_ABSOLUTETIME(&nowtimeAB, &_timeoutStickyAB) == -1)
{
has2fingers = true;
}
else
{
_sticky2finger = false; }
}
data[2] |= 0x88; data[3] |= 0x88; }
if ((deviceNumButtons > 1) && ((data[1] & 0x80) == 0))
{
{
if ((_jitterclick) && (_pADBKeyboard))
{
_keyboardTimeAB.hi = 0;
_keyboardTimeAB.lo = 0;
_pADBKeyboard->callPlatformFunction(_gettime, false,
(void *)&_keyboardTimeAB, 0, 0, 0);
clock_get_uptime(&now);
SUB_ABSOLUTETIME(&now, &_keyboardTimeAB);
if ( CMP_ABSOLUTETIME(&now, &_jitterclicktimeAB) == 1)
{
buttonState |= 1;
}
if ( !outzone)
{
buttonState |= 1; }
if (CMP_ABSOLUTETIME( &_zonepeckingtimeAB, &_keyboardTimeAB) != 0)
{
buttonState = 0;
}
}
else
buttonState |= 1;
}
}
for (cnt = 0; cnt < numExtraBytes; cnt++) {
dy |= ((data[2 + cnt] >> 4) & 7) << (7 + (cnt * 3));
dx |= ((data[2 + cnt]) & 7) << (7 + (cnt * 3));
if ((deviceNumButtons > (cnt + 2)) && ((data[2 + cnt] & 0x80) == 0))
buttonState |= 4 << (cnt * 2);
if ((deviceNumButtons > (cnt + 2 + 1)) && ((data[2 + cnt] & 0x08) == 0))
buttonState |= 4 << (cnt * 2 + 1);
}
if (dy & (0x40 << (numExtraBytes * 3)))
dy |= (0xffffffc0 << (numExtraBytes * 3));
if (dx & (0x40 << (numExtraBytes * 3)))
dx |= (0xffffffc0 << (numExtraBytes * 3));
clock_get_uptime(&now);
if (_jittermove)
{
if ((has2fingers) || (outzone && palm))
{
if (!buttonState)
{
return;
}
else if ((data[1] & 0x80) == 0) {
return;
}
else
{
dx = 0;
dy = 0;
}
}
if (( !outzone) && (_pADBKeyboard))
{
_keyboardTimeAB.hi = 0;
_keyboardTimeAB.lo = 0;
_pADBKeyboard->callPlatformFunction(_gettime, false, (void *)&_zonepeckingtimeAB, 0, 0, 0);
} else
if (_pADBKeyboard)
{
_keyboardTimeAB.hi = 0;
_keyboardTimeAB.lo = 0;
_pADBKeyboard->callPlatformFunction(_gettime, false, (void *)&_keyboardTimeAB, 0, 0, 0);
nanoseconds_to_absolutetime( (unsigned long long)( (unsigned long long)(5 * 60 * 1000) * (unsigned long long)(1000 * 1000) ), &_fake5minAB);
SUB_ABSOLUTETIME(&now, &_keyboardTimeAB);
if (CMP_ABSOLUTETIME (&now, &_fake5minAB) == -1)
{
if ( CMP_ABSOLUTETIME ( &_zonepeckingtimeAB, &_keyboardTimeAB) != 0)
{
if (!buttonState)
{
return;
}
else if ((data[1] & 0x80) == 0)
{
return;
}
else
{
dx = 0;
dy = 0;
}
}
}
}
}
dispatchRelativePointerEvent(dx, dy, buttonState, now);
}
void AppleADBMouseType4::packetWP(UInt8 , IOByteCount length, UInt8 * data)
{
int dx, dy, cnt, numExtraBytes;
bool palm = false, outzone = false, has2fingers = false;
UInt32 buttonState = 0;
AbsoluteTime now;
numExtraBytes = length - 2;
dy = data[0] & 0x7f;
dx = data[1] & 0x7f;
if ((data[0] & 0x80) == 0)
{
buttonState |= 1;
}
{
if ((data[2] & 0x80) == 0)
{
outzone = true;
}
if ((data[2] & 0x08) == 0)
{
palm = true;
}
if ((data[3] & 0x80) == 0)
{
if (_2fingernoaction)
{
has2fingers = true;
_sticky2finger = true;
clock_get_uptime(&now);
absolutetime_to_nanoseconds(now, &_sticky2fingerTime64);
}
}
if ((data[3] & 0x08) != 0)
{
_sticky2finger = false;
}
if (_sticky2finger)
{
UInt64 nowtime64;
clock_get_uptime(&now);
absolutetime_to_nanoseconds(now, &nowtime64);
if (nowtime64 - _sticky2fingerTime64 < _timeoutSticky64)
{
palm = true;
}
else
{
_sticky2finger = false; }
}
data[2] |= 0x88; data[3] |= 0x88; }
if ((deviceNumButtons > 1) && ((data[1] & 0x80) == 0))
{
{
if ((_jitterclick) && (_pADBKeyboard))
{
AbsoluteTime keyboardtime;
UInt64 nowtime64, keytime64;
keyboardtime.hi = 0;
keyboardtime.lo = 0;
_pADBKeyboard->callPlatformFunction(_gettime, false,
(void *)&keyboardtime, 0, 0, 0);
clock_get_uptime(&now);
absolutetime_to_nanoseconds(now, &nowtime64);
absolutetime_to_nanoseconds(keyboardtime, &keytime64);
if (nowtime64 - keytime64 > _jitterclicktime64)
{
buttonState |= 1;
}
}
else
buttonState |= 1;
}
}
for (cnt = 0; cnt < numExtraBytes; cnt++) {
dy |= ((data[2 + cnt] >> 4) & 7) << (7 + (cnt * 3));
dx |= ((data[2 + cnt]) & 7) << (7 + (cnt * 3));
if ((deviceNumButtons > (cnt + 2)) && ((data[2 + cnt] & 0x80) == 0))
buttonState |= 4 << (cnt * 2);
if ((deviceNumButtons > (cnt + 2 + 1)) && ((data[2 + cnt] & 0x08) == 0))
buttonState |= 4 << (cnt * 2 + 1);
}
if (dy & (0x40 << (numExtraBytes * 3)))
dy |= (0xffffffc0 << (numExtraBytes * 3));
if (dx & (0x40 << (numExtraBytes * 3)))
dx |= (0xffffffc0 << (numExtraBytes * 3));
clock_get_uptime(&now);
if(typeTrackpad )
{
if ((_2fingernoaction && has2fingers) || (_palmnoaction && palm) ||
(_zonenoaction && outzone))
{
if (!buttonState)
{
return;
}
else
{
dx = 0;
dy = 0;
}
}
if (_jittermove)
{
if (_pADBKeyboard)
{
AbsoluteTime keyboardtime;
UInt64 nowtime64, keytime64;
keyboardtime.hi = 0;
keyboardtime.lo = 0;
_pADBKeyboard->callPlatformFunction(_gettime, false, (void *)&keyboardtime, 0, 0, 0);
absolutetime_to_nanoseconds(now, &nowtime64);
absolutetime_to_nanoseconds(keyboardtime, &keytime64);
if (nowtime64 - keytime64 < _jitterclicktime64)
{
if ((my_abs(dx) < _jitterdelta) && (my_abs(dy) < _jitterdelta))
{
if (!buttonState)
{
return;
}
else
{
dx = 0;
dy = 0;
}
}
}
}
}
if (_zonenomove)
{
if (_pADBKeyboard)
{
AbsoluteTime keyboardtime;
UInt64 nowtime64, keytime64;
keyboardtime.hi = 0;
keyboardtime.lo = 0;
_pADBKeyboard->callPlatformFunction(_gettime, false, (void *)&keyboardtime, 0, 0, 0);
absolutetime_to_nanoseconds(now, &nowtime64);
absolutetime_to_nanoseconds(keyboardtime, &keytime64);
if (nowtime64 - keytime64 < _jitterclicktime64)
{
if (_palmnomove && palm)
{
return;
}
if (outzone)
{
if (!_ignorezone)
{
if (!buttonState)
{
return;
}
else if ((data[1] & 0x80) == 0) {
return;
}
else
{
dx = 0;
dy = 0;
}
}
}
else
{
_ignorezone = true;
}
}
else {
_ignorezone = false;
}
}
}
if (_zonepecknomove)
{
if (_pADBKeyboard)
{
AbsoluteTime keyboardtime;
UInt64 keytime64;
keyboardtime.hi = 0;
keyboardtime.lo = 0;
_pADBKeyboard->callPlatformFunction(_gettime, false, (void *)&keyboardtime, 0, 0, 0);
absolutetime_to_nanoseconds(keyboardtime, &keytime64);
if (outzone)
{
if (_zonepeckingtime64 != keytime64)
{
if (!buttonState)
{
return;
}
else if ((data[1] & 0x80) == 0) {
return;
}
else
{
dx = 0;
dy = 0;
}
}
}
else
{
_zonepeckingtime64 = keytime64;
}
}
}
}
dispatchRelativePointerEvent(dx, dy, buttonState, now);
}
OSData * AppleADBMouseType4::copyAccelerationTable()
{
char keyName[10];
strcpy( keyName, "accl" );
keyName[4] = (deviceSignature >> 24);
keyName[5] = (deviceSignature >> 16);
keyName[6] = (deviceSignature >> 8);
keyName[7] = (deviceSignature >> 0);
keyName[8] = 0;
IOLockLock( _mouseLock);
OSData * data = OSDynamicCast( OSData,
getProperty( keyName ));
IOLockUnlock( _mouseLock);
if( data)
{
data->retain();
}
else
{
data = super::copyAccelerationTable();
}
return( data );
}
bool AppleADBMouseType4::enableEnhancedMode()
{
UInt8 adbdata[8];
IOByteCount adblength = 8;
OSNumber *plistnum;
adbDevice->readRegister(1, adbdata, &adblength);
if((adbdata[6] != 0x0D))
{
adbdata[6] = 0xD;
if (adbDevice->writeRegister(1, adbdata, &adblength) != 0)
return FALSE;
if (adbDevice->readRegister(1, adbdata, &adblength) != 0)
return FALSE;
if (adbdata[6] != 0x0D)
{
IOLog("AppleADBMouseType4 deviceClass = %d (non-Extended Mode)\n", adbdata[6]);
return FALSE;
}
adbdata[0] = 0x19; adbdata[1] = 0x14;
adbdata[2] = 0x19;
adbdata[3] = 0xB2; adbdata[4] = 0xB2;
adbdata[5] = 0x8A;
adbdata[6] = 0x1B;
adbdata[7] = 0x57; adblength = 8;
adbDevice->writeRegister(2, adbdata, &adblength);
Clicking = FALSE;
Dragging = FALSE;
DragLock = FALSE;
setProperty("Clicking", (unsigned long long)Clicking, sizeof(Clicking)*8);
setProperty("Dragging", (unsigned long long)Dragging, sizeof(Dragging)*8);
setProperty("DragLock", (unsigned long long)DragLock, sizeof(DragLock)*8);
plistnum = OSDynamicCast( OSNumber, getProperty("JitterNoClick"));
if (plistnum)
{
_jitterclick = (bool) plistnum->unsigned16BitValue();
}
else
{
_jitterclick = false;
}
plistnum = OSDynamicCast( OSNumber, getProperty("JitterNoMove"));
if (plistnum)
{
_jittermove = (bool) plistnum->unsigned16BitValue();
}
else
{
_jittermove = false;
}
if (_isWEnhanced) {
setProperty("JitterNoClick", true, sizeof(UInt32));
setProperty("JitterNoMove", true, sizeof(UInt32));
_jitterclick = _jittermove = true;
}
plistnum = OSDynamicCast( OSNumber, getProperty("W sticky input timeout"));
if (plistnum)
{
_timeoutSticky64 = plistnum->unsigned32BitValue() * 1000 * 1000; nanoseconds_to_absolutetime(_timeoutSticky64, &_timeoutStickyAB);
}
else
{
_timeoutSticky64 = 500 * 1000 * 1000; nanoseconds_to_absolutetime(_timeoutSticky64, &_timeoutStickyAB);
}
plistnum = OSDynamicCast( OSNumber, getProperty("W threshold"));
if (plistnum)
{
_WThreshold = (UInt8) plistnum->unsigned16BitValue();
}
else
{
_WThreshold = 7; }
plistnum = OSDynamicCast( OSNumber, getProperty("TwofingerNoAction"));
if (plistnum)
{
_2fingernoaction = (bool) plistnum->unsigned16BitValue();
}
else
{
_2fingernoaction = false;
}
plistnum = OSDynamicCast( OSNumber, getProperty("PalmNoAction Permanent"));
if (plistnum)
{
_palmnoaction = (bool) plistnum->unsigned16BitValue();
}
else
{
_palmnoaction = false;
}
plistnum = OSDynamicCast( OSNumber, getProperty("PalmNoAction When Typing"));
if (plistnum)
{
_palmnomove = (bool) plistnum->unsigned16BitValue();
}
else
{
_palmnomove = false;
}
plistnum = OSDynamicCast( OSNumber, getProperty("OutsidezoneNoAction Permanent"));
if (plistnum)
{
_zonenoaction = (bool) plistnum->unsigned16BitValue();
}
else
{
_zonenoaction = false;
}
plistnum = OSDynamicCast( OSNumber, getProperty("OutsidezoneNoAction When Typing"));
if (plistnum)
{
_zonenomove = (bool) plistnum->unsigned16BitValue();
}
else
{
_zonenomove = false;
}
plistnum = OSDynamicCast( OSNumber, getProperty("OutsidezoneNoAction When Pecking"));
if (plistnum)
{
_zonepecknomove = (bool) plistnum->unsigned16BitValue();
}
else
{
_zonepecknomove = false;
}
_ignorezone = false;
_zonepeckingtime64 = 0;
nanoseconds_to_absolutetime(0, &_zonepeckingtimeAB);
return TRUE;
}
return FALSE;
}
IOReturn AppleADBMouseType4::setParamProperties( OSDictionary * dict )
{
OSData * data;
OSNumber *datan;
IOReturn err = kIOReturnSuccess;
UInt8 adbdata[8];
IOByteCount adblength;
if (typeTrackpad == TRUE)
{
IOLockLock( _mouseLock);
if (data = OSDynamicCast(OSData, dict->getObject("Clicking")))
{
adblength = sizeof(adbdata);
adbDevice->readRegister(2, adbdata, &adblength);
adbdata[0] = (adbdata[0] & 0x7F) | (*( (UInt8 *) data->getBytesNoCopy() ))<<7;
setProperty("Clicking", (unsigned long long)((adbdata[0]&0x80)>>7), sizeof(adbdata[0])*8);
adbDevice->writeRegister(2, adbdata, &adblength);
}
if (data = OSDynamicCast(OSData, dict->getObject("Dragging")))
{
adblength = sizeof(adbdata);
adbDevice->readRegister(2, adbdata, &adblength);
adbdata[1] = (adbdata[1] & 0x7F) | (*( (UInt8 *) data->getBytesNoCopy() ))<<7;
setProperty("Dragging", (unsigned long long)((adbdata[1]&0x80)>>7), sizeof(adbdata[1])*8);
adbDevice->writeRegister(2, adbdata, &adblength);
}
if (data = OSDynamicCast(OSData, dict->getObject("DragLock")))
{
adblength = sizeof(adbdata);
adbDevice->readRegister(2, adbdata, &adblength);
adbdata[3] = *((UInt8 *) data->getBytesNoCopy());
if(adbdata[3])
{
setProperty("DragLock", (unsigned long long)adbdata[3], sizeof(adbdata[3])*8);
adbdata[3] = 0xFF;
adblength = sizeof(adbdata);
adbDevice->writeRegister(2, adbdata, &adblength);
}
else
{
setProperty("DragLock", (unsigned long long)adbdata[3], sizeof(adbdata[3])*8);
adbdata[3] = 0xB2;
adblength = sizeof(adbdata);
adbDevice->writeRegister(2, adbdata, &adblength);
}
}
if (datan = OSDynamicCast(OSNumber, dict->getObject("JitterNoClick")))
{
_jitterclick = (bool) datan->unsigned32BitValue();
setProperty("JitterNoClick", _jitterclick, sizeof(UInt32));
}
if (datan = OSDynamicCast(OSNumber, dict->getObject("JitterNoMove")))
{
_jittermove = (bool) datan->unsigned32BitValue();
setProperty("JitterNoMove", _jittermove, sizeof(UInt32));
_jitterclick = _jittermove;
}
if (datan = OSDynamicCast(OSNumber, dict->getObject("Trackpad Jitter Milliseconds")))
{
_jitterclicktime64 = datan->unsigned32BitValue() * 1000 * 1000; setProperty("Trackpad Jitter Milliseconds", datan->unsigned32BitValue(),
8 * sizeof(adbdata[1]));
nanoseconds_to_absolutetime (_jitterclicktime64, &_jitterclicktimeAB);
}
if (datan = OSDynamicCast(OSNumber, dict->getObject("W sticky input timeout")))
{
_timeoutSticky64 = datan->unsigned32BitValue() * 1000 * 1000; setProperty("W sticky input timeout", datan->unsigned32BitValue(),
8 * sizeof(adbdata[1]));
nanoseconds_to_absolutetime(_timeoutSticky64, &_timeoutStickyAB);
}
if (datan = OSDynamicCast(OSNumber, dict->getObject("W threshold")))
{
_WThreshold = (UInt8) datan->unsigned32BitValue();
_WThreshold &= 0xf; setProperty("W threshold", _WThreshold, sizeof((adbdata[2]) * 8));
adblength = sizeof(adbdata);
adbDevice->readRegister(2, adbdata, &adblength);
adbdata[7] = adbdata[7] & 0xf0; adbdata[7] = adbdata[7] | _WThreshold;
adblength = sizeof(adbdata);
adbDevice->writeRegister(2, adbdata, &adblength);
#if 0
adblength = sizeof(adbdata);
adbDevice->readRegister(1, adbdata, &adblength);
if((adbdata[6] != 0x0D))
{
IOLog("Gestures are not in mode 0x0D\n");
}
adblength = sizeof(adbdata);
adbdata[7] = 0; adbDevice->readRegister(2, adbdata, &adblength);
#endif
}
if (datan = OSDynamicCast(OSNumber, dict->getObject("Use Panther Settings for W")))
{
_usePantherSettings = (bool) datan->unsigned32BitValue();
setProperty("Use Panther Settings for W", _usePantherSettings, sizeof(UInt32));
}
if (datan = OSDynamicCast(OSNumber, dict->getObject("PalmNoAction Permanent")))
{
_palmnoaction = (bool) datan->unsigned32BitValue();
setProperty("PalmNoAction Permanent", _palmnoaction, sizeof(UInt32));
}
if (datan = OSDynamicCast(OSNumber, dict->getObject("PalmNoAction When Typing")))
{
_palmnomove = (bool) datan->unsigned32BitValue();
setProperty("PalmNoAction When Typing", _palmnomove, sizeof(UInt32));
}
if (datan = OSDynamicCast(OSNumber, dict->getObject("TwofingerNoAction")))
{
_2fingernoaction = (bool) datan->unsigned32BitValue();
setProperty("TwofingerNoAction", _2fingernoaction, sizeof(UInt32));
}
if (datan = OSDynamicCast(OSNumber, dict->getObject("OutsidezoneNoAction Permanent")))
{
_zonenoaction = (bool) datan->unsigned32BitValue();
setProperty("OutsidezoneNoAction Permanent", _zonenoaction, sizeof(UInt32));
}
if (datan = OSDynamicCast(OSNumber, dict->getObject("OutsidezoneNoAction When Typing")))
{
_zonenomove = (bool) datan->unsigned32BitValue();
setProperty("OutsidezoneNoAction When Typing", _zonenomove, sizeof(UInt32));
}
if (datan = OSDynamicCast(OSNumber, dict->getObject("OutsidezoneNoAction When Pecking")))
{
_zonepecknomove = (bool) datan->unsigned32BitValue();
setProperty("OutsidezoneNoAction When Pecking", _zonepecknomove, sizeof(UInt32));
}
if (datan = OSDynamicCast(OSNumber, dict->getObject("USBMouseStopsTrackpad")))
{
UInt8 mode;
mode = datan->unsigned32BitValue();
setProperty("USBMouseStopsTrackpad", (unsigned long long)(mode), sizeof(mode)*8);
if (mode)
{
if ( ! _notifierA)
_notifierA = addNotification( gIOFirstMatchNotification, serviceMatching( "IOUSBHIDDriver" ),
(IOServiceNotificationHandler)check_usb_mouse, this, 0 );
if (! _notifierT)
_notifierT = addNotification( gIOTerminatedNotification, serviceMatching( "IOUSBHIDDriver" ),
(IOServiceNotificationHandler)check_usb_mouse, this, 0 );
}
else
{
if (_notifierA)
{
_notifierA->remove();
_notifierA = NULL;
}
if (_notifierT)
{
_notifierT->remove();
_notifierT = NULL;
}
_ignoreTrackpad = false;
}
}
IOLockUnlock( _mouseLock);
} #if 0
adblength = 8;
adbDevice->readRegister(2, adbdata, &adblength);
IOLog("adbdata[0] = 0x%x\n", adbdata[0]);
IOLog("adbdata[1] = 0x%x\n", adbdata[1]);
IOLog("adbdata[2] = 0x%x\n", adbdata[2]);
IOLog("adbdata[3] = 0x%x\n", adbdata[3]);
IOLog("adbdata[4] = 0x%x\n", adbdata[4]);
IOLog("adbdata[5] = 0x%x\n", adbdata[5]);
IOLog("adbdata[6] = 0x%x\n", adbdata[6]);
IOLog("adbdata[7] = 0x%x\n", adbdata[7]);
#endif
if (err == kIOReturnSuccess)
{
return super::setParamProperties(dict);
}
IOLog("AppleADBMouseType4::setParamProperties failing here\n");
return( err );
}