Skip to content

Commit db22ab1

Browse files
authored
Use VoodooInput Trackpoint logic for Elan Touchpads (#60)
1 parent 4e27bd9 commit db22ab1

File tree

4 files changed

+76
-94
lines changed

4 files changed

+76
-94
lines changed

VoodooPS2Trackpad/VoodooPS2Elan.cpp

Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@
3333
// ApplePS2Elan Class Implementation
3434
//
3535

36-
OSDefineMetaClassAndStructors(ApplePS2Elan, IOHIPointing);
37-
38-
UInt32 ApplePS2Elan::deviceType()
39-
{ return NX_EVS_DEVICE_TYPE_MOUSE; };
40-
41-
UInt32 ApplePS2Elan::interfaceID()
42-
{ return NX_EVS_DEVICE_INTERFACE_BUS_ACE; };
36+
OSDefineMetaClassAndStructors(ApplePS2Elan, IOService);
4337

4438
bool ApplePS2Elan::init(OSDictionary *dict) {
4539
// Initialize this object's minimal state. This is invoked right after this
@@ -239,18 +233,6 @@ bool ApplePS2Elan::start(IOService *provider) {
239233
}
240234
#endif
241235

242-
// Advertise the current state of the tapping feature.
243-
//
244-
// Must add this property to let our superclass know that it should handle
245-
// trackpad acceleration settings from user space. Without this, tracking
246-
// speed adjustments from the mouse prefs panel have no effect.
247-
setProperty(kIOHIDPointerAccelerationTypeKey, kIOHIDTrackpadAccelerationType);
248-
setProperty(kIOHIDScrollAccelerationTypeKey, kIOHIDTrackpadScrollAccelerationKey);
249-
setProperty(kIOHIDScrollResolutionKey, _scrollresolution << 16, 32);
250-
// added for Sierra precise scrolling (credit @usr-sse2)
251-
setProperty("HIDScrollResolutionX", _scrollresolution << 16, 32);
252-
setProperty("HIDScrollResolutionY", _scrollresolution << 16, 32);
253-
254236
// Setup workloop with command gate for thread syncronization...
255237
IOWorkLoop *pWorkLoop = getWorkLoop();
256238
_cmdGate = IOCommandGate::commandGate(this);
@@ -340,11 +322,15 @@ void ApplePS2Elan::setParamPropertiesGated(OSDictionary *config) {
340322

341323
const struct {const char *name; int *var;} int32vars[] = {
342324
{"WakeDelay", &wakedelay},
343-
{"ScrollResolution", &_scrollresolution},
325+
{"TrackpointDeadzone", &_trackpointDeadzone},
344326
{"TrackpointMultiplierX", &_trackpointMultiplierX},
345327
{"TrackpointMultiplierY", &_trackpointMultiplierY},
346328
{"TrackpointDividerX", &_trackpointDividerX},
347329
{"TrackpointDividerY", &_trackpointDividerY},
330+
{"TrackpointScrollMultiplierX", &_trackpointScrollMultiplierX},
331+
{"TrackpointScrollMultiplierY", &_trackpointScrollMultiplierY},
332+
{"TrackpointScrollDividerY", &_trackpointScrollDividerX},
333+
{"TrackpointScrollDividerY", &_trackpointScrollDividerY},
348334
{"MouseResolution", &_mouseResolution},
349335
{"MouseSampleRate", &_mouseSampleRate},
350336
{"ForceTouchMode", (int*)&_forceTouchMode},
@@ -412,16 +398,8 @@ void ApplePS2Elan::setParamPropertiesGated(OSDictionary *config) {
412398
if (attachedHIDPointerDevices && attachedHIDPointerDevices->getCount() > 0) {
413399
ignoreall = usb_mouse_stops_trackpad;
414400
}
415-
}
416-
417-
IOReturn ApplePS2Elan::setParamProperties(OSDictionary *dict) {
418-
if (_cmdGate) {
419-
// syncronize through workloop...
420-
//_cmdGate->runAction(OSMemberFunctionCast(IOCommandGate::Action, this, &ApplePS2Elan::setParamPropertiesGated), dict);
421-
setParamPropertiesGated(dict);
422-
}
423-
424-
return super::setParamProperties(dict);
401+
402+
setTrackpointProperties();
425403
}
426404

427405
IOReturn ApplePS2Elan::setProperties(OSObject *props) {
@@ -434,6 +412,28 @@ IOReturn ApplePS2Elan::setProperties(OSObject *props) {
434412
return super::setProperties(props);
435413
}
436414

415+
void ApplePS2Elan::setTrackpointProperties()
416+
{
417+
// Trackpoint information for VoodooInput
418+
OSDictionary *trackpoint = OSDictionary::withCapacity(10);
419+
if (trackpoint == nullptr)
420+
return;
421+
422+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_DEADZONE, _trackpointDeadzone);
423+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_BTN_CNT, 3);
424+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_MOUSE_MULT_X, _trackpointMultiplierX);
425+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_MOUSE_MULT_Y, _trackpointMultiplierY);
426+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_MOUSE_DIV_X, _trackpointDividerX);
427+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_MOUSE_DIV_Y, _trackpointDividerY);
428+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_SCROLL_MULT_X, _trackpointScrollMultiplierX);
429+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_SCROLL_MULT_Y, _trackpointScrollMultiplierY);
430+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_SCROLL_DIV_X, _trackpointScrollDividerX);
431+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_SCROLL_DIV_Y, _trackpointScrollDividerY);
432+
433+
setProperty(VOODOO_TRACKPOINT_KEY, trackpoint);
434+
OSSafeReleaseNULL(trackpoint);
435+
}
436+
437437
IOReturn ApplePS2Elan::message(UInt32 type, IOService* provider, void* argument) {
438438
// Here is where we receive messages from the keyboard driver
439439
//
@@ -1870,19 +1870,6 @@ void ApplePS2Elan::elantechReportTrackpoint() {
18701870
int dx = packet[4] - (int)((packet[1] ^ 0x80) << 1);
18711871
int dy = (int)((packet[2] ^ 0x80) << 1) - packet[5];
18721872

1873-
dx = dx * _trackpointMultiplierX / _trackpointDividerX;
1874-
dy = dy * _trackpointMultiplierY / _trackpointDividerY;
1875-
1876-
// enable trackpoint scroll mode when middle button was pressed and the trackpoint moved
1877-
if (trackpointMiddleButton == 4 && (dx != 0 || dy != 0)) {
1878-
trackpointScrolling = true;
1879-
}
1880-
1881-
// disable trackpoint scrolling mode when middle button is released
1882-
if (trackpointScrolling && trackpointMiddleButton == 0) {
1883-
trackpointScrolling = false;
1884-
}
1885-
18861873
AbsoluteTime timestamp;
18871874
clock_get_uptime(&timestamp);
18881875

@@ -1891,12 +1878,13 @@ void ApplePS2Elan::elantechReportTrackpoint() {
18911878
uint64_t timestamp_ns;
18921879
absolutetime_to_nanoseconds(timestamp, &timestamp_ns);
18931880
keytime = timestamp_ns;
1894-
1895-
if (trackpointScrolling) {
1896-
dispatchScrollWheelEvent(dy, dx, 0, timestamp);
1897-
} else {
1898-
dispatchRelativePointerEvent(dx, dy, trackpointRightButton | trackpointLeftButton | trackpointMiddleButton, timestamp);
1899-
}
1881+
1882+
trackpointReport.timestamp = timestamp;
1883+
trackpointReport.buttons = trackpointLeftButton | trackpointMiddleButton | trackpointRightButton;
1884+
trackpointReport.dx = dx;
1885+
trackpointReport.dy = dy;
1886+
super::messageClient(kIOMessageVoodooTrackpointMessage, voodooInputInstance,
1887+
&trackpointReport, sizeof(trackpointReport));
19001888
}
19011889

19021890
void ApplePS2Elan::processPacketStatusV4() {
@@ -2108,8 +2096,11 @@ void ApplePS2Elan::sendTouchData() {
21082096

21092097
if (!info.is_buttonpad) {
21102098
if (transducers_count == 0) {
2111-
UInt32 buttons = leftButton | rightButton;
2112-
dispatchRelativePointerEvent(0, 0, buttons, timestamp);
2099+
trackpointReport.timestamp = timestamp;
2100+
trackpointReport.buttons = leftButton | rightButton;
2101+
trackpointReport.dx = trackpointReport.dy = 0;
2102+
super::messageClient(kIOMessageVoodooTrackpointMessage, voodooInputInstance,
2103+
&trackpointReport, sizeof(trackpointReport));
21132104
} else {
21142105
UInt32 buttons = 0;
21152106
bool send = false;
@@ -2122,7 +2113,11 @@ void ApplePS2Elan::sendTouchData() {
21222113
send = true;
21232114
}
21242115
if (send) {
2125-
dispatchRelativePointerEvent(0, 0, buttons, timestamp);
2116+
trackpointReport.timestamp = timestamp;
2117+
trackpointReport.buttons = buttons;
2118+
trackpointReport.dx = trackpointReport.dy = 0;
2119+
super::messageClient(kIOMessageVoodooTrackpointMessage, voodooInputInstance,
2120+
&trackpointReport, sizeof(trackpointReport));
21262121
}
21272122
}
21282123

VoodooPS2Trackpad/VoodooPS2Elan.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ struct elantech_data {
209209
// ApplePS2Elan Class Declaration
210210
//
211211

212-
class EXPORT ApplePS2Elan : public IOHIPointing {
213-
typedef IOHIPointing super;
212+
class EXPORT ApplePS2Elan : public IOService {
213+
typedef IOService super;
214214
OSDeclareDefaultStructors(ApplePS2Elan);
215215

216216
private:
@@ -225,6 +225,7 @@ class EXPORT ApplePS2Elan : public IOHIPointing {
225225
IOCommandGate* _cmdGate {nullptr};
226226

227227
VoodooInputEvent inputEvent {};
228+
TrackpointReport trackpointReport {};
228229

229230
// when trackpad has physical button
230231
UInt32 leftButton = 0;
@@ -236,8 +237,6 @@ class EXPORT ApplePS2Elan : public IOHIPointing {
236237
const float cos30deg = 0.86602540378f;
237238
UInt32 lastFingers = 0;
238239

239-
bool trackpointScrolling {false};
240-
241240
int heldFingers = 0;
242241
int headPacketsCount = 0;
243242
elan_virtual_finger_state virtualFinger[ETP_MAX_FINGERS] {};
@@ -246,12 +245,16 @@ class EXPORT ApplePS2Elan : public IOHIPointing {
246245

247246
ForceTouchMode _forceTouchMode {FORCE_TOUCH_BUTTON};
248247

249-
int _scrollresolution {2300};
250248
int wakedelay {1000};
249+
int _trackpointDeadzone {1};
251250
int _trackpointMultiplierX {120};
252251
int _trackpointMultiplierY {120};
253252
int _trackpointDividerX {120};
254253
int _trackpointDividerY {120};
254+
int _trackpointScrollMultiplierX {120};
255+
int _trackpointScrollMultiplierY {120};
256+
int _trackpointScrollDividerX {120};
257+
int _trackpointScrollDividerY {120};
255258

256259
int _mouseResolution {0x3};
257260
int _mouseSampleRate {200};
@@ -285,6 +288,7 @@ class EXPORT ApplePS2Elan : public IOHIPointing {
285288

286289
void setParamPropertiesGated(OSDictionary *dict);
287290
void injectVersionDependentProperties(OSDictionary *dict);
291+
void setTrackpointProperties();
288292

289293
void registerHIDPointerNotifications();
290294
void unregisterHIDPointerNotifications();
@@ -344,10 +348,6 @@ class EXPORT ApplePS2Elan : public IOHIPointing {
344348
bool start(IOService *provider) override;
345349
void stop(IOService *provider) override;
346350

347-
UInt32 deviceType() override;
348-
UInt32 interfaceID() override;
349-
350-
IOReturn setParamProperties(OSDictionary* dict) override;
351351
IOReturn setProperties(OSObject *props) override;
352352

353353
IOReturn message(UInt32 type, IOService* provider, void* argument) override;

VoodooPS2Trackpad/VoodooPS2SynapticsTouchPad.cpp

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,43 +1901,22 @@ IOReturn ApplePS2SynapticsTouchPad::setProperties(OSObject *props)
19011901
void ApplePS2SynapticsTouchPad::setTrackpointProperties()
19021902
{
19031903
// Trackpoint information for VoodooInput
1904-
OSDictionary *trackpoint = OSDictionary::withCapacity(5);
1904+
OSDictionary *trackpoint = OSDictionary::withCapacity(10);
19051905
if (trackpoint == nullptr)
19061906
return;
19071907

1908-
OSNumber *deadzone = OSNumber::withNumber(_deadzone, 32);
1909-
OSNumber *buttonCnt = OSNumber::withNumber(3, 32);
1910-
OSNumber *multX = OSNumber::withNumber(_mouseMultiplierX, 32);
1911-
OSNumber *multY = OSNumber::withNumber(_mouseMultiplierY, 32);
1912-
OSNumber *divX = OSNumber::withNumber(_mouseDivisorX, 32);
1913-
OSNumber *divY = OSNumber::withNumber(_mouseDivisorY, 32);
1914-
OSNumber *scrollMultX = OSNumber::withNumber(_scrollMultiplierX, 32);
1915-
OSNumber *scrollMultY = OSNumber::withNumber(_scrollMultiplierY, 32);
1916-
OSNumber *scrollDivX = OSNumber::withNumber(_scrollDivisorX, 32);
1917-
OSNumber *scrollDivY = OSNumber::withNumber(_scrollDivisorY, 32);
1918-
1919-
trackpoint->setObject(VOODOO_TRACKPOINT_DEADZONE, deadzone);
1920-
trackpoint->setObject(VOODOO_TRACKPOINT_BTN_CNT, buttonCnt);
1921-
trackpoint->setObject(VOODOO_TRACKPOINT_MOUSE_MULT_X, multX);
1922-
trackpoint->setObject(VOODOO_TRACKPOINT_MOUSE_MULT_Y, multY);
1923-
trackpoint->setObject(VOODOO_TRACKPOINT_MOUSE_DIV_X, divX);
1924-
trackpoint->setObject(VOODOO_TRACKPOINT_MOUSE_DIV_Y, divY);
1925-
trackpoint->setObject(VOODOO_TRACKPOINT_SCROLL_MULT_X, scrollMultX);
1926-
trackpoint->setObject(VOODOO_TRACKPOINT_SCROLL_MULT_Y, scrollMultY);
1927-
trackpoint->setObject(VOODOO_TRACKPOINT_SCROLL_DIV_X, scrollDivX);
1928-
trackpoint->setObject(VOODOO_TRACKPOINT_SCROLL_DIV_Y, scrollDivY);
1929-
setProperty(VOODOO_TRACKPOINT_KEY, trackpoint);
1908+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_DEADZONE, _deadzone);
1909+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_BTN_CNT, 3);
1910+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_MOUSE_MULT_X, _mouseMultiplierX);
1911+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_MOUSE_MULT_Y, _mouseMultiplierY);
1912+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_MOUSE_DIV_X, _mouseDivisorX);
1913+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_MOUSE_DIV_Y, _mouseDivisorY);
1914+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_SCROLL_MULT_X, _scrollMultiplierX);
1915+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_SCROLL_MULT_Y, _scrollMultiplierY);
1916+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_SCROLL_DIV_X, _scrollDivisorX);
1917+
PS2DictSetNumber(trackpoint, VOODOO_TRACKPOINT_SCROLL_DIV_Y, _scrollDivisorY);
19301918

1931-
OSSafeReleaseNULL(deadzone);
1932-
OSSafeReleaseNULL(buttonCnt);
1933-
OSSafeReleaseNULL(multX);
1934-
OSSafeReleaseNULL(multY);
1935-
OSSafeReleaseNULL(divX);
1936-
OSSafeReleaseNULL(divY);
1937-
OSSafeReleaseNULL(scrollMultX);
1938-
OSSafeReleaseNULL(scrollMultY);
1939-
OSSafeReleaseNULL(scrollDivX);
1940-
OSSafeReleaseNULL(scrollDivY);
1919+
setProperty(VOODOO_TRACKPOINT_KEY, trackpoint);
19411920
OSSafeReleaseNULL(trackpoint);
19421921
}
19431922

VoodooPS2Trackpad/VoodooPS2TrackpadCommon.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111

1212
#define TEST_BIT(x, y) ((x >> y) & 0x1)
1313

14+
void inline PS2DictSetNumber(OSDictionary *dict, const char *key, unsigned int num) {
15+
OSNumber *val = OSNumber::withNumber(num, 32);
16+
if (val != nullptr) {
17+
dict->setObject(key, val);
18+
val->release();
19+
}
20+
}
21+
1422
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1523
// SimpleAverage Class Declaration
1624
//

0 commit comments

Comments
 (0)