Skip to content

Commit d77f143

Browse files
committed
Very rough first draft palm reject
1 parent b6713c3 commit d77f143

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

VoodooPS2Trackpad/VoodooPS2Elan.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,12 +1941,12 @@ void ApplePS2Elan::processPacketHeadV4() {
19411941
pres = (packet[1] & 0xf0) | ((packet[4] & 0xf0) >> 4);
19421942
traces = (packet[0] & 0xf0) >> 4;
19431943

1944-
INTERRUPT_LOG("VoodooPS2Elan: pres: %d, traces: %d, width: %d\n", pres, traces, etd.width);
1944+
INTERRUPT_LOG("VoodooPS2Elan: pres: %d, traces: %d, width: %d (%d)\n", pres, traces, etd.width, etd.width * info.width / info.x_res);
19451945

19461946
virtualFinger[id].button = (packet[0] & 0x3);
19471947
virtualFinger[id].prev = virtualFinger[id].now;
19481948
virtualFinger[id].pressure = pres;
1949-
virtualFinger[id].width = traces;
1949+
virtualFinger[id].width = traces * info.width / info.x_res;
19501950

19511951
virtualFinger[id].now.x = x;
19521952
virtualFinger[id].now.y = y;
@@ -1997,7 +1997,11 @@ void ApplePS2Elan::processPacketMotionV4() {
19971997
sendTouchData();
19981998
}
19991999

2000-
MT2FingerType ApplePS2Elan::GetBestFingerType(int i) {
2000+
MT2FingerType ApplePS2Elan::GetBestFingerType(int i, uint8_t width, uint8_t pressure) {
2001+
if (width >= 25 || pressure >= 120) {
2002+
return kMT2FingerTypePalm;
2003+
}
2004+
20012005
switch (i) {
20022006
case 0: return kMT2FingerTypeIndexFinger;
20032007
case 1: return kMT2FingerTypeMiddleFinger;
@@ -2019,30 +2023,32 @@ void ApplePS2Elan::sendTouchData() {
20192023

20202024
// Ignore input for specified time after keyboard/trackpoint usage
20212025
if (timestamp_ns - keytime < maxaftertyping) {
2022-
return;
2026+
// return;
20232027
}
20242028

20252029
static_assert(VOODOO_INPUT_MAX_TRANSDUCERS >= ETP_MAX_FINGERS, "Trackpad supports too many fingers");
20262030

20272031
int transducers_count = 0;
20282032
for (int i = 0; i < ETP_MAX_FINGERS; i++) {
20292033
const auto &state = virtualFinger[i];
2030-
if (!state.touch) {
2031-
continue;
2032-
}
2034+
// if (!state.touch) {
2035+
// continue;
2036+
// }
20332037

2034-
auto &transducer = inputEvent.transducers[transducers_count];
2038+
auto &transducer = inputEvent.transducers[i];
20352039

20362040
transducer.currentCoordinates = state.now;
20372041
transducer.previousCoordinates = state.prev;
20382042
transducer.timestamp = timestamp;
20392043

20402044
transducer.isValid = true;
20412045
transducer.isPhysicalButtonDown = info.is_buttonpad && state.button;
2042-
transducer.isTransducerActive = true;
2046+
transducer.isTransducerActive = state.touch;
20432047

20442048
transducer.secondaryId = i;
2045-
transducer.fingerType = GetBestFingerType(transducers_count);
2049+
if (transducer.fingerType != kMT2FingerTypePalm) {
2050+
transducer.fingerType = GetBestFingerType(i, state.width, state.pressure);
2051+
}
20462052
transducer.type = FINGER;
20472053

20482054
// it looks like Elan PS2 pressure and width is very inaccurate
@@ -2058,7 +2064,8 @@ void ApplePS2Elan::sendTouchData() {
20582064
transducer.currentCoordinates.width = 10;
20592065
}
20602066

2061-
transducers_count++;
2067+
if (transducer.isTransducerActive)
2068+
transducers_count++;
20622069
}
20632070

20642071
// set the thumb to improve 4F pinch and spread gesture and cross-screen dragging
@@ -2069,11 +2076,16 @@ void ApplePS2Elan::sendTouchData() {
20692076
int newThumbIndex = 0;
20702077
int currentThumbIndex = 0;
20712078
for (int i = 0; i < transducers_count; i++) {
2072-
if (inputEvent.transducers[i].currentCoordinates.y > maxY) {
2079+
auto &transducer = inputEvent.transducers[i];
2080+
if (!transducer.isTransducerActive || transducer.fingerType == kMT2FingerTypePalm) {
2081+
continue;
2082+
}
2083+
2084+
if (transducer.currentCoordinates.y > maxY) {
20732085
maxY = inputEvent.transducers[i].currentCoordinates.y;
20742086
newThumbIndex = i;
20752087
}
2076-
if (inputEvent.transducers[i].fingerType == kMT2FingerTypeThumb) {
2088+
if (transducer.fingerType == kMT2FingerTypeThumb) {
20772089
currentThumbIndex = i;
20782090
}
20792091
}
@@ -2085,9 +2097,10 @@ void ApplePS2Elan::sendTouchData() {
20852097
inputEvent.transducers[i].isValid = false;
20862098
inputEvent.transducers[i].isPhysicalButtonDown = false;
20872099
inputEvent.transducers[i].isTransducerActive = false;
2100+
inputEvent.transducers[i].fingerType = kMT2FingerTypeUndefined;
20882101
}
20892102

2090-
inputEvent.contact_count = transducers_count;
2103+
inputEvent.contact_count = ETP_MAX_FINGERS;
20912104
inputEvent.timestamp = timestamp;
20922105

20932106
if (voodooInputInstance) {

VoodooPS2Trackpad/VoodooPS2Elan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ class EXPORT ApplePS2Elan : public IOService {
324324
void resetMouse();
325325
void setTouchPadEnable(bool enable);
326326

327-
static MT2FingerType GetBestFingerType(int i);
327+
static MT2FingerType GetBestFingerType(int i, uint8_t width, uint8_t pressure);
328328

329329
template<int I>
330330
int ps2_command(UInt8* params, unsigned int command);

0 commit comments

Comments
 (0)