Skip to content

Commit 7223814

Browse files
committed
Behave like a touchscreen, properly
* except dragging to select, which times out after 14ms and screws up your selection
1 parent c87f07a commit 7223814

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

VoodooI2CGoodix/VoodooI2CGoodixEventDriver.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,32 @@ void VoodooI2CGoodixEventDriver::dispatchDigitizerEvent(int logicalX, int logica
3030

3131
// Dispatch the actual event
3232
dispatchDigitizerEventWithTiltOrientation(timestamp, 0, kDigitiserTransducerFinger, 0x1, click ? 0x1 : 0x0, x, y);
33+
34+
last_x = x;
35+
last_y = y;
36+
last_id = 0;
37+
}
38+
39+
void VoodooI2CGoodixEventDriver::scheduleLift() {
40+
this->timer_source->setTimeoutMS(14);
41+
}
42+
43+
void VoodooI2CGoodixEventDriver::fingerLift() {
44+
AbsoluteTime timestamp;
45+
clock_get_uptime(&timestamp);
46+
47+
dispatchDigitizerEventWithTiltOrientation(timestamp, last_id, kDigitiserTransducerFinger, 0x1, 0x0, last_x, last_y);
3348
}
3449

50+
3551
void VoodooI2CGoodixEventDriver::reportTouches(struct Touch touches[], int numTouches) {
3652
if (numTouches == 1) {
3753
// Initial mouse down event
3854
Touch touch = touches[0];
3955
dispatchDigitizerEvent(touch.x, touch.y, true);
56+
57+
// Lift a bit later
58+
scheduleLift();
4059
}
4160
else {
4261
// Move the cursor to the location of the first finger, but don't click
@@ -87,6 +106,15 @@ bool VoodooI2CGoodixEventDriver::handleStart(IOService* provider) {
87106
return false;
88107
}
89108

109+
this->work_loop = getWorkLoop();
110+
if (!this->work_loop) {
111+
IOLog("%s::Unable to get workloop\n", getName());
112+
stop(provider);
113+
return false;
114+
}
115+
116+
work_loop->retain();
117+
90118
name = getProductName();
91119

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

106134
multitouch_interface->registerService();
107135

136+
timer_source = IOTimerEventSource::timerEventSource(this, OSMemberFunctionCast(IOTimerEventSource::Action, this, &VoodooI2CGoodixEventDriver::fingerLift));
137+
138+
if (!timer_source || work_loop->addEventSource(timer_source) != kIOReturnSuccess) {
139+
IOLog("%s::Could not add timer source to work loop\n", getName());
140+
return false;
141+
}
142+
108143
return true;
109144
}
110145

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

159+
if (timer_source) {
160+
work_loop->removeEventSource(timer_source);
161+
OSSafeReleaseNULL(timer_source);
162+
}
163+
124164
super::handleStop(provider);
125165
}
126166

VoodooI2CGoodix/VoodooI2CGoodixEventDriver.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <IOKit/IOLib.h>
2020
#include <IOKit/IOService.h>
21+
#include <IOKit/IOTimerEventSource.h>
2122

2223
#include <IOKit/hidevent/IOHIDEventService.h>
2324
#include <IOKit/hidsystem/IOHIDTypes.h>
@@ -105,14 +106,23 @@ class EXPORT VoodooI2CGoodixEventDriver : public IOHIDEventService {
105106
protected:
106107
const char* name;
107108
bool awake = true;
108-
// IOHIDInterface* hid_interface;
109109
VoodooI2CMultitouchInterface* multitouch_interface;
110110
OSArray* transducers;
111111

112112
private:
113-
OSSet* attached_hid_pointer_devices;
113+
IOWorkLoop *work_loop;
114+
IOTimerEventSource *timer_source;
115+
116+
UInt32 buttons = 0;
117+
IOFixed last_x = 0;
118+
IOFixed last_y = 0;
119+
SInt32 last_id = 0;
120+
121+
int click_tick = 0;
114122

115123
void dispatchDigitizerEvent(int logicalX, int logicalY, bool click);
124+
void fingerLift();
125+
void scheduleLift();
116126
};
117127

118128

0 commit comments

Comments
 (0)