localId
This commit is contained in:
parent
6d26ed888e
commit
ccfd4db370
@ -199,16 +199,24 @@ public class Controller {
|
||||
// ignore event
|
||||
return false;
|
||||
}
|
||||
boolean ok = fingersState.set(fingerId, point, pressure, action == MotionEvent.ACTION_UP);
|
||||
if (!ok) {
|
||||
Finger finger = fingersState.get(fingerId);
|
||||
if (finger == null) {
|
||||
Ln.w("Too many fingers for touch event");
|
||||
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!
|
||||
int pointerCount = fingersState.update(touchPointerProperties, touchPointerCoords);
|
||||
fingersState.cleanUp();
|
||||
Ln.w("pointerCount = " + pointerCount);
|
||||
MotionEvent event = MotionEvent.obtain(lastTouchDown, now, action, pointerCount, touchPointerProperties, touchPointerCoords, 0, 0, 1f, 1f, 0, 0,
|
||||
|
||||
Ln.d("pointerCount = " + pointerCount);
|
||||
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);
|
||||
return injectEvent(event);
|
||||
}
|
||||
|
@ -3,18 +3,24 @@ package com.genymobile.scrcpy;
|
||||
public class Finger {
|
||||
|
||||
private final long id;
|
||||
private final int localId;
|
||||
private Point point;
|
||||
private float pressure;
|
||||
private boolean up;
|
||||
|
||||
public Finger(long id) {
|
||||
public Finger(long id, int localId) {
|
||||
this.id = id;
|
||||
this.localId = localId;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getLocalId() {
|
||||
return localId;
|
||||
}
|
||||
|
||||
public Point getPoint() {
|
||||
return point;
|
||||
}
|
||||
|
@ -36,50 +36,24 @@ public class FingersState {
|
||||
return -1;
|
||||
}
|
||||
|
||||
private Finger create(long id) {
|
||||
public Finger get(long id) {
|
||||
int index = indexOf(id);
|
||||
if (index != -1) {
|
||||
// already exists, return it
|
||||
return fingers[index];
|
||||
}
|
||||
int firstEmpty = indexOfFirstEmpty();
|
||||
if (firstEmpty == -1) {
|
||||
index = indexOfFirstEmpty();
|
||||
if (index == -1) {
|
||||
// it's full
|
||||
return null;
|
||||
}
|
||||
Finger finger = new Finger(id);
|
||||
fingers[firstEmpty] = finger;
|
||||
// id 0 is reserved for mouse events
|
||||
int localId = index;// + 1;
|
||||
Finger finger = new Finger(id, localId);
|
||||
fingers[index] = 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.
|
||||
*
|
||||
@ -93,12 +67,18 @@ public class FingersState {
|
||||
Finger finger = fingers[i];
|
||||
if (finger != null) {
|
||||
// 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();
|
||||
coords[i].x = point.getX();
|
||||
coords[i].y = point.getY();
|
||||
coords[i].pressure = finger.getPressure();
|
||||
coords[count].x = point.getX();
|
||||
coords[count].y = point.getY();
|
||||
coords[count].pressure = finger.getPressure();
|
||||
|
||||
if (finger.isUp()) {
|
||||
// remove it
|
||||
fingers[i] = null;
|
||||
}
|
||||
|
||||
++count;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user