This commit is contained in:
Romain Vimont 2019-09-29 16:08:03 +02:00
commit ccfd4db370
3 changed files with 37 additions and 43 deletions

View file

@ -199,16 +199,24 @@ public class Controller {
// ignore event // ignore event
return false; return false;
} }
boolean ok = fingersState.set(fingerId, point, pressure, action == MotionEvent.ACTION_UP); Finger finger = fingersState.get(fingerId);
if (!ok) { if (finger == null) {
Ln.w("Too many fingers for touch event"); Ln.w("Too many fingers for touch event");
return false; return false;
} }
finger.setPoint(point);
finger.setPressure(pressure);
finger.setUp(action == MotionEvent.ACTION_UP);
// FAIL: action_up will always remove the finger, and the event will not be written! // FAIL: action_up will always remove the finger, and the event will not be written!
int pointerCount = fingersState.update(touchPointerProperties, touchPointerCoords); int pointerCount = fingersState.update(touchPointerProperties, touchPointerCoords);
fingersState.cleanUp();
Ln.w("pointerCount = " + pointerCount); Ln.d("pointerCount = " + pointerCount);
MotionEvent event = MotionEvent.obtain(lastTouchDown, now, action, pointerCount, touchPointerProperties, touchPointerCoords, 0, 0, 1f, 1f, 0, 0, for (int i = 0; i < pointerCount; ++i) {
Ln.d("props = " + touchPointerProperties[i].id);
Ln.d("coords = " + touchPointerCoords[i].x + "," + touchPointerCoords[i].y);
}
MotionEvent event = MotionEvent.obtain(lastTouchDown, now, action | (finger.getLocalId() << 8), pointerCount, touchPointerProperties, touchPointerCoords, 0, 0, 1f, 1f, 0, 0,
InputDevice.SOURCE_TOUCHSCREEN, 0); InputDevice.SOURCE_TOUCHSCREEN, 0);
return injectEvent(event); return injectEvent(event);
} }

View file

@ -3,18 +3,24 @@ package com.genymobile.scrcpy;
public class Finger { public class Finger {
private final long id; private final long id;
private final int localId;
private Point point; private Point point;
private float pressure; private float pressure;
private boolean up; private boolean up;
public Finger(long id) { public Finger(long id, int localId) {
this.id = id; this.id = id;
this.localId = localId;
} }
public long getId() { public long getId() {
return id; return id;
} }
public int getLocalId() {
return localId;
}
public Point getPoint() { public Point getPoint() {
return point; return point;
} }

View file

@ -36,50 +36,24 @@ public class FingersState {
return -1; return -1;
} }
private Finger create(long id) { public Finger get(long id) {
int index = indexOf(id); int index = indexOf(id);
if (index != -1) { if (index != -1) {
// already exists, return it // already exists, return it
return fingers[index]; return fingers[index];
} }
int firstEmpty = indexOfFirstEmpty(); index = indexOfFirstEmpty();
if (firstEmpty == -1) { if (index == -1) {
// it's full // it's full
return null; return null;
} }
Finger finger = new Finger(id); // id 0 is reserved for mouse events
fingers[firstEmpty] = finger; int localId = index;// + 1;
Finger finger = new Finger(id, localId);
fingers[index] = finger;
return finger; return finger;
} }
public boolean unset(long id) {
int index = indexOf(id);
if (index == -1) {
return false;
}
fingers[index] = null;
return true;
}
public boolean set(long id, Point point, float pressure, boolean up) {
Finger finger = create(id);
if (finger == null) {
return false;
}
finger.setPoint(point);
finger.setPressure(pressure);
finger.setUp(up);
return true;
}
public void cleanUp() {
for (int i = 0; i < fingers.length; ++i) {
if (fingers[i] != null && fingers[i].isUp()) {
fingers[i] = null;
}
}
}
/** /**
* Initialize the motion event parameters. * Initialize the motion event parameters.
* *
@ -93,12 +67,18 @@ public class FingersState {
Finger finger = fingers[i]; Finger finger = fingers[i];
if (finger != null) { if (finger != null) {
// id 0 is reserved for mouse events // id 0 is reserved for mouse events
props[count].id = i + 1; props[count].id = finger.getLocalId();
Ln.d("update id = " + finger.getLocalId());
Point point = finger.getPoint(); Point point = finger.getPoint();
coords[i].x = point.getX(); coords[count].x = point.getX();
coords[i].y = point.getY(); coords[count].y = point.getY();
coords[i].pressure = finger.getPressure(); coords[count].pressure = finger.getPressure();
if (finger.isUp()) {
// remove it
fingers[i] = null;
}
++count; ++count;
} }