mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-04-20 19:45:00 +00:00
add displayId setting to InputEvent
This commit is contained in:
parent
ee810f653b
commit
749e614665
3 changed files with 19 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue