add displayId setting to InputEvent

This commit is contained in:
evigurskiy 2020-03-02 14:48:39 +03:00
parent ee810f653b
commit 749e614665
3 changed files with 19 additions and 1 deletions

View file

@ -2,6 +2,7 @@ package com.genymobile.scrcpy;
import com.genymobile.scrcpy.wrappers.InputManager;
import android.os.Build;
import android.os.SystemClock;
import android.view.InputDevice;
import android.view.InputEvent;
@ -10,6 +11,8 @@ import android.view.KeyEvent;
import android.view.MotionEvent;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Controller {
@ -178,7 +181,6 @@ public class Controller {
action = MotionEvent.ACTION_POINTER_DOWN | (pointerIndex << MotionEvent.ACTION_POINTER_INDEX_SHIFT);
}
}
MotionEvent event = MotionEvent
.obtain(lastTouchDown, now, action, pointerCount, pointerProperties, pointerCoords, 0, buttons, 1f, 1f, DEVICE_ID_VIRTUAL, 0,
InputDevice.SOURCE_TOUCHSCREEN, 0);
@ -220,6 +222,9 @@ public class Controller {
}
private boolean injectEvent(InputEvent event) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
InputManager.setDisplayId(event, device.getDisplayId());
}
return device.injectInputEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
}

View file

@ -22,6 +22,7 @@ public final class Device {
private final ServiceManager serviceManager = new ServiceManager();
private final int displayId;
private ScreenInfo screenInfo;
private RotationListener rotationListener;
@ -76,6 +77,10 @@ public final class Device {
return Build.MODEL;
}
public int getDisplayId() {
return displayId;
}
public boolean injectInputEvent(InputEvent inputEvent, int mode) {
return serviceManager.getInputManager().injectInputEvent(inputEvent, mode);
}

View file

@ -37,4 +37,12 @@ public final class InputManager {
return false;
}
}
public static void setDisplayId(InputEvent inputEvent, int displayId) {
try {
inputEvent.getClass().getMethod("setDisplayId", int.class).invoke(inputEvent, displayId);
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
Ln.e("Could not invoke method", e);
}
}
}