Skip to content

Commit

Permalink
Behave like a touchscreen, properly
Browse files Browse the repository at this point in the history
* except dragging to select, which times out after 14ms and screws up your selection
  • Loading branch information
lazd committed Jan 6, 2020
1 parent c87f07a commit 7223814
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
40 changes: 40 additions & 0 deletions VoodooI2CGoodix/VoodooI2CGoodixEventDriver.cpp
Expand Up @@ -30,13 +30,32 @@ void VoodooI2CGoodixEventDriver::dispatchDigitizerEvent(int logicalX, int logica

// Dispatch the actual event
dispatchDigitizerEventWithTiltOrientation(timestamp, 0, kDigitiserTransducerFinger, 0x1, click ? 0x1 : 0x0, x, y);

last_x = x;
last_y = y;
last_id = 0;
}

void VoodooI2CGoodixEventDriver::scheduleLift() {
this->timer_source->setTimeoutMS(14);
}

void VoodooI2CGoodixEventDriver::fingerLift() {
AbsoluteTime timestamp;
clock_get_uptime(&timestamp);

dispatchDigitizerEventWithTiltOrientation(timestamp, last_id, kDigitiserTransducerFinger, 0x1, 0x0, last_x, last_y);
}


void VoodooI2CGoodixEventDriver::reportTouches(struct Touch touches[], int numTouches) {
if (numTouches == 1) {
// Initial mouse down event
Touch touch = touches[0];
dispatchDigitizerEvent(touch.x, touch.y, true);

// Lift a bit later
scheduleLift();
}
else {
// Move the cursor to the location of the first finger, but don't click
Expand Down Expand Up @@ -87,6 +106,15 @@ bool VoodooI2CGoodixEventDriver::handleStart(IOService* provider) {
return false;
}

this->work_loop = getWorkLoop();
if (!this->work_loop) {
IOLog("%s::Unable to get workloop\n", getName());
stop(provider);
return false;
}

work_loop->retain();

name = getProductName();

publishMultitouchInterface();
Expand All @@ -105,6 +133,13 @@ bool VoodooI2CGoodixEventDriver::handleStart(IOService* provider) {

multitouch_interface->registerService();

timer_source = IOTimerEventSource::timerEventSource(this, OSMemberFunctionCast(IOTimerEventSource::Action, this, &VoodooI2CGoodixEventDriver::fingerLift));

if (!timer_source || work_loop->addEventSource(timer_source) != kIOReturnSuccess) {
IOLog("%s::Could not add timer source to work loop\n", getName());
return false;
}

return true;
}

Expand All @@ -121,6 +156,11 @@ void VoodooI2CGoodixEventDriver::handleStop(IOService* provider) {
OSSafeReleaseNULL(transducers);
}

if (timer_source) {
work_loop->removeEventSource(timer_source);
OSSafeReleaseNULL(timer_source);
}

super::handleStop(provider);
}

Expand Down
14 changes: 12 additions & 2 deletions VoodooI2CGoodix/VoodooI2CGoodixEventDriver.hpp
Expand Up @@ -18,6 +18,7 @@

#include <IOKit/IOLib.h>
#include <IOKit/IOService.h>
#include <IOKit/IOTimerEventSource.h>

#include <IOKit/hidevent/IOHIDEventService.h>
#include <IOKit/hidsystem/IOHIDTypes.h>
Expand Down Expand Up @@ -105,14 +106,23 @@ class EXPORT VoodooI2CGoodixEventDriver : public IOHIDEventService {
protected:
const char* name;
bool awake = true;
// IOHIDInterface* hid_interface;
VoodooI2CMultitouchInterface* multitouch_interface;
OSArray* transducers;

private:
OSSet* attached_hid_pointer_devices;
IOWorkLoop *work_loop;
IOTimerEventSource *timer_source;

UInt32 buttons = 0;
IOFixed last_x = 0;
IOFixed last_y = 0;
SInt32 last_id = 0;

int click_tick = 0;

void dispatchDigitizerEvent(int logicalX, int logicalY, bool click);
void fingerLift();
void scheduleLift();
};


Expand Down

0 comments on commit 7223814

Please sign in to comment.