Skip to content

Commit 380b7de

Browse files
committed
Working drag and clicking, broken right click
1 parent db0e024 commit 380b7de

3 files changed

Lines changed: 75 additions & 18 deletions

File tree

‎VoodooI2CGoodix/VoodooI2CGoodixEventDriver.cpp‎

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define super IOHIDEventService
1616
OSDefineMetaClassAndStructors(VoodooI2CGoodixEventDriver, IOHIDEventService);
1717

18-
void VoodooI2CGoodixEventDriver::dispatchDigitizerEvent(int logicalX, int logicalY, bool click) {
18+
void VoodooI2CGoodixEventDriver::dispatchDigitizerEvent(int logicalX, int logicalY, UInt32 clickType) {
1919
AbsoluteTime timestamp;
2020
clock_get_uptime(&timestamp);
2121

@@ -24,36 +24,83 @@ void VoodooI2CGoodixEventDriver::dispatchDigitizerEvent(int logicalX, int logica
2424
IOFixed y = ((logicalY * 1.0f) / multitouch_interface->logical_max_y) * 65535;
2525

2626
// Dispatch the actual event
27-
dispatchDigitizerEventWithTiltOrientation(timestamp, 0, kDigitiserTransducerFinger, 0x1, click ? 0x1 : 0x0, x, y);
27+
dispatchDigitizerEventWithTiltOrientation(timestamp, 0, kDigitiserTransducerFinger, 0x1, clickType, x, y);
2828

29+
// Store the coordinates so we can lift the finger later
2930
last_x = x;
3031
last_y = y;
31-
last_id = 0;
3232
}
3333

3434
void VoodooI2CGoodixEventDriver::scheduleLift() {
35+
this->timer_source->cancelTimeout();
3536
this->timer_source->setTimeoutMS(FINGER_LIFT_EVENT_DELAY);
3637
}
3738

3839
void VoodooI2CGoodixEventDriver::fingerLift() {
3940
AbsoluteTime timestamp;
4041
clock_get_uptime(&timestamp);
4142

42-
dispatchDigitizerEventWithTiltOrientation(timestamp, last_id, kDigitiserTransducerFinger, 0x1, 0x0, last_x, last_y);
43+
dispatchDigitizerEventWithTiltOrientation(timestamp, 0, kDigitiserTransducerFinger, 0x1, HOVER, last_x, last_y);
44+
45+
click_tick = 0;
46+
start_scroll = true;
47+
48+
// Reset right click status so we're not stuck checking if we're still right clicking
49+
if (right_click) {
50+
right_click = false;
51+
}
4352
}
4453

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

51-
// Lift a bit later
58+
// Check for right clicks
59+
UInt16 temp_x = touch.x;
60+
UInt16 temp_y = touch.y;
61+
if (!right_click) {
62+
if (temp_x == compare_input_x && temp_y == compare_input_y) {
63+
compare_input_counter = compare_input_counter + 1;
64+
compare_input_x = temp_x;
65+
compare_input_y = temp_y;
66+
67+
if (compare_input_counter >= RIGHT_CLICK_TICKS && !right_click) {
68+
compare_input_x = 0;
69+
compare_input_y = 0;
70+
compare_input_counter = 0;
71+
right_click = true;
72+
}
73+
}
74+
else {
75+
compare_input_x = temp_x;
76+
compare_input_y = temp_y;
77+
compare_input_counter = 0;
78+
}
79+
}
80+
81+
// Determine what click type to send
82+
UInt32 clickType = LEFT_CLICK;
83+
84+
if (click_tick <= HOVER_TICKS) {
85+
clickType = HOVER;
86+
click_tick++;
87+
}
88+
89+
if (right_click) {
90+
clickType = right_click;
91+
}
92+
93+
dispatchDigitizerEvent(touch.x, touch.y, clickType);
94+
95+
// Lift the finger a bit later
5296
scheduleLift();
5397
}
5498
else {
99+
// Our finger event is multitouch, so we're not clicking
100+
click_tick = 0;
101+
55102
// Move the cursor to the location of the first finger, but don't click
56-
dispatchDigitizerEvent(touches[0].x, touches[0].y, false);
103+
dispatchDigitizerEvent(touches[0].x, touches[0].y, HOVER);
57104

58105
AbsoluteTime timestamp;
59106
clock_get_uptime(&timestamp);

‎VoodooI2CGoodix/VoodooI2CGoodixEventDriver.hpp‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929

3030
#include "../../../Dependencies/helpers.hpp"
3131

32-
#define FINGER_LIFT_EVENT_DELAY 14
32+
#define FINGER_LIFT_EVENT_DELAY 50
33+
#define HOVER 0x0
34+
#define LEFT_CLICK 0x1
35+
#define RIGHT_CLICK 0x2
36+
#define HOVER_TICKS 2
37+
#define RIGHT_CLICK_TICKS 25
3338

3439
struct Touch {
3540
int x;
@@ -128,7 +133,7 @@ class EXPORT VoodooI2CGoodixEventDriver : public IOHIDEventService {
128133
* @click Whether this is a click event
129134
*/
130135

131-
void dispatchDigitizerEvent(int logicalX, int logicalY, bool click);
136+
void dispatchDigitizerEvent(int logicalX, int logicalY, UInt32 clickType);
132137

133138
/* Dispatch a finger lift event at the location of the last digitizer event
134139
*/
@@ -143,10 +148,15 @@ class EXPORT VoodooI2CGoodixEventDriver : public IOHIDEventService {
143148
IOWorkLoop *work_loop;
144149
IOTimerEventSource *timer_source;
145150

146-
UInt32 buttons = 0;
147151
IOFixed last_x = 0;
148152
IOFixed last_y = 0;
149-
SInt32 last_id = 0;
153+
154+
int click_tick = 0;
155+
bool right_click = false;
156+
bool start_scroll = true;
157+
UInt16 compare_input_x = 0;
158+
UInt16 compare_input_y = 0;
159+
int compare_input_counter = 0;
150160
};
151161

152162

‎VoodooI2CGoodix/VoodooI2CGoodixTouchDriver.cpp‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,14 @@ void VoodooI2CGoodixTouchDriver::goodix_ts_report_touch(UInt8 *coor_data, Touch
334334
int input_y = get_unaligned_le16(&coor_data[3]);
335335
int input_w = get_unaligned_le16(&coor_data[5]);
336336

337-
IOLog("%s::raw: %d,%d\n", getName(), input_x, input_y);
337+
// IOLog("%s::raw: %d,%d\n", getName(), input_x, input_y);
338338

339339
// Scale swapping has to happen before everything
340340
if (ts->swap_x_y_scale) {
341341
input_x = (int)(((float)input_x / ts->abs_x_max) * ts->abs_y_max);
342342
input_y = (int)(((float)input_y / ts->abs_y_max) * ts->abs_x_max);
343343

344-
IOLog("%s::scl: %d,%d\n", getName(), input_x, input_y);
344+
// IOLog("%s::scl: %d,%d\n", getName(), input_x, input_y);
345345

346346
// Inversions have to happen before axis swapping
347347
if (ts->inverted_x)
@@ -350,7 +350,7 @@ void VoodooI2CGoodixTouchDriver::goodix_ts_report_touch(UInt8 *coor_data, Touch
350350
input_y = ts->abs_x_max - input_y;
351351

352352
if (ts->inverted_x || ts->inverted_y) {
353-
IOLog("%s::inv: %d,%d\n", getName(), input_x, input_y);
353+
// IOLog("%s::inv: %d,%d\n", getName(), input_x, input_y);
354354
}
355355
}
356356
else {
@@ -361,16 +361,16 @@ void VoodooI2CGoodixTouchDriver::goodix_ts_report_touch(UInt8 *coor_data, Touch
361361
input_y = ts->abs_y_max - input_y;
362362

363363
if (ts->inverted_x || ts->inverted_y) {
364-
IOLog("%s::inv: %d,%d\n", getName(), input_x, input_y);
364+
// IOLog("%s::inv: %d,%d\n", getName(), input_x, input_y);
365365
}
366366
}
367367

368368
if (ts->swapped_x_y || ts->swapped_x_y_values) {
369369
swap(input_x, input_y);
370-
IOLog("%s::swp: %d,%d\n", getName(), input_x, input_y);
370+
// IOLog("%s::swp: %d,%d\n", getName(), input_x, input_y);
371371
}
372372

373-
IOLog("%s::Touch %d with width %d at %d,%d\n", getName(), id, input_w, input_x, input_y);
373+
// IOLog("%s::Touch %d with width %d at %d,%d\n", getName(), id, input_w, input_x, input_y);
374374

375375
// Store touch information
376376
touches[id].x = input_x;

0 commit comments

Comments
 (0)