From c6f297714669af2701bf8aeaec463829cd50c0bb Mon Sep 17 00:00:00 2001 From: Michael Belyaev Date: Fri, 4 Dec 2020 10:47:45 +0300 Subject: [PATCH] Add trackpoint device from VoodooTrackpoint --- VoodooInput.xcodeproj/project.pbxproj | 16 +++++ VoodooInput/Trackpoint/TrackpointDevice.cpp | 54 +++++++++++++++ VoodooInput/Trackpoint/TrackpointDevice.hpp | 35 ++++++++++ VoodooInput/VoodooInput.cpp | 68 +++++++++++++++---- VoodooInput/VoodooInput.hpp | 2 + .../VoodooInputMultitouch/VoodooInputEvent.h | 15 ++++ .../VoodooInputMessages.h | 3 + 7 files changed, 179 insertions(+), 14 deletions(-) create mode 100644 VoodooInput/Trackpoint/TrackpointDevice.cpp create mode 100644 VoodooInput/Trackpoint/TrackpointDevice.hpp diff --git a/VoodooInput.xcodeproj/project.pbxproj b/VoodooInput.xcodeproj/project.pbxproj index 075fc5e..6ce3b1f 100644 --- a/VoodooInput.xcodeproj/project.pbxproj +++ b/VoodooInput.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 358914F425798FA5007A0B58 /* TrackpointDevice.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 358914F225798FA5007A0B58 /* TrackpointDevice.hpp */; }; + 358914F525798FA5007A0B58 /* TrackpointDevice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 358914F325798FA5007A0B58 /* TrackpointDevice.cpp */; }; 7BBAB1FD22E3A2F800B2941A /* VoodooInput.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 7BBAB1FC22E3A2F800B2941A /* VoodooInput.hpp */; }; 7BBAB1FF22E3A2F800B2941A /* VoodooInput.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7BBAB1FE22E3A2F800B2941A /* VoodooInput.cpp */; }; 7BBAB21722E3AD0E00B2941A /* VoodooInputSimulatorDevice.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 7BBAB21122E3AD0D00B2941A /* VoodooInputSimulatorDevice.hpp */; }; @@ -17,6 +19,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 358914F225798FA5007A0B58 /* TrackpointDevice.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = TrackpointDevice.hpp; sourceTree = ""; }; + 358914F325798FA5007A0B58 /* TrackpointDevice.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TrackpointDevice.cpp; sourceTree = ""; }; 7BBAB1F922E3A2F800B2941A /* VoodooInput.kext */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = VoodooInput.kext; sourceTree = BUILT_PRODUCTS_DIR; }; 7BBAB1FC22E3A2F800B2941A /* VoodooInput.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = VoodooInput.hpp; sourceTree = ""; }; 7BBAB1FE22E3A2F800B2941A /* VoodooInput.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = VoodooInput.cpp; sourceTree = ""; }; @@ -47,6 +51,15 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 358914F125798FA5007A0B58 /* Trackpoint */ = { + isa = PBXGroup; + children = ( + 358914F225798FA5007A0B58 /* TrackpointDevice.hpp */, + 358914F325798FA5007A0B58 /* TrackpointDevice.cpp */, + ); + path = Trackpoint; + sourceTree = ""; + }; 7BBAB1EF22E3A2F800B2941A = { isa = PBXGroup; children = ( @@ -69,6 +82,7 @@ 7BBAB1FB22E3A2F800B2941A /* VoodooInput */ = { isa = PBXGroup; children = ( + 358914F125798FA5007A0B58 /* Trackpoint */, CEC086442439FD3E00F5B701 /* VoodooInputMultitouch */, 7BBAB20F22E3AC7E00B2941A /* VoodooInputSimulator */, 7BBAB1FC22E3A2F800B2941A /* VoodooInput.hpp */, @@ -127,6 +141,7 @@ buildActionMask = 2147483647; files = ( 7BBAB21722E3AD0E00B2941A /* VoodooInputSimulatorDevice.hpp in Headers */, + 358914F425798FA5007A0B58 /* TrackpointDevice.hpp in Headers */, 7BBAB21B22E3AD0E00B2941A /* VoodooInputActuatorDevice.hpp in Headers */, 7BBAB1FD22E3A2F800B2941A /* VoodooInput.hpp in Headers */, ); @@ -230,6 +245,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 358914F525798FA5007A0B58 /* TrackpointDevice.cpp in Sources */, 7BBAB1FF22E3A2F800B2941A /* VoodooInput.cpp in Sources */, 7BBAB21922E3AD0E00B2941A /* VoodooInputActuatorDevice.cpp in Sources */, 7BBAB21822E3AD0E00B2941A /* VoodooInputSimulatorDevice.cpp in Sources */, diff --git a/VoodooInput/Trackpoint/TrackpointDevice.cpp b/VoodooInput/Trackpoint/TrackpointDevice.cpp new file mode 100644 index 0000000..0c3b2e7 --- /dev/null +++ b/VoodooInput/Trackpoint/TrackpointDevice.cpp @@ -0,0 +1,54 @@ +/* + * TrackpointDevice.cpp + * VoodooTrackpoint + * + * Copyright (c) 2019 Leonard Kleinhans + * + */ + +#include "TrackpointDevice.hpp" + +OSDefineMetaClassAndStructors(TrackpointDevice, IOHIPointing); + +UInt32 TrackpointDevice::deviceType() { + return NX_EVS_DEVICE_TYPE_MOUSE; +} + +UInt32 TrackpointDevice::interfaceID() { + return NX_EVS_DEVICE_INTERFACE_BUS_ACE; +} + +IOItemCount TrackpointDevice::buttonCount() { + return 3; +}; + +IOFixed TrackpointDevice::resolution() { + return (150) << 16; +}; + +bool TrackpointDevice::start(IOService* provider) { + if (!super::start(provider)) { + return false; + } + + setProperty(kIOHIDScrollAccelerationTypeKey, kIOHIDTrackpadScrollAccelerationKey); + setProperty(kIOHIDScrollResolutionKey, 800 << 16, 32); + setProperty("HIDScrollResolutionX", 800 << 16, 32); + setProperty("HIDScrollResolutionY", 800 << 16, 32); + + registerService(); + return true; +} + +void TrackpointDevice::stop(IOService* provider) { + super::stop(provider); +} + + +void TrackpointDevice::updateRelativePointer(int dx, int dy, int buttons, uint64_t timestamp) { + dispatchRelativePointerEvent(dx, dy, buttons, timestamp); +}; + +void TrackpointDevice::updateScrollwheel(short deltaAxis1, short deltaAxis2, short deltaAxis3, uint64_t timestamp) { + dispatchScrollWheelEvent(deltaAxis1, deltaAxis2, deltaAxis3, timestamp); +} diff --git a/VoodooInput/Trackpoint/TrackpointDevice.hpp b/VoodooInput/Trackpoint/TrackpointDevice.hpp new file mode 100644 index 0000000..acf6171 --- /dev/null +++ b/VoodooInput/Trackpoint/TrackpointDevice.hpp @@ -0,0 +1,35 @@ +/* + * TrackpointDevice.hpp + * VoodooTrackpoint + * + * Copyright (c) 2019 Leonard Kleinhans + * + */ + +#ifndef TrackpointDevice_hpp +#define TrackpointDevice_hpp + +#include +#include + +class TrackpointDevice : public IOHIPointing { + typedef IOHIPointing super; + OSDeclareDefaultStructors(TrackpointDevice); +protected: + virtual IOItemCount buttonCount() override; + virtual IOFixed resolution() override; + + +public: + bool start(IOService* provider) override; + void stop(IOService* provider) override; + + virtual UInt32 deviceType() override; + virtual UInt32 interfaceID() override; + + void updateRelativePointer(int dx, int dy, int buttons, uint64_t timestamp); + void updateScrollwheel(short deltaAxis1, short deltaAxis2, short deltaAxis3, uint64_t timestamp); + +}; + +#endif /* TrackpointDevice_hpp */ diff --git a/VoodooInput/VoodooInput.cpp b/VoodooInput/VoodooInput.cpp index afc2346..c4852de 100644 --- a/VoodooInput/VoodooInput.cpp +++ b/VoodooInput/VoodooInput.cpp @@ -3,12 +3,14 @@ // VoodooInput // // Copyright © 2019 Kishor Prins. All rights reserved. +// Copyright (c) 2020 Leonard Kleinhans // #include "VoodooInput.hpp" #include "VoodooInputMultitouch/VoodooInputMessages.h" #include "VoodooInputSimulator/VoodooInputActuatorDevice.hpp" #include "VoodooInputSimulator/VoodooInputSimulatorDevice.hpp" +#include "Trackpoint/TrackpointDevice.hpp" #define super IOService OSDefineMetaClassAndStructors(VoodooInput, IOService); @@ -29,11 +31,13 @@ bool VoodooInput::start(IOService *provider) { // Allocate the simulator and actuator devices simulator = OSTypeAlloc(VoodooInputSimulatorDevice); actuator = OSTypeAlloc(VoodooInputActuatorDevice); + trackpoint = OSTypeAlloc(TrackpointDevice); - if (!simulator || !actuator) { - IOLog("VoodooInput could not alloc simulator or actuator!\n"); + if (!simulator || !actuator || !trackpoint) { + IOLog("VoodooInput could not alloc simulator, actuator or trackpoint!\n"); OSSafeReleaseNULL(simulator); OSSafeReleaseNULL(actuator); + OSSafeReleaseNULL(trackpoint); return false; } @@ -59,6 +63,18 @@ bool VoodooInput::start(IOService *provider) { goto exit; } + // Initialize trackpoint device + if (!trackpoint->init(NULL) || !trackpoint->attach(this)) { + IOLog("VoodooInput could not init or attach trackpoint!\n"); + goto exit; + } + else if (!trackpoint->start(this)) { + IOLog("VoodooInput could not start trackpoint!\n"); + trackpoint->detach(this); + goto exit; + } + trackpoint->registerService(); + setProperty(VOODOO_INPUT_IDENTIFIER, kOSBooleanTrue); if (!parentProvider->open(this)) { @@ -93,6 +109,12 @@ void VoodooInput::stop(IOService *provider) { OSSafeReleaseNULL(actuator); } + if (trackpoint) { + trackpoint->stop(this); + trackpoint->detach(this); + OSSafeReleaseNULL(trackpoint); + } + super::stop(provider); } @@ -138,21 +160,39 @@ UInt32 VoodooInput::getLogicalMaxY() { } IOReturn VoodooInput::message(UInt32 type, IOService *provider, void *argument) { - if (type == kIOMessageVoodooInputMessage && provider == parentProvider) { - if (argument && simulator) { - simulator->constructReport(*(VoodooInputEvent*)argument); + switch (type) { + case kIOMessageVoodooInputMessage: + if (provider == parentProvider && argument && simulator) + simulator->constructReport(*(VoodooInputEvent*)argument); + break; + + case kIOMessageVoodooInputUpdateDimensionsMessage: + if (provider == parentProvider && argument) { + const VoodooInputDimensions& dimensions = *(VoodooInputDimensions*)argument; + logicalMaxX = dimensions.max_x - dimensions.min_x; + logicalMaxY = dimensions.max_y - dimensions.min_y; + } + break; + + case kIOMessageVoodooInputUpdatePropertiesNotification: + updateProperties(); + break; + + case kIOMessageVoodooTrackpointRelativePointer: { + if (trackpoint) { + const RelativePointerEvent& event = *(RelativePointerEvent*)argument; + trackpoint->updateRelativePointer(event.dx, event.dy, event.buttons, event.timestamp); + } + break; } - } - else if (type == kIOMessageVoodooInputUpdateDimensionsMessage && provider == parentProvider) { - if (argument) { - const VoodooInputDimensions& dimensions = *(VoodooInputDimensions*)argument; - logicalMaxX = dimensions.max_x - dimensions.min_x; - logicalMaxY = dimensions.max_y - dimensions.min_y; + case kIOMessageVoodooTrackpointScrollWheel: { + if (trackpoint) { + const ScrollWheelEvent& event = *(ScrollWheelEvent*)argument; + trackpoint->updateScrollwheel(event.deltaAxis1, event.deltaAxis2, event.deltaAxis3, event.timestamp); + } + break; } } - else if (type == kIOMessageVoodooInputUpdatePropertiesNotification) { - updateProperties(); - } return super::message(type, provider, argument); } diff --git a/VoodooInput/VoodooInput.hpp b/VoodooInput/VoodooInput.hpp index 5384226..97d0063 100644 --- a/VoodooInput/VoodooInput.hpp +++ b/VoodooInput/VoodooInput.hpp @@ -12,6 +12,7 @@ class VoodooInputSimulatorDevice; class VoodooInputActuatorDevice; +class TrackpointDevice; #ifndef EXPORT #define EXPORT __attribute__((visibility("default"))) @@ -24,6 +25,7 @@ class EXPORT VoodooInput : public IOService { VoodooInputSimulatorDevice* simulator; VoodooInputActuatorDevice* actuator; + TrackpointDevice* trackpoint; UInt8 transformKey; diff --git a/VoodooInput/VoodooInputMultitouch/VoodooInputEvent.h b/VoodooInput/VoodooInputMultitouch/VoodooInputEvent.h index f573b2a..66771fc 100644 --- a/VoodooInput/VoodooInputMultitouch/VoodooInputEvent.h +++ b/VoodooInput/VoodooInputMultitouch/VoodooInputEvent.h @@ -3,6 +3,7 @@ // VooodooInput // // Copyright © 2019 Kishor Prins. All rights reserved. +// Copyright (c) 2020 Leonard Kleinhans // #ifndef VOODOO_INPUT_EVENT_H @@ -23,4 +24,18 @@ struct VoodooInputDimensions { SInt32 max_y; }; +struct RelativePointerEvent { + uint64_t timestamp; + int dx; + int dy; + int buttons; +}; + +struct ScrollWheelEvent { + uint64_t timestamp; + short deltaAxis1; + short deltaAxis2; + short deltaAxis3; +}; + #endif /* VoodooInputEvent_h */ diff --git a/VoodooInput/VoodooInputMultitouch/VoodooInputMessages.h b/VoodooInput/VoodooInputMultitouch/VoodooInputMessages.h index c0fefe3..a3e24ee 100644 --- a/VoodooInput/VoodooInputMultitouch/VoodooInputMessages.h +++ b/VoodooInput/VoodooInputMultitouch/VoodooInputMessages.h @@ -20,6 +20,9 @@ #define kIOMessageVoodooInputMessage 12345 #define kIOMessageVoodooInputUpdateDimensionsMessage 12346 #define kIOMessageVoodooInputUpdatePropertiesNotification 12347 +#define kIOMessageVoodooTrackpointRelativePointer iokit_vendor_specific_msg(430) +#define kIOMessageVoodooTrackpointScrollWheel iokit_vendor_specific_msg(431) + #define kVoodooInputTransducerFingerType 1 #define kVoodooInputTransducerStylusType 2